Little confused with BCD to Decimal conversion and vice versa.
Please clarify, if I have 3 variables sec, minu, hrs and want decimal values in them, is the following correct?
AIM: To get the decimal values inside sec (0-59), minu (0-59) & Hrs (0-23)
The first thing my code is doing is resetting DS1307 with the following line of code:
Code:
I2CWRITE SDA,SCL,$D0,$00,[$17,$3B,$17,$01,$00,$00,$00,$90]
The above line only executes once only when PIC is powered for the first time only.
As you can see I choose a 24Hr format for my time. I also want to start my time with 23:59:23. I am only interested in hrs,min,sec,day only.
Now if I read back the time:
Code:
I2CREAD SDA,SCL,$D1,$00,[STR DB0\8]
and want decimal values in my variables, please guide what is the correct way of doing it as the following is not working
Code:
temp=db0[0]
sec =(temp>>4)*10+(temp & $0F)
temp=db0[1]
minu =(temp>>4)*10+(temp & $0F)
temp=db0[2]
hrs=(temp>>4)*10+(temp & $0F)
Lcdout $FE,1,DEC2 sec," : ",DEC2 minu," : ",DEC2 hrs
Bookmarks