Definition in file Main.c.
#include "Main.h"
#include "Temperature.h"
#include "RTC.h"
#include "UART.h"
#include "Lcd_functions.h"
#include "LCD_driver.h"
#include "Buttons.h"
Include dependency graph for Main.c:

Go to the source code of this file.
Functions | |
| void | Delay (int i) |
| Delay-routine. | |
| void | Initialization (void) |
| Initialize the different modules of the ATmega169(P). | |
| void | main (void) |
| Main function which contains the endless main loop. | |
| void | OSCCAL_calibration (void) |
| Calibrate the internal OSCCAL byte, using the external 32,768 kHz crystal as reference. | |
|
|
Delay-routine.
Definition at line 93 of file Main.c. Referenced by ADC_init(), OSCCAL_calibration(), and RTC_init(). 00094 { 00095 int j,k; 00096 00097 for(k=1;k<=i;k++) 00098 { 00099 for(j=1;j<=124;j++); 00100 } 00101 }
|
|
|
Initialize the different modules of the ATmega169(P).
Definition at line 59 of file Main.c. References ADC_init(), CONTRAST, LCD_Init(), LCDsetupData(), OSCCAL_calibration(), PWM_init(), RTC_init(), SingleEnded, and UART_init(). Referenced by main(). 00060 { 00061 CLKPR = (1<<CLKPCE); // set Clock Prescaler Change Enable 00062 CLKPR = (1<<CLKPS1) | (1<<CLKPS0); // set prescaler = 8, Inter RC 8Mhz / 8 = 1Mhz 00063 00064 OSCCAL_calibration(); // calibrate the OSCCAL byte 00065 00066 CONTRAST = 0x0F; // set the LCD contrast register to max 00067 00068 DDRB = 0xF0; // set PORTB as output to drive the LEDS on STK500 00069 00070 DDRE = 0x00; // set PORTE as input to read the SWITCHES on STK500 00071 00072 PWM_init(); // initialize Timer1 with PWM 00073 00074 RTC_init(); // start timer2 asynchronous, used for RTC clock 00075 00076 // Select either Single Ended or Differential ADC measurement, comment out the other 00077 ADC_init(SingleEnded); // initialize the ADC, select "Single_ended" or "Differential" 00078 // ADC_init(Differential); // initialize the ADC, select "Single_ended" or "Differential" 00079 00080 UART_init(12); // set up the UART 00081 00082 LCD_Init(); // initialize the LCD 00083 00084 LCDsetupData(); // set the display to scroll the init text 00085 00086 __enable_interrupt(); //enable global interrupt 00087 }
Here is the call graph for this function: ![]() |
|
|
Main function which contains the endless main loop.
Definition at line 36 of file Main.c. References ADC_conversion(), CheckButtons(), Initialization(), LCD_update(), Send_TX_data(), Store_RX_data(), and Time_update(). 00037 { 00038 Initialization(); // Call the initialization function 00039 00040 while(1) // endless main loop 00041 { 00042 Time_update(); // update clock 00043 00044 ADC_conversion(); // measure the temperature 00045 00046 Store_RX_data(); // store data from receivebuffer to SRAM 00047 00048 Send_TX_data(); // load data from SRAM to transmit-buffer and start transmission 00049 00050 CheckButtons(); // check if any input from user on the STK500-buttons 00051 00052 LCD_update(); // call LCD routine 00053 } 00054 }
Here is the call graph for this function: ![]() |
|
|
Calibrate the internal OSCCAL byte, using the external 32,768 kHz crystal as reference.
Definition at line 107 of file Main.c. References Delay(), FALSE, and TRUE. Referenced by Initialization(). 00108 { 00109 unsigned char calibrate = FALSE; 00110 int temp; 00111 unsigned char tempL; 00112 00113 CLKPR = (1<<CLKPCE); // set Clock Prescaler Change Enable 00114 // set prescaler = 8, Inter RC 8Mhz / 8 = 1Mhz 00115 CLKPR = (1<<CLKPS1) | (1<<CLKPS0); 00116 00117 TIMSK2 = 0; //disable OCIE2A and TOIE2 00118 00119 ASSR = (1<<AS2); //select asynchronous operation of timer2 (32,768kHz) 00120 00121 OCR2A = 200; // set timer2 compare value 00122 00123 TIMSK0 = 0; // delete any interrupt sources 00124 00125 TCCR1B = (1<<CS10); // start timer1 with no prescaling 00126 TCCR2A = (1<<CS20); // start timer2 with no prescaling 00127 00128 while(ASSR & (0x01 | 0x04)); //wait for TCN2UB and TCR2UB to be cleared 00129 00130 Delay(1000); // wait for external crystal to stabilise 00131 00132 while(!calibrate) 00133 { 00134 __disable_interrupt(); // disable global interrupt 00135 00136 TIFR1 = 0xFF; // delete TIFR1 flags 00137 TIFR2 = 0xFF; // delete TIFR2 flags 00138 00139 TCNT1H = 0; // clear timer1 counter 00140 TCNT1L = 0; 00141 TCNT2 = 0; // clear timer2 counter 00142 00143 while ( !(TIFR2 && (1<<OCF2A)) ); // wait for timer2 compareflag 00144 00145 TCCR1B = 0; // stop timer1 00146 00147 __enable_interrupt(); // enable global interrupt 00148 00149 if ( (TIFR1 && (1<<TOV1)) ) 00150 { 00151 temp = 0xFFFF; // if timer1 overflows, set the temp to 0xFFFF 00152 } 00153 else 00154 { // read out the timer1 counter value 00155 tempL = TCNT1L; 00156 temp = TCNT1H; 00157 temp = (temp << 8); 00158 temp += tempL; 00159 } 00160 00161 if (temp > 6250) 00162 { 00163 OSCCAL--; // the internRC oscillator runs to fast, decrease the OSCCAL 00164 } 00165 else if (temp < 6120) 00166 { 00167 OSCCAL++; // the internRC oscillator runs to slow, increase the OSCCAL 00168 } 00169 else 00170 calibrate = TRUE; // the interRC is correct 00171 00172 TCCR1B = (1<<CS10); // start timer1 00173 } 00174 }
Here is the call graph for this function: ![]() |
1.4.5