00001
00050 #include "avr_compiler.h"
00051 #include "rtc_driver.h"
00052
00053
00054 #define LED_PORT PORTD
00055 #define RTC_CYCLES_1S 1024
00056
00057
00059 typedef struct RTC_BCD_struct{
00060 uint8_t sec_ones;
00061 uint8_t sec_tens;
00062 } RTC_BCD_t;
00063
00064
00078 int main(void)
00079 {
00080
00081 OSC.CTRL |= OSC_RC32KEN_bm;
00082
00083 do {
00084
00085 } while ( ( OSC.STATUS & OSC_RC32KRDY_bm ) == 0);
00086
00087
00088
00089 CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;
00090
00091
00092 LED_PORT.DIR = 0xFF;
00093
00094 do {
00095
00096 } while ( RTC_Busy() );
00097
00098
00099 RTC_Initialize( RTC_CYCLES_1S, 0, 0, RTC_PRESCALER_DIV1_gc );
00100
00101
00102 RTC_SetIntLevels( RTC_OVFINTLVL_LO_gc, RTC_COMPINTLVL_OFF_gc );
00103
00104
00105 PMIC.CTRL |= PMIC_LOLVLEN_bm;
00106 sei();
00107
00108 do {
00109
00110 nop();
00111 } while (1);
00112 }
00113
00114
00120 ISR(RTC_OVF_vect)
00121 {
00122 static RTC_BCD_t rtcTime;
00123
00124
00125
00126
00127 if ( ++rtcTime.sec_ones > 9 ) {
00128 rtcTime.sec_ones = 0;
00129 rtcTime.sec_tens++;
00130 }
00131
00132
00133 if ( rtcTime.sec_tens > 5 ) {
00134 rtcTime.sec_tens = 0;
00135 }
00136
00137
00138 LED_PORT.OUT = ~( ( rtcTime.sec_tens << 4 ) | rtcTime.sec_ones );
00139 }