[comp.lang.pascal] Interrupt type stuff

chaudhury@physics.ucla.edu (CHAUDHURY, SHILADITYA) (12/06/90)

I guess I am not quite sure what programming question to ask, but let
me explain what I need to do and perhaps someone can give me pointers:

I have a programmable parallel port whose starting address I know. I now
need to use this I/O port to read a button i.e., when the button is pressed
(sort of like Jeopardy buzzers) my program goes and takes data and locks out
the button till it is ready for more data.  I would naturally like to do
this in TP 4+.
Has anyone had any experience doing this? Any ideas on where to look?

Thanks in advance,

--Raj Chaudhury
UCLA Solid State

phys169@csc.canterbury.ac.nz (12/07/90)

In article <25202@adm.brl.mil>, chaudhury@physics.ucla.edu (CHAUDHURY, SHILADITYA) writes:
> I have a programmable parallel port whose starting address I know. I now
> need to use this I/O port to read a button i.e., when the button is pressed
> (sort of like Jeopardy buzzers) my program goes and takes data and locks out
> the button till it is ready for more data.  I would naturally like to do
> this in TP 4+.

Parallel printer ports normally have 3 registers:

3Bc/378/278 Printer data (output, readbale, but don't trust it to be
bi-directional). (Bit 0 comes out on pin 2..bit 7 on pin 9)

3BD/379/279 Printer status register (input)
pin 11 (BUSY) -> bit 7
pin 10  (ACK)  -> bit 6
pin 12 (PAPER) -> bit 5
pin 13 (ONLINE)-> bit 4
pin 15 (ERROR) -> bit 3

3BE/37A/27A Printer control register (output)
Bit 4 -> allow IRQ generation (interrupt-driven printer IO doesn't work well)
Bit 3 -> pin 17 (might allow printer data port to go into input mode, probably
                 won't, and trying it might cook chips).
Bit 2 -> pin 16 (initialise printer)
Bit 1 -> pin 14 (auto linefeed)
Bit 0 -> latch data output

Of course, you don't need to use the port to connect to a printer. Use pull-up
resistors (4.7kohm) to a +5v supply, and put switches from input pins to earth.
Don't feed inputs into output pins. Programming would be something like:

var LptPort : array[1..4] of word absolute $40:8;
    BaseAddr: word;
    InputBits : byte;

begin
BaseAddr:=LptPort[1];
repeat InputBits:=port[BaseAddr+1] xor $FF; {change this depending on switch type}
       if boolean(InputBits and $F8)
          then begin
               {acknowledge which switch is on by testing bits 3-7}
               repeat InputBits:=port[BaseAddr+1] xor $FF;
                      until (InputBits and $F8)=0;
       until Whatever;
end;

Hope this helps,
Mark Aitchison.