Hi,
I am revisiting a problem I had a long time ago with the output of my DS1307. I used code to overcome this problem before but I want to understand why this is happening.
When I ouput to my LCD the hour and minute from my DS1307 board (http://www.futurlec.com/Mini_DS1307.shtml) it work except for 9 PM and 8 PM.
For 8 PM I get the output 0>:00 PM and for 9 PM I get 0?:00 PM.
Can someone please help me with this? I opted for converting 24 hour format to AM PM format through coding instead of reproggramming the DS1307 for AM PM mode. Thhis was frustrating me as well.
Here is my code.
#picaxe 28x1 'Sets type of picaxe chip for this program
setfreq m8 'You need to set freq. to 8hz to get a 9600 baud
symbol seconds = b0
symbol minutes = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7
symbol ampm = b10
serout 7,T9600_8,(254, $01) 'Clears Screen
hi2csetup i2cmaster,%11010000,i2cslow_8,i2cbyte
main:
hi2cin 0, (seconds,minutes,hour,day,date,month,year,control)
'Set ampm variable
if hour >= $12 and hour < $24 then let ampm = 1
else let ampm= 0
endif
'12 hour time for LCD display
if hour > $12 and hour < $24 then let hour = hour - $12
elseif hour = $0 then let hour = $12
else let hour = hour
endif
bcdtoascii hour,b8,b9
if ampm =1 then serout 7,T9600_8,(254, 197," ",b8,b9,":"): serout 7, T9600_8, (254, 204, "PM")
else serout 7,T9600_8,(254, 197," ",b8,b9,":"): serout 7, T9600_8, (254, 204, "AM")
endif
bcdtoascii minutes, b8,b9 'Displays minutes
serout 7,T9600_8,(254, 201,b8,b9)
b8 = minutes
minutes = b8 / 16 * 10
minutes = b8 & $F + minutes
goto main
Thanks!!!!
I am revisiting a problem I had a long time ago with the output of my DS1307. I used code to overcome this problem before but I want to understand why this is happening.
When I ouput to my LCD the hour and minute from my DS1307 board (http://www.futurlec.com/Mini_DS1307.shtml) it work except for 9 PM and 8 PM.
For 8 PM I get the output 0>:00 PM and for 9 PM I get 0?:00 PM.
Can someone please help me with this? I opted for converting 24 hour format to AM PM format through coding instead of reproggramming the DS1307 for AM PM mode. Thhis was frustrating me as well.
Here is my code.
#picaxe 28x1 'Sets type of picaxe chip for this program
setfreq m8 'You need to set freq. to 8hz to get a 9600 baud
symbol seconds = b0
symbol minutes = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7
symbol ampm = b10
serout 7,T9600_8,(254, $01) 'Clears Screen
hi2csetup i2cmaster,%11010000,i2cslow_8,i2cbyte
main:
hi2cin 0, (seconds,minutes,hour,day,date,month,year,control)
'Set ampm variable
if hour >= $12 and hour < $24 then let ampm = 1
else let ampm= 0
endif
'12 hour time for LCD display
if hour > $12 and hour < $24 then let hour = hour - $12
elseif hour = $0 then let hour = $12
else let hour = hour
endif
bcdtoascii hour,b8,b9
if ampm =1 then serout 7,T9600_8,(254, 197," ",b8,b9,":"): serout 7, T9600_8, (254, 204, "PM")
else serout 7,T9600_8,(254, 197," ",b8,b9,":"): serout 7, T9600_8, (254, 204, "AM")
endif
bcdtoascii minutes, b8,b9 'Displays minutes
serout 7,T9600_8,(254, 201,b8,b9)
b8 = minutes
minutes = b8 / 16 * 10
minutes = b8 & $F + minutes
goto main
Thanks!!!!