'////////////////////////////////////////////////////////////// '/// App AVR134 - Real Time Clock (RTC) using Async Timer /// '/// This is FastAVR version of how to implement a Real /// '/// Time Clock on AVR controlers using Async timer. /// '/// /// '/// STK-200, STK-300, STK-500 www.FastAVR.com /// '/// LED0 : seconds /// '/// LED1-LED6: minutes /// '/// LED7 : hour /// '/// year represents only units and tenth's of year /// '////////////////////////////////////////////////////////////// $Device= Mega103 ' used device $Stack = 32 ' stack depth $Clock = 4 ' adjust for used crystal $Timer0=Timer, Prescale=128, Async $Lcd = PORTA.0, RS=PORTA.5, EN=PORTA.4, 16, 2 $LeadChar="0", Format (2,0) Declare Interrupt Ovf0() Dim sec As Byte, min As Byte, hour As Byte Dim day As Byte, month As Byte, year As Byte 'Wait 1 ' wait for stabilize hour=23: min=59: sec=0 day=3: month=5: year=3 Start Timer0 Enable Ovf0 Enable Interrupts Do 'PowerSave Loop '////////////////////////////////////////////////////////////// Interrupt Ovf0(), Save 2 Incr sec If sec=60 Then sec=0 Incr min If min=60 Then min=0 Incr hour If hour=24 Then hour=0 Incr day If day=32 Then day=1 Incr month ElseIf day=31 Then If month=4 Or month=6 Or month=9 Or month=11 Then day=1 Incr month End If ElseIf day=30 Then If month=2 Then day=1 Incr month End If ElseIf day=29 Then If month=2 And (year mod 4)>0 Then day=1 Incr month End If End If If month=13 Then month=1 Incr year End If End If End If End If Locate 1,1: Lcd hour; ":"; min; ":"; sec Locate 2,1: Lcd day; "-"; month; "-20"; year End Interrupt