Hello all,
I did the search ad review before putting up this post and was close with a few hints from Hippy but still no luck. I am trying to update or reset the time, if it loses time, through a serin command.
My code is not too pretty but needs help in building the HEX or BCD string to set the clock.
Sorry about the old commented code. This was close before I put the () around b13 etc trying to use the $ to convert the data.
I know the DS1307 has been through the wringer here many times but I have not seen this one as yet. All the samples seem to start with the Wizard code so the time is always set or hard coded not taking input from the serin command.
Thanks in advance,
PFM
I did the search ad review before putting up this post and was close with a few hints from Hippy but still no luck. I am trying to update or reset the time, if it loses time, through a serin command.
My code is not too pretty but needs help in building the HEX or BCD string to set the clock.
Code:
Set_Time:
sertxd ("Top of Set_Time",ret,lfeed)
high 2 'RED LED
low 3
i2cslave %11010000, i2cslow, i2cbyte 'setup i2c slave port
'sertxd ("setup I2C",ret,lfeed)
readi2c 0, (b13, b12, b11) 'get hours, mins, secs
'Convert BCD to decimal
'bcd_decimal:
let temp_byte = secs & %11110000 / 16 * 10
let secs = secs & %00001111 + temp_byte
let temp_byte = mins & %11110000 / 16 * 10
let mins = mins & %00001111 + temp_byte
let temp_byte = hours & %11110000 / 16 * 10
let hours = hours & %00001111 + temp_byte
' sertxd (#secs,COM,#mins,COM,#hours,COM,RET,LFEED)
sertxd ("Time Old ",#b11,":")
sertxd (#b12,":")
sertxd (#b13, ret,lfeed)
'sertxd (#b11, ret,lfeed)
sertxd ("enter hour 00-23 ")
b1 = 0
b2 = 0
serin 6,N4800_4, b1,b2 ' get two chars convert to decimal hours
b1=b1-48
b1=b1*10
b2=b2-48
b11= b1+b2
sertxd (b11, ret, lfeed)
'sertxd (b2, ret, lfeed)
pause 1000
b1 = 0
b2 = 0
sertxd ("enter next minute 00-59")
serin 6,N4800_4, b1,b2 ' get two chars convert to decimal minutes
b1=b1-48
b1=b1*10
b2=b2-48
b12= b1+b2
sertxd (b12, ret, lfeed)
pause 1000
b13 = 0
sertxd ("Set time to ",#b11,":")
sertxd (#b12, ":")
sertxd (#b13, "___ Y", ret,lfeed)
serin 6,N4800,("Y")
sertxd ("Write Time to RTC", ret,lfeed)
' NEED TO CONVERT DECIMAL TO HEX FOR THIS TO WORK OR DO A LOOKUP
'First program the date
high 5 ' write protect eeprom
i2cslave %11010000, i2cslow, i2cbyte
writei2c 0, ($(b13), $(b12), $(b11), $07, $02, $02, $07, $10)
pause 50
readi2c 0, (b13, b12, b11) 'get hours, mins, secs
'Convert BCD to decimal
'bcd_decimal:
let temp_byte = secs & %11110000 / 16 * 10
let secs = secs & %00001111 + temp_byte
let temp_byte = mins & %11110000 / 16 * 10
let mins = mins & %00001111 + temp_byte
let temp_byte = hours & %11110000 / 16 * 10
let hours = hours & %00001111 + temp_byte
' sertxd (#secs,COM,#mins,COM,#hours,COM,RET,LFEED)
sertxd ("New Time Set ",#b11,":")
sertxd (#b12,":")
sertxd (#b13, ret,lfeed)
'sertxd (#b13, ret,lfeed)
'sertxd (#b11, ret,lfeed)
I know the DS1307 has been through the wringer here many times but I have not seen this one as yet. All the samples seem to start with the Wizard code so the time is always set or hard coded not taking input from the serin command.
Thanks in advance,
PFM
Last edited: