I'm working on a new project with a DS1307. My end goal is to have a GoPro start recording on the time of day by using a servo and a DS1307 RTC. I have the RTC working but I'd like to be able to set the time via the serial port. I've been trying to modify the code from this thread. The problem I'm having is in the conversion between ASCII output from the terminal window and the BCD input the the RTC is expecting. So when I enter a 1 for the variable "mins", I get back a 31 which is the hex value for 1. I've been trying to find a solution to this but have failed so far.
Any tips would be wonderful. Thanks.
Any tips would be wonderful. Thanks.
Code:
'########################################
'# For PICAXE-28X1 and MAXIM DS1307 RTC #
'########################################
#picaxe 20m2
SetFreq m8
'########################################
symbol sec = b3
symbol mins = b4
symbol hrs = b5
symbol dow = b6
symbol day = b7
symbol mth = b8
symbol yr = b9
#rem
sec = $0
mins = $0
hrs = $1
dow = $2
day = $3
mth = $4
yr = $14
#endrem
serrxd("set "), mins ', mins, hrs, dow, day, mth, yr
Main:
'DS1307 CODE
pause 2000
' Set up i2c for device
hi2csetup i2cmaster, %11010000, i2cslow_8, i2cbyte '%11010000 is device i2c bus address
'''hi2cout 0, ($00,$27,$23,$04,$20,$07,$16,%00010000)
hi2cout 0, (sec, mins, hrs, dow, day, mth, yr, %00010000)
DS1307:
pause 1800
hi2cin 6,(b0)
bcdtoascii b0, b1, b2 ' DS1307 stores data in BCD format
sertxd ("Date/Time:- Yr:",b1,b2) ' Write output to terminal
hi2cin 5,(b0) ' Month Read from register 5
bcdtoascii b0, b1, b2
sertxd (" Mo:", b1, b2)
hi2cin 4,(b0) ' Day Read from register 4
bcdtoascii b0, b1, b2
sertxd (" Day:", b1, b2)
hi2cin 3,(b0) ' DoW Read from register 3
bcdtoascii b0, b1, b2
If b2 = "1" then sertxd (" DoW:","Su") 'convert Ascii 1-7 Day of Week number to Text
elseif b2 = "2" then sertxd (" DoW:","Mo")
elseif b2 = "3" then sertxd (" DoW:","Tu")
elseif b2 = "4" then sertxd (" DoW:","We")
elseif b2 = "5" then sertxd (" DoW:","Th")
elseif b2 = "6" then sertxd (" DoW:","Fr")
elseif b2 = "7" then sertxd (" DoW:","Sa")
EndIf
hi2cin 2,(b0) ' Hour Read from register 2
bcdtoascii b0, b1, b2
sertxd (" Hr:", b1, b2)
hi2cin 1,(b0) ' Minute Read from register 1
bcdtoascii b0, b1, b2
sertxd (" Min:", b1, b2)
hi2cin 0,(b0) ' Second Read from register 0
bcdtoascii b0, b1, b2
sertxd (" Sec:", b1, b2)
sertxd (" min = ", mins, cr, lf)
'goto DS1307