My current project is not performing very well. It relies on matching the values in two variables to the converted BDC format from a battery backed up 1307 RTC. My idea is to use a variable to store the current time in minutes from midnight, so in theory it should have a value between 0 and 1439. The idea then is to convert the time the LEDs come on into a numerical value and the use the "if then " statement to determine if the LEDs should be on in the event of a power cut. For example if the on time was from 14:00 to 18:00 hrs then the values would be => then 840 but =< 1080, so if there was a power cut and power was resumed at say 15:00 hrs then as the time would be converted to 900 and the logic would then check the value against the programmed value and thus turn the LEDs on. This is my proposed code (with some of the RTC variables not included for simplicity)
Code:
Counter 1 var byte
counter 2 var byte
counter 3 var byte
TimeH var byte ' Variable to store current hour
TimeM var Byte ' Variable to store current minutes
Main:
I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl] ; read DS1307 chip
timeH=(RTCHour>>4) 'convert the BCD format of the hours register and store in variable timeH
timeH=(timeH &$03)*10
timeH=timeH+(RTCHour&$0F)
timeM=(RTCMin>>4)
timeM=(timeM &$07)*10
timeM=timeM+(RTCMin&$0F) 'convert the BCD format of the mins register and store in variable timeM
If TimeH = 0 and timeM = 0 then
couner 3 = 0
endif
If TimeH <1 then counter 1 = 0
If timeH >0 then counter 1 = Time H * 60
Counter 3 = counter1 + TimeM
Endif
endif
Would welcome comments
Bookmarks