24 hour or 12 hour modes.
We can write or read Time or Calenda information from the appropiate register bytes which is in BCD format.
both programs will display in a 12 hour format using the terminal window .
Using 24 hour mode we enter for
hours $00 to $23
mins $00 to $59
secs $00 to $59
Using 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
We can write or read Time or Calenda information from the appropiate register bytes which is in BCD format.
both programs will display in a 12 hour format using the terminal window .
Using 24 hour mode we enter for
hours $00 to $23
mins $00 to $59
secs $00 to $59
Code:
# no_data
#terminal 9600
SETFREQ M8
SYMBOL secs = b2
SYMBOL mins = b3
SYMBOL hours = b4
SYMBOL day = b5
SYMBOL date = b6
SYMBOL month = b7
SYMBOL year = b8
SYMBOL PM_AM = b9
SYMBOL D0 = b10
SYMBOL D1 = b11
SYMBOL D2 = b12
SYMBOL D3 = b13
SYMBOL D4 = b14
SYMBOL D5 = b15
Initialize:
HI2Csetup I2Cmaster, %11010000, I2Cfast_8, I2Cbyte ' Set to 400kbps
' HI2Cout $0 , ( $14, $59, $11 ,day, $11, $01 , $15) ' Uncomment to Program DS3231 example (11.59.00 AM)
;Progam Registers (secs,mins,hours,day,date,month,year) ' Enter in BCD hours example ( $0 to $23 )
' HI2Cout $0E, ($0) ' Control (turn On 1hz $0) output Pin3 ( Off $4)
Main:
PAUSE 1000
ReadRegisters:
HI2Cin $0 , (secs,mins,hours,day,date,month,year) ' Read from DS3231
ClockDisplay:
PM_AM ="P" : IF hours < $12 THEN :PM_AM = "A" :ENDIF 'Indicate P or A
IF hours =$20 OR hours =$21 THEN :hours = hours -$6 :ENDIF
hours = hours //$12 : IF hours =$0 THEN: hours =$12 :ENDIF '24 to 12 hour format
BcdTOASCII hours,D5,D4 : IF D5 = "0" THEN: D5 = " " :ENDIF 'Zero blanking
BcdTOASCII mins ,D3,D2
BcdTOASCII secs ,D1,D0
sertxd (CR,LF,D5,D4,".",D3,D2,".",D1,D0," ",PM_AM,"M ") '(11.59.00 PM )
BcdTOASCII date ,D5,D4
BcdTOASCII month,D3,D2
BcdTOASCII year ,D1,D0
sertxd (D5,D4,"/",D3,D2,"/20",D1,D0) '( 28/06/2011 )
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:
# no_data
#terminal 9600
SETFREQ M8
SYMBOL secs = b2
SYMBOL mins = b3
SYMBOL hours = b4
SYMBOL day = b5
SYMBOL date = b6
SYMBOL month = b7
SYMBOL year = b8
SYMBOL AM_PM = b9
SYMBOL D0 = b10
SYMBOL D1 = b11
SYMBOL D2 = b12
SYMBOL D3 = b13
SYMBOL D4 = b14
SYMBOL D5 = b15
Initialize:
HI2Csetup I2Cmaster, %11010000, I2Cfast_8, I2Cbyte ' Set to 100kbps
' HI2Cout $0 , ( $14, $59, $51 ,day, $11, $01 , $15) ' Uncomment to Program DS3231 example (11.59.00 AM )
;Progam Registers (secs,mins,hours,day,date,month,year) ' Enter in BCD example hours AM 1-12 ( $41 to $52 )
' example hours PM 1-12 ( $61 to $72 )
' HI2Cout $0E, ($0) ' Control (turn On 1hz $0) output Pin3 ( Off $4)
Main:
pause 1000
ReadRegisters:
HI2Cin $0 , (secs,mins,hours,day,date,month,year) ' Read from DS3231
ClockDisplay:
AM_PM = "A" : IF hours >$60 THEN : AM_PM ="P": ENDIF ' 12 hour format PM
D5 = hours &$10 /$10 +$30 : IF D5 = "0" THEN : D5 = " " : ENDIF 'Zero blanking
D4 = hours //$10
D3 = mins /$10
D2 = mins //$10
D1 = secs /$10
D0 = secs //$10
sertxd (CR,LF,D5,#D4,".",#D3,#D2,".",#D1,#D0," ",AM_PM,"M ")'(11.59.00 PM )
D5 = date /$10
D4 = date //$10
D3 = month /$10
D2 = month //$10
D1 = year /$10
D0 = year //$10
sertxd (#D5,#D4,"/",#D3,#D2,"/20",#D1,#D0) '(11/01/2015)
GOTO Main
Last edited: