Hi,
I also tried a clock program with the DS1337, works good, just that the seconds do not stop at 59, it continues to 80....or 89, thats was last night. How can the chip gives me this kinf of values ????
K
Hi,
I also tried a clock program with the DS1337, works good, just that the seconds do not stop at 59, it continues to 80....or 89, thats was last night. How can the chip gives me this kinf of values ????
K
The clock setting and ouput values are in BCD
There are lots of DS1307 examples on the forum that explain the conversion.
Charles Linquist
I think it might the mod mode, I will try this tonight, basic basic basic:
Code:while RTCHour != 1 I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl] Pause 20 'Will get the time from timer chip and do a 60 min count down 'Also add interrupt if someone presses start to view the charge/discharge cycle Rest_seconds = 59 - RTCSec Rest_min = 59 - RTCMin lcdout $FE,1, "Time: ", dec2 RTCHour, ":", dec2 RTCMin, ":", dec2 RTCSec lcdout $FE,$C0, " Dif: ", dec2 RTCHour, ":", dec2 Rest_min ,":", dec2 Rest_seconds Pause 150 Wend
BCD... o crap, yes would explain why it went from 9 to 16 !!!, thanks. Missed that on the spec sheet.
Code:sec VAR BYTE ' seconds mins VAR BYTE ' minutes hr VAR BYTE ' hours day VAR BYTE ' day date VAR BYTE ' date mon VAR BYTE ' month yr VAR BYTE ' year 'DEC VARS SEC_O VAR BYTE SEC_T VAR BYTE MIN_O VAR BYTE MIN_T VAR BYTE HR_O VAR BYTE HR_T VAR BYTE MON_O VAR BYTE MON_T VAR BYTE DATE_O VAR BYTE DATE_T VAR BYTE YR_O VAR BYTE YR_T VAR BYTE '################################################# READ_RTC: I2CREAD DS_SDA, DS_SCL, RTC, SecReg, [sec,mins,hr,day,date,mon,yr] SEC_T = sec & $70 SEC_T = SEC_T>>4 SEC_O = sec & $0F MIN_T = mins & $70 MIN_T = MIN_T>>4 MIN_O = MINs & $0F HR_T = hr & $70 HR_T = HR_T>>4 HR_O = hr & $0F MON_T = mon & $70 MON_T = MON_T>>4 MON_O = mon & $0F DATE_T = date & $70 DATE_T = DATE_T>>4 DATE_O = date & $0F YR_T = yr & $70 YR_T = YR_T>>4 YR_O = yr & $0F
Dave
Always wear safety glasses while programming.
Hey dave, thanks for the help. I had written this program with two Subroutine that I found on this site somewhere.. I will test it tonight.
Code:CountDown: I2CWRITE SDApin,SCLpin,$D0,$00,[$00,$00,$00,$00,$00,$00,$00,$00] ' Write to DS1307 to start counter at ZERO Pause 20 while RTCHour != 1 I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl] Pause 20 'Will get the time from timer chip and do a 60 min count down 'Also add interrupt if someone presses start to view the charge/discharge cycle TempVal=RTCSec GoSub BCD_TO_BIN Secs=TempVal TempVal=RTCmin GoSub BCD_TO_BIN Mins=TempVal Rest_seconds = 59 - Secs Rest_min = 59 - Mins lcdout $FE,1, "Time: ", dec2 RTCHour, ":", dec2 RTCMin, ":", dec2 RTCSec lcdout $FE,$C0, " Dif: ", dec2 RTCHour, ":", dec2 Rest_min ,":", dec2 Rest_seconds Pause 150 Wend return BCD_TO_BIN: ' Convert the BCD values into BIN Temp1 = $0F & TempVal ' Clear off the top four bits Temp1 = Temp1 Dig 0 Temp2 = TempVal >> 4 ' Shift down four to read 2 BCD value Temp2 = Temp2 Dig 0 TempVal = Temp2 * 10 + Temp1 Return BIN_TO_BCD: Temp1 = TempVal Dig 0 ' GET THE DEC DIGIT FOR THE FIRST NIBBLE Temp2 = TempVal Dig 1 ' GET THE DEC DIGIT FOR THE FIRST NIBBLE Temp2 = Temp2 << 4 ' MOVE NUMBER OVER TO 2ND NIBBLE TempVal = Temp1 ^ Temp2 ' XOR THEM TOGTHER TO MAKE THE WHOLE BCD NUMBER Return
Bookmarks