RTC.h File Reference


Detailed Description

Prototypes for RTC.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
RTC.h,v
Date
2006/02/16 18:11:22

Definition in file RTC.h.

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

Go to the source code of this file.

Functions

void RTC_init (void)
 Start Timer/Counter2 in asynchronous operation using a 32.768kHz crystal.
void Time_update (void)
 Updates the time and date variables.


Function Documentation

void RTC_init void   ) 
 

Start Timer/Counter2 in asynchronous operation using a 32.768kHz crystal.

Definition at line 35 of file RTC.c.

References DAY, Delay(), HOUR, MINUTE, MONTH, SECOND, YEAR_HI, and YEAR_LO.

Referenced by Initialization().

00036 {
00037     Delay(1000);            // wait for 1 sec to let the Xtal stabilize after a power-on,
00038 
00039     __disable_interrupt();  // disabel global interrupt
00040 
00041     TIMSK2 = 0;             // disable OCIE2A and TOIE2
00042 
00043     ASSR = (1<<AS2);        // select asynchronous operation of Timer2
00044 
00045     TCNT2 = 0;              // clear TCNT2A
00046     TCCR2A = (1<<CS22) | (1<<CS20);             // select precaler: 32.768 kHz / 128 = 1 sec between each overflow
00047 
00048     while(ASSR & (0x01 | 0x04));       // wait for TCN2UB and TCR2UB to be cleared
00049 
00050     TIFR2 = 0xFF;           // clear interrupt-flags
00051     TIMSK2 = (1<<TOIE2);    // enable Timer2 overflow interrupt
00052 
00053     __enable_interrupt();                 // enable global interrupt
00054 
00055     // initial time and date setting
00056     HOUR = 8;
00057     MINUTE = 0;
00058     SECOND = 0;
00059     DAY = 4;
00060     MONTH = 11;
00061     YEAR_LO = 2;
00062     YEAR_HI = 20;
00063 }

Here is the call graph for this function:

void Time_update void   ) 
 

Updates the time and date variables.

Definition at line 68 of file RTC.c.

References DAY, FALSE, HOUR, MaxDate, MINUTE, MONTH, SECOND, TRUE, YEAR_HI, and YEAR_LO.

Referenced by main().

00069 {
00070    unsigned char LeapYear = FALSE;
00071 
00072     //the variable SECOND gets updated in the Timer0 Overflow Interrupt Routine every second
00073 
00074     if(SECOND > 59)                         // if one minute
00075     {
00076         SECOND = 0;                         // clear SECOND
00077         MINUTE++;                           // increment MINUTE
00078 
00079         if(MINUTE > 59)                     // if one hour
00080         {
00081             MINUTE = 0;                     // clear MINUTE
00082             HOUR++;                         // increment HOUR
00083 
00084             if(HOUR > 23)                   // if one hour
00085             {
00086                 HOUR = 0;                   // clear HOUR
00087                 DAY++;                      // increment DAY
00088 
00089                 if(MONTH == 2)              // if it's February
00090                 {
00091                     // check for leap year
00092                     if(!YEAR_LO)                        // if YEAR_LO = 0, (a century has passed)
00093                     {
00094                         if(!(YEAR_HI%4))                // check if YEAR_HI is divisible by 4
00095                             LeapYear = TRUE;                // then it is a leap year
00096                     }
00097                     else if(!(YEAR_LO%4) & (YEAR_LO != 0))  // else if YEAR_LO is divisible by 4 and not zero
00098                         LeapYear = TRUE;                    // then it's a leap year
00099                 }
00100 
00101                 if(DAY > (MaxDate[MONTH] + LeapYear))   // if a whole month has passed
00102                 {
00103                     DAY = 1;                // clear DAY
00104                     MONTH++;                // increment MONTH
00105 
00106                     if(MONTH > 12)          // if one year
00107                     {
00108                         MONTH = 1;          // clear MONTH
00109                         YEAR_LO++;          // increment YEAR_LO
00110 
00111                         if(YEAR_LO > 99)    // if one century
00112                         {
00113                             YEAR_LO = 0;    // clear YEAR_LO
00114                             YEAR_HI++;      // increment YEAR_HI
00115 
00116                             if(YEAR_HI > 99)    // if 100 centuries
00117                                 YEAR_HI = 0;    // the AVR is still going strong :)
00118                         }
00119                     }
00120                 }
00121             }
00122         }
00123     }
00124 }


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