Main.h File Reference


Detailed Description

Defines and prototypes for Main.c.

Application note:
AVR064: A Temperature Monitoring System with LCD Output
Documentation:
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Name
RELEASE_1_1
Revision
1.3
RCSfile
Main.h,v
Date
2006/02/16 18:11:22

Definition in file Main.h.

#include <inavr.h>
#include <iom169.h>

Include dependency graph for Main.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define cbi(port, bit)   (port &= ~(1<<bit))
#define CONTRAST   (*(unsigned char *) (0xE7))
#define DAY   (*(unsigned char *) (0x4F3))
#define FALSE   0
#define HOUR   (*(unsigned char *) (0x4F0))
#define MINUTE   (*(unsigned char *) (0x4F1))
#define MONTH   (*(unsigned char *) (0x4F4))
#define Nr_of_hex_bytes_to_send   11
#define OFFSET   (*(unsigned char *) (0x4FA))
#define REVISION_H   0x30
#define REVISION_L   0x33
#define sbi(port, bit)   (port |= (1<<bit))
#define SECOND   (*(unsigned char *) (0x4F2))
#define SET_POINT   (*(unsigned char *) (0x4F7))
#define TEMP_HIGHBYTE   (*(unsigned char *) (0x4F8))
#define TEMP_LOWBYTE   (*(unsigned char *) (0x4F9))
#define TRUE   1
#define YEAR_HI   (*(unsigned char *) (0x4F5))
#define YEAR_LO   (*(unsigned char *) (0x4F6))

Functions

void Delay (int)
 Delay-routine.
void Initialization (void)
 Initialize the different modules of the ATmega169(P).
void OSCCAL_calibration (void)
 Calibrate the internal OSCCAL byte, using the external 32,768 kHz crystal as reference.


Define Documentation

#define cbi port,
bit   )     (port &= ~(1<<bit))
 

Definition at line 40 of file Main.h.

#define CONTRAST   (*(unsigned char *) (0xE7))
 

Definition at line 51 of file Main.h.

Referenced by Initialization().

#define DAY   (*(unsigned char *) (0x4F3))
 

Definition at line 56 of file Main.h.

Referenced by RTC_init(), and Time_update().

#define FALSE   0
 

Definition at line 42 of file Main.h.

Referenced by LCD_Init(), LCD_SOF_interrupt(), LCD_update(), LCDsetupData(), OSCCAL_calibration(), Store_RX_data(), Time_update(), and USART0_RXC_interrupt().

#define HOUR   (*(unsigned char *) (0x4F0))
 

Definition at line 53 of file Main.h.

Referenced by RTC_init(), Send_TX_data(), Store_RX_data(), and Time_update().

#define MINUTE   (*(unsigned char *) (0x4F1))
 

Definition at line 54 of file Main.h.

Referenced by RTC_init(), and Time_update().

#define MONTH   (*(unsigned char *) (0x4F4))
 

Definition at line 57 of file Main.h.

Referenced by RTC_init(), and Time_update().

#define Nr_of_hex_bytes_to_send   11
 

Definition at line 65 of file Main.h.

Referenced by Send_TX_data().

#define OFFSET   (*(unsigned char *) (0x4FA))
 

Definition at line 63 of file Main.h.

Referenced by Temperature_regulation().

#define REVISION_H   0x30
 

Definition at line 25 of file Main.h.

Referenced by Send_TX_data().

#define REVISION_L   0x33
 

Definition at line 26 of file Main.h.

Referenced by Send_TX_data().

#define sbi port,
bit   )     (port |= (1<<bit))
 

Definition at line 39 of file Main.h.

#define SECOND   (*(unsigned char *) (0x4F2))
 

Definition at line 55 of file Main.h.

Referenced by RTC_init(), Time_update(), and TIMER2_OVF_interrupt().

#define SET_POINT   (*(unsigned char *) (0x4F7))
 

Definition at line 60 of file Main.h.

Referenced by ADC_init(), and Temperature_regulation().

#define TEMP_HIGHBYTE   (*(unsigned char *) (0x4F8))
 

Definition at line 61 of file Main.h.

Referenced by Temp_calculation(), and Temperature_regulation().

#define TEMP_LOWBYTE   (*(unsigned char *) (0x4F9))
 

Definition at line 62 of file Main.h.

Referenced by Temp_calculation().

#define TRUE   1
 

Definition at line 43 of file Main.h.

Referenced by LCD_SOF_interrupt(), LCD_update(), LCDsetupData(), OSCCAL_calibration(), Time_update(), and USART0_RXC_interrupt().

#define YEAR_HI   (*(unsigned char *) (0x4F5))
 

Definition at line 58 of file Main.h.

Referenced by RTC_init(), and Time_update().

#define YEAR_LO   (*(unsigned char *) (0x4F6))
 

Definition at line 59 of file Main.h.

Referenced by RTC_init(), and Time_update().


Function Documentation

void Delay int  i  ) 
 

Delay-routine.

Parameters:
i - delay

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 }

void Initialization void   ) 
 

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:

void OSCCAL_calibration void   ) 
 

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:


Generated on Fri Feb 17 12:28:30 2006 for AVR064: A Temperature Monitoring System with LCD Output by  doxygen 1.4.5