Page 1 of 1

Realtime clock issue [SOLVED]

Posted: Fri Jun 18, 2010 5:50 pm
by TyrelHaveman
Hi guys,

I'm adding calendar-date/time tracking to my clock driver (rather than just counting ticks). I'm working on grabbing the current date and time from the RTC. It mostly works, except for one odd thing. Note (in case it's relevant) that I'm testing with Bochs 2.4.5.

The one thing that's not working is this: If I read "Status Register B" by doing an outb 11 (address for this register) on port 0x70 and an inb on port 0x71, bit 2 is not set, indicating that the numbers returned if I read the time will not be in BCD. However they are, in fact, in BCD. For example at 37 minutes past the hour, I got 0x37 (55) rather than 0x25 (37). Why is the status register lying to me?

The info I got on this status register comes from my copy of "The Indepensible PC Hardware Book", which is somewhat out of date, but I don't imagine this has changed. The only thing I found in the wiki was that it may be in BCD, but it doesn't say how to check whether it's in BCD or not. :-)

Any help would be appreciated!

Thanks,
Tyrel

Re: Realtime clock issue

Posted: Fri Jun 18, 2010 6:14 pm
by gerryg400
0 means BCD.

Re: Realtime clock issue

Posted: Fri Jun 18, 2010 6:22 pm
by TyrelHaveman
gerryg400 wrote:0 means BCD.
So the book is wrong?

Re: Realtime clock issue

Posted: Fri Jun 18, 2010 6:26 pm
by gerryg400
I don't have the book so I can't check, but maybe.

Edit: what I mean is that my source says 0 means bcd, so I think the book is wrong. We need others to comment.

Re: Realtime clock issue

Posted: Sat Jun 19, 2010 12:07 am
by Brendan
Hi,
gerryg400 wrote:Edit: what I mean is that my source says 0 means bcd, so I think the book is wrong. We need others to comment.
My information says 0 = BCD, 1 = binary; and I know this is right because I've used it to read the RTC correctly (on a variety of computers) in the past.

The information I use is from a text file called "pctim003.txt". It's old, but very complete and covers just about everything you could want to know about timers and timing for older hardware; and is the best reference for RTC and PIT that I've ever seen. I did a quick search and found it online: here!. :)


Cheers,

Brendan

Re: Realtime clock issue

Posted: Sat Jun 19, 2010 5:37 am
by bewing
The wiki CMOS article says very clearly:

Status Register B, Bit 1 (value = 2): Enables 24 hour format if set
Status Register B, Bit 2 (value = 4): Enables Binary mode if set (which means BCD mode is 0)

-- so yes, your book is totally wrong.

And I hope that when you access Status register B, that that's a decimal 11 you are using for the IO port.

Re: Realtime clock issue

Posted: Sat Jun 19, 2010 9:28 am
by TyrelHaveman
Thanks to all of you! I've written the correction in my copy of that book in case I ever run across that again. :-)

Also, thanks, bewing, for pointing that out on the CMOS article. I see now that the "Time And Date" article I was reading does indeed point to the CMOS article, I just missed it somehow.