delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/06/08/19:42:40

Date: Fri, 09 Jun 1995 10:41:16 +1100
From: Bill Currie <BILLC AT teleng1 DOT tait DOT co DOT nz>
Subject: Re: Millisecond timer
To: Ian Macky <imacky AT us DOT oracle DOT com>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Organization: Tait Electronics Ltd.

For your millisecond timer (actually sub-millisecond):

1 read the count in timer 0, subtract the delay (count dounn), and
  store the value
2 read the count in timer 0
3 if count >= stored value goto 2

to read timer 0
write 00000110 (0x06) to port 0x43 (latch counter 0, sqare wave, 
binary)
read lsb from port 0x40
read msb from port 0x40

Timer 0 is already programmed with a count of 0 to get 18.2Hz by the
BIOS (unless its been reprogrammed).  I'm not certian if bits 0 to 4
have an effect when latching the counter, but mode 3 (square wave)is
what the bios uses.

NOTE: becareful of counter wraparound! Its not too difficult to 
handle and I'm sure you can figure it out.

readtimer:
movb $0x06,%al
outb %al,$ox43
inb $0x40,%al
movb %al,%ah
inb $0x40,%al
xchgb %al,%ah
ret

_mdelay:.globl mdelay
pushl %eax
pushl %ebx
call readtimer
subw count,%ax
movw %ax,%bx
lop:
readtimer
cmpw %bx,%ax  #<-- I'm never certain about comparisions in AT&T code
ja lop
popl %ebx
popl %eax
ret

count:
.word 0x100  # 0.215 milliseconds

BTW I use something similar to this when reading the joystick pots 
and it works very well.  If you like, I can post my joystic code (it 
will read all four pots and takes a maximum of about 5 to 10 mS, no 
mater what.

Bill

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019