Thanks guys for your comments.
I still haven't got to the bottom as to why the display jumps to 08:00 when turning 16:00 when powered up, but won't do it when the time is set manually to something like 15:58.
I've browsed through my other snippets of code for RTC and came up with this.
This worked a treat and seems a better way than having all the BCD conversion code that other examples used, and I've used in my current project. However I want to be able to use variables to set the time so I tried substituting [$00,$00,$19,$7,$14,$2,$10,$90] for [RTCSec,RTCMin,RTCHour,RTCDay,RTCMonth,RTCYear,$90] and then have the following to set the hrs and mins and copy them to the RTC variablesCode:DB0 var byte[8] CMCON = %00000111 ' Comparators = off gosub write_1307 read_1307: ' Read time Secs,Mins,Hours,Day,Date,Month,Year,Control I2CREAD SDA,SCL,$D1,$00,[STR DB0\8] ' Read 8 bytes from DS1307 lcdout $fe,1,"Time=",hex2 DB0[2],":",hex2 DB0[1],":",hex2 DB0[0] 'bit 0=sec, bit 1=min, bit 2=hrs lcdout $fe,$c0,"Date=",hex2 DB0[4],":",hex2 DB0[5],":",hex2 db0[6] 'bit 4=day, bit 5=month, bit 6=year goto read_1307 end Write_1307: ' Set time & date to 19:00:00 14th Feb 201 I2CWRITE SDA,SCL,$D0,$00,[$00,$00,$19,$7,$14,$2,$10,$90] ' Write to DS1307 pause 10 RETURN ' Sec Min Hr Day D M Y Control
The original example has the following to read the DS1307 and display the second and 1st bytes for the timeCode:LCDOUT $FE,1 LCDOUT $FE,2,"Set Time" inp3: IF H_butt = 0 THEN GOSUB IncHours IF M_butt = 0 THEN GOSUB IncMinutes SetHour=Hours SetMin=Minutes LCDOUT $FE,$C0,#SetHour DIG 1,#SetHour DIG 0,":",#SetMin DIG 1,#SetMin DIG 0 pause 200 If S_butt = 0 then pause 250 goto savetime endif goto inp3 savetime: RTCmin = setmin rtchour = sethour gosub Write_1307 Write_1307: ' Secs,Mins,Hours,Day,Date,Month,Year,Control I2CWrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCDay,RTCMonth,RTCYear,$90] pause 10 RETURN
This worked fine when the values for the time and date etc were stored a $10,$30 etc, but when I used the RTChour and RTCmin variables the LCD displays 0A:1E when RTCHour=10 and RTCMin=30 for example. I'm sure it's a classic noob error, but for the life of me I can't see what I need to do to store the values for these variables in the I2Cwrite statement, and then read them back and display them correctly on the screen.Code:I2CREAD SDApin,SCLpin,$D1,$00,[STR DB0\8] ' Read 8 bytes from DS1307 Secs,Mins,Hours,Day,Date,Month,Year,Control LCDOut $FE,$c0+11,hex2 DB0[2],":",hex2 DB0[1]




Bookmarks