Page 1 of 3
Timer Interrupt
Posted: Mon Mar 22, 2004 11:34 am
by ich_will
Hi I set up a function for the timer interrupt (IRQ 0) and read every time a interrupt occurs the time with:
outportb(0x70, 0x04); // get the current hour
hour = inportb(0x71);
outportb(0x70, 0x02); // get the current minute
min = inportb(0x71);
outportb(0x70, 0x00); // get the current second
sec = inportb(0x71);
I know this is a slow solution but it's only for tests.
If we have for example 18 H the kernel outs 24 H, if we have 23 H it outs 35 H why?? The same thing with the minutes and seconds (not the same numbers i think) the seconds can be for example 62s.
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 12:00 pm
by Neo
the BIOS clock counts in BCD not binary.
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 12:01 pm
by DennisCGc
Uhm, because the CMOS is BCD based.
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 12:04 pm
by DennisCGc
Neo wrote:
the BIOS clock counts in BCD not binary.
It is not the BIOS but the CMOS
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 12:10 pm
by ich_will
What does BCD mean and how can I convert it in real time? (Not set the bit for Binary Bit in CMOS Register B)
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 12:12 pm
by Neo
BCD representation is quite easy to convert to decimal. i not sure but i think this formula of mine is right.
IIRC BCD basically uses a nibble for each digit. i.e the decimal no.23 is represented as 0010_0011 binary etc. HTH
<edit>
BCD=Binary Coded Decimal.
and i think my explanation was for packed BCD. BCD uses a byte i think for each digit. (again check a number system book to be sure).
</edit>
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 12:19 pm
by DennisCGc
Neo wrote:
BCD representation is quite easy to convert to decimal. i not sure but i think this formula of mine is right.
IIRC BCD basically uses a nibble for each digit. i.e the decimal no.23 is represented as 0010_0011 binary etc. HTH
I don't have my OS source on this computer, but I think it should work. Now I don't have to get the sources from the other computer
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 1:43 pm
by Therx
if you have a printf function support HEX then output it as that.
Pete
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 2:48 pm
by ASHLEY4
This is the code i use to convert it:
Code: Select all
;----------------------------------------------------;
; bcd_to_ASCII ;converts bcd number to ASCII ;
;----------------------------------------------------;
; ;
; Input: ;
; Bcd number in al. ;
; Output: ;
; ASCII number in val. ;
; (100%) ;
;....................................................;
bcd_to_ASCII:
pusha ;start of convert
mov ah,al ;copy AL to AH
and ax,0f00fh ;mask bits
mov cl,4 ;CL=04 for shift
shr ah,cl ;shift right AH to get unpacked BCD
or ax, 3030h ;combine with 30 to get ASCII
xchg ah,al ;swap for ASCII storage convention
mov [val],ax ;store the ASCII value in VAL
popa
ret
ASHLEY4.
Re:Timer Interrupt
Posted: Mon Mar 22, 2004 5:10 pm
by Dragon88
<edit>
BCD=Binary Coded Decimal.
and i think my explanation was for packed BCD. BCD uses a byte i think for each digit. (again check a number system book to be sure).
</edit>
Depends on whether it is packed or not. Packed BCD stores 2 digits per byte, unpacked only stores 1 in the low nybble.
Re:Timer Interrupt
Posted: Tue Mar 23, 2004 2:27 am
by DennisCGc
ASHLEY4 wrote:
This is the code i use to convert it:
Code: Select all
;----------------------------------------------------;
; bcd_to_ASCII ;converts bcd number to ASCII ;
;----------------------------------------------------;
; ;
; Input: ;
; Bcd number in al. ;
; Output: ;
; ASCII number in val. ;
; (100%) ;
;....................................................;
bcd_to_ASCII:
pusha ;start of convert
mov ah,al ;copy AL to AH
and ax,0f00fh ;mask bits
mov cl,4 ;CL=04 for shift
shr ah,cl ;shift right AH to get unpacked BCD
or ax, 3030h ;combine with 30 to get ASCII
xchg ah,al ;swap for ASCII storage convention
mov [val],ax ;store the ASCII value in VAL
popa
ret
ASHLEY4.
I have another code with DAA and AAD, but I don't have it now :-[
I'll send it on this forum, when I have a floppy drive in my new computer
Re:Timer Interrupt
Posted: Tue Mar 23, 2004 6:21 am
by ich_will
DennisCGcs dec= bcd-((bcd>>4)*6); work fine.
But what shoud I do if an timer interrupt occurs? Should I increment a counter? but than i have to convert bcd every time i would get the time.
Re:Timer Interrupt
Posted: Tue Mar 23, 2004 6:29 am
by DennisCGc
ich_will wrote:
DennisCGcs dec= bcd-((bcd>>4)*6); work fine.
Btw, it was from neo
But what shoud I do if an timer interrupt occurs? Should I increment a counter? but than i have to convert bcd every time i would get the time.
No, in my OS, I call a time_init.
This reads the time from the CMOS, and the time, which has been read, is converted to decimals.
And this initializes the PIT, it will be set that every 1/100 sec a timer interrupt will be called and when the interrupt occured 100 times, a second will be added, and so the clock is updated.
Re:Timer Interrupt
Posted: Tue Mar 23, 2004 6:57 am
by Pype.Clicker
iirc, the time in the CMOS is automagically incremented by some external circuit (the realtime clock)
Re:Timer Interrupt
Posted: Tue Mar 23, 2004 7:19 am
by DennisCGc
Pype.Clicker wrote:
iirc, the time in the CMOS is automagically incremented by some external circuit (the realtime clock)
But then he have to convert it each time.
Well, it's up to him to choose a method, although my method may be faster, it may be more difficult than Pype's method.