24 hour or 12 hour modes.
code was quickly cut for the 20x2 hopefully it will help ! lol
both programs will display in the terminal window 12 hour format.
To program the ds1307 in 24 hour mode we enter for
hours $00 to $23
mins $00 to $59
secs $00 to $59
To program the ds1307 in 12 hour mode we enter for
hours AM $41 to $52 (1-12)
hours PM $61 to $72 (1-12)
mins $00 to $59
secs $00 to $59
code was quickly cut for the 20x2 hopefully it will help ! lol
both programs will display in the terminal window 12 hour format.
To program the ds1307 in 24 hour mode we enter for
hours $00 to $23
mins $00 to $59
secs $00 to $59
Code:
# picaxe20x2
# no_data
# no_table
SYMBOL character1 = B2
SYMBOL character2 = B3
SYMBOL character3 = B4
SYMBOL character4 = B5
SYMBOL character5 = B6
SYMBOL character6 = B7
SYMBOL hours = B8
SYMBOL mins = B9
SYMBOL secs = B10
SYMBOL day = B11
SYMBOL date = B12
SYMBOL month = B13
SYMBOL year = B14
SYMBOL PM_AM = B15
Program:
HI2Csetup I2Cmaster, %11010000, I2Cslow, I2Cbyte ' set to 100kbps
HI2Cout $0, ( $00,$58 ,$23 ,day,date,month,year) ' write time to DS1307 example (11.58.00 PM)
'prog time (secs,mins,hours,day,date,month,year) ' enter hours in 24 hour format ($0 to $23)
Main:
HI2Csetup I2Cmaster, %11010000, I2Cslow, I2Cbyte
HI2Cin $0, (secs,mins,hours,day,date,month,year) ' read time DS1307
ClockDisplay:
PM_AM ="P" : IF hours < $12 then :PM_AM = "A" : ENDIF 'indicate PM or AM
IF hours = $20 OR hours = $21 THEN : LET hours = hours - $6 : ENDIF
IF hours > $12 THEN : LET hours = hours - $12 : ENDIF '24 to 12 hour format
IF hours = $0 THEN : hours = $12 : ENDIF
BcdTOASCII hours,character1,character2 : IF character1 = "0" THEN : character1 = " " : ENDIF' zero blanking character1
BcdTOASCII mins ,character3,character4
BcdTOASCII secs ,character5,character6
sertxd (CR, LF,character1,character2,".",character3,character4,".",character5,character6," ",PM_AM,"M", CR, LF)'(11.58.00 PM)
pause 1000 : goto main
hours AM $41 to $52 (1-12)
hours PM $61 to $72 (1-12)
mins $00 to $59
secs $00 to $59
Code:
# picaxe20x2
# no_data
# no_table
SYMBOL character1 = B2
SYMBOL character2 = B3
SYMBOL character3 = B4
SYMBOL character4 = B5
SYMBOL character5 = B6
SYMBOL character6 = B7
SYMBOL hours = B8
SYMBOL mins = B9
SYMBOL secs = B10
SYMBOL day = B11
SYMBOL date = B12
SYMBOL month = B13
SYMBOL year = B14
SYMBOL AM_PM = B15
Program:
HI2Csetup I2Cmaster, %11010000, I2Cslow, I2Cbyte ' set to 100kbps
HI2Cout $0, ( $00,$58 , $71 ,day,date,month,year) ' write time to DS1307 example (11.58.00 PM)
' prog time (secs,mins,hours,day,date,month,year) ' hours AM 1-12 ($41 to $52)
' hours PM 1-12 ($61 to $72)
Main:
HI2Csetup I2Cmaster, %11010000, I2Cslow, I2Cbyte
HI2Cin $0 ,(secs,mins,hours,day,date,month,year) ' read time DS1307
ClockDisplay:
LET hours = hours - $40 :AM_PM = "A" ' 12 hour format AM
IF hours > $20 THEN : LET hours = hours - $20 : AM_PM ="P": ENDIF ' 12 hour format PM
BcdTOASCII hours,character1,character2 : IF character1 = "0" THEN : character1 = " " : ENDIF' zero blanking character1
BcdTOASCII mins ,character3,character4
BcdTOASCII secs ,character5,character6
sertxd (CR, LF,character1,character2,".",character3,character4,".",character5,character6," ",AM_PM,"M", CR, LF)'(11.58.00 PM)
pause 1000 : goto main
Last edited: