Hi guys, I'm running a DS1307 and have experienced some strange jumps in time that has been replicated by a friend using his own development board. When the system is first powered up the clock displays the default time of 14:00, and runs ok until 15:59. When it rolls over to 16:00 it actually jumps to 08:00 and then continues to run Ok displaying 08:01, 08:02 etc. If after power up I set the time to 15:59 using the option in the menu it correctly displays 16:00 16:01 etc without issue. Equally, when it is powered up, displays 14:00 and trips to 08:00, if left to run on for 8 hours, it correctly displays 16:00 when the time has elapsed.

Here's are the time variables

Code:
;----[Variables/Aliases - Time]------------------------------------------

RTCSec              var byte	 ' Seconds
RTCMin              var byte     ' Minutes
RTCHour             var byte	 ' Hours
RTCWDay             var byte	 ' Weekday
RTCDay              var byte     ' Day
RTCMonth            var byte	 ' Months
RTCYear             var byte	 ' Year
RTCCtrl             var byte	 ' Control 
SetTime             var byte	 ' 12/24 Hour Clock
SetSec              var byte     ' Seconds
SetMin              var byte	 ' Minutes
SetHour             var byte	 ' Hours

TimeOut             var word	 ' Variable for SetUp Menu Time-Out
TimeH               var byte     ' Variable to store current hour for comparison to drop temp time
TimeM               var Byte     ' Variable to store current minutes for comparison to drop temp time
And then I have this initial setting

Code:
RTCSec=0
RTCMin=0
RTCHour=14

I2CWrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]
And then this is the section in the main loop that reads the chip and displays the time

Code:
I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]  ; read DS1307 chip
If RTCHour.6=1 then
			
CounterA=(RTCHour>>4)&$01                           ' Work-Out 12 or 24 hour Display for Hours
else
CounterA=(RTCHour>>4)&$03
endif
CounterA=CounterA*10+(RTCHour&$0F)                  ' Display Hours appropriately for 12 or 24 hour Mode 
If RTCHour.6=1 then			
LCDOut $FE,$c0+11,#CounterA
else
LCDOut $FE,$c0+11,#CounterA Dig 1,#CounterA Dig 0
endif
LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F

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
And finally here's the section that deals with manually setting the time from the menu

Code:
time:

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:
'	Save 12/24 Hours to BCD DS1307's Format
'	---------------------------------------
			CounterA=SetHour
			If SetTime=1 then
				If CounterA>12 then CounterA=CounterA-12
				If CounterA=0 then CounterA=12
				endif
			Gosub ConvertBCD
			RTCHour=CounterB
' Save the Hours Value
			If SetTime=1 then
				RTCHour.6=1
' Save the 12 Hour Mode Flag
				If SetHour=>12 then RTCHour.5=1
' Save the 'PM' Flag
				endif
'
'	Save Minutes
'	------------
			CounterA=SetMin
			Gosub ConvertBCD
			RTCMin=CounterB

            CounterA=SetSec
			Gosub ConvertBCD
			RTCSec=CounterB

I2CWrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]

goto mainmenu
I'm at a loss ? - any suggestions