Im a moron or something.....problems with 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
Tora OS

Im a moron or something.....problems with time.

Post by Tora OS »

Well i seem to have a few problems getting the time to display correctly. It seems to display numbers which are close to (meaning 6 or 12 or 16 off from the real time), but not the numbers. the code seems to work fine for date/time values that are less than 10.


BTW...this is my first real experience with C, so my code is probably pretty bad. Helpful pointers are appreciated too.


Code:
http://babb.sytes.net/PUB/Tora%20OS/timefunction.txt

Pic of what happens:
http://babb.sytes.net/PUB/Tora%20OS/Tor ... 0time..JPG
retainsoft

Re:Im a moron or something.....problems with time.

Post by retainsoft »

Hi it seems your'e making a mistake with BCD and decimal. The CMOS as far as i know uses BCD notation meaning 14 = 20 and 12 = 18 which is clearly showing on your picture.

in short try:
time_hours_tens = (time_hours >> 4) & 0x0F;
time_hours_ones = (time_hours >> 0) & 0x0F;

time_minutes_tens = (time_minutes >> 4) & 0x0F;
time_minutes_ones = (time_minutes >> 0) & 0x0F;

repeat above for all other cases(if statements are not needed anymore).

Greets,

Rene (RetainSoft)
Tora OS

Re:Im a moron or something.....problems with time.

Post by Tora OS »

so >> and << are like the shr and shl operators in ASM.


cool. Thanks a lot.
Post Reply