Hi Roger, I'm no expert, but maybe this can be of some use.
I have these variables to display the time on an LCD
I then read the DS1307 and convert the BDC value into time as followsCode:TimeH var byte 'variable to store Hours TimeM var byte 'variable to store Minutes SS VAR Byte 'variable to store Seconds RTCsec var byte 'RTC Seconds RTCMin var byte 'RTC Minutes RTCHour var byte 'RTC Hours
Now maybe (I don't know as I've never written to an external e-prom) you can save the byte variables for TimeH, TimeM and SS with something likeCode:I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour] ' read the RTC 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) 'convert the BCD format of the mins register and store in variable timeM timeM=(timeM &$07)*10 timeM=timeM+(RTCMin&$0F) ss=(RTCSec>>4) 'convert the BCD format of the sec register and store in variable ss ss=(ss &$07)*10 ss=ss+(RTCSec&$0F) LCDOut $FE,$C0+11,#TimeH DIG 1,#TimeH DIG 0,":",#TimeM DIG 1,#TimeM DIG 0 'display the current time on the LCD
Like I said, I'm no expert, and may be sending you off on a tangent !!Code:I2Cwrite SDApin,SCLpin,$insert address of eeprom,[TimeH,TimeM,SS]
Forgot to add, this is the routine to convert to BDC if required
CounterA and CounterB are byte variables, as are setHR and setMN. I used these as the initial time to display on the LCD. For example I want to set the initial time to 12:00 I use 12 for setHR and 0 for setMN. If you need to convert from decimal to BDC before sending to the eepprom, then maybe this bit of code can help ??Code:CounterA=SetMN Gosub ConvertBCD RTCMin=CounterB CounterA=SetHR Gosub ConvertBCD RTCHour=CounterB I2Cwrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour] ConvertBCD: CounterB=CounterA DIG 1 ' CounterA is the entry variable CounterB=CounterB<<4 ' CounterB holds the converted BCD result on exit CounterB=CounterB+CounterA DIG 0 Return




Bookmarks