Get CMOS time

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Thunder

Get CMOS time

Post 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
Tim

Re:Get CMOS time

Post 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);
Thunder

Re:Get CMOS time

Post 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
Tim

Re:Get CMOS time

Post by Tim »

That's exactly the same thing :).
Post Reply