rendered paste body#include <avr/interrupt.h>typedef struct { unsigned char second; unsigned char minute; unsigned char hour; unsigned char date; unsigned char month; unsigned int year; unsigned char changed;} time_t;time_t time={0,0,12,1,1,2007};char not_leap(void) //check for leap year{ if (!(time.year%100)) return (char)(time.year%400); else return (char)(time.year%4);} SIGNAL(SIG_OVERFLOW2) //overflow interrupt vector{ if (++time.second==60) //keep track of time, date, month, and year { time.second=0; if (++time.minute==60) { time.minute=0; if (++time.hour==24) { time.hour=0; if (++time.date==32) { time.month++; time.date=1; } else if (time.date==31) { if ((time.month==4) || (time.month==6) || (time.month==9) || (time.month==11)) { time.month++; time.date=1; } } else if (time.date==30) { if(time.month==2) { time.month++; time.date=1; } } else if (time.date==29) { if((time.month==2) && (not_leap())) { time.month++; time.date=1; } } if (time.month==13) { time.month=1; time.year++; } } } } time.changed=1;} void RTC_init(void){ TIMSK2 = 0; // disable OCIE2A and TOIE2 ASSR = (1<<AS2); // select asynchronous operation of Timer2 TCNT2 = 0; // clear TCNT2A TCCR2B = (1<<CS22) | (1<<CS20); // select precaler: 32.768 kHz / 128 = 1 sec between each overflow while(ASSR & (0x01 | 0x04)); // wait for TCN2UB and TCR2UB to be cleared TIFR2 = 0xFF; // clear interrupt-flags TIMSK2 = (1<<TOIE2); // enable Timer2 overflow interrupt}int main(void){RTC_init();sei();while(1) { }