Timer Interrupt
Timer Interrupt
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.
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
It is not the BIOS but the CMOSNeo wrote: the BIOS clock counts in BCD not binary.
Re:Timer Interrupt
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
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>
Code: Select all
dec= bcd-((bcd>>4)*6);
<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>
Only Human
Re:Timer Interrupt
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 computerNeo 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. HTHCode: Select all
dec= bcd-((bcd>>4)*6);
Re:Timer Interrupt
This is the code i use to convert it:
ASHLEY4.
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
Re:Timer Interrupt
Depends on whether it is packed or not. Packed BCD stores 2 digits per byte, unpacked only stores 1 in the low nybble.<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
I have another code with DAA and AAD, but I don't have it now :-[ASHLEY4 wrote: This is the code i use to convert it:ASHLEY4.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
I'll send it on this forum, when I have a floppy drive in my new computer
Re:Timer Interrupt
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.
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
Btw, it was from neoich_will wrote: DennisCGcs dec= bcd-((bcd>>4)*6); work fine.
No, in my OS, I call a time_init.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.
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.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Timer Interrupt
iirc, the time in the CMOS is automagically incremented by some external circuit (the realtime clock)
Re:Timer Interrupt
But then he have to convert it each time.Pype.Clicker wrote: iirc, the time in the CMOS is automagically incremented by some external circuit (the realtime clock)
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.