Page 1 of 1

Get CMOS time

Posted: Wed Jul 09, 2003 10:46 am
by Thunder
Hello,
I have 3 bytes from CMOS: sec, min and hour.

The problem is that, when I decode digits into string, I get wrong time? (The converter from digit to string works fine)

Thanks. Bye

Re:Get CMOS time

Posted: Wed Jul 09, 2003 1:25 pm
by Tim
How are you decoding the digits? They're BCD encoded, which means that the high nibble and low nibble contain separate decimal digits. If you display the numbers as hex they will appear as their decimal equivalents. To convert to decimal, do:

Code: Select all

sec = ((sec_bcd & 0xf0) >> 16) * 10 + (sec_bcd & 0x0f);

Re:Get CMOS time

Posted: Wed Jul 09, 2003 2:13 pm
by Thunder
Thank you for explaining, but I use a bit different method:
TIME.hour=((TIME.hour>>4)*10+(TIME.hour & 0xF));

Thanks again :). Bye

Re:Get CMOS time

Posted: Wed Jul 09, 2003 3:11 pm
by Tim
That's exactly the same thing :).