Information Technology Reference
In-Depth Information
This is tested with
if (in1&0x80)==1)
When this condition is TRUE (that is, when the button is closed) then the output data lines
(D0-D7) will flash on and off with a delay of 1 second between flashes. An output of all 1s
to the data lines causes the LEDs to be off, and all 0s cause the LEDs to be on.
Program 16.4
/* Flash LEDs on and off when the push button connected to BUSY
*/
/* is closed
*/
#include <stdio.h>
#include <dos.h>
#define DATA 0x378
#define STATUS DATA+1
#define CONTROL DATA+2
int main(void)
{
int in1;
do
{
in1 = _inp(STATUS);
if (in1&0x80)==1) /* if switch closed this is TRUE */
{
_outp(DATA,0x00); /* LEDs on */
delay(1000);
_outp(DATA, 0xff); /* LEDs off */
delay(1000);
}
else
_outp(DATA,0x01); /* switch open */
} while (!kbhit());
return(0);
}
16.5 Interrupt-driven parallel port
16.5.1 Introduction
The previous section discusses how the parallel port is used to output data. This chapter dis-
cusses how an external device can interrupt the processor. It does this by hooking onto the
interrupt server routine for the interrupt that the port is attached to. Normally this interrupt
routine serves as a printer interrupt (such as lack of paper, paper jam and so on). Thus, an
external device can use the interrupt service routine to transmit data to or from the PC.
16.5.2 Interrupts
Each parallel port is hooked to an interrupt. Normally the primary parallel port is connected
to IRQ7. It is assumed in this section that this is the case. As with the serial port this interrupt
line must be enabled by setting the appropriate bit in the interrupt mask register (IMR),
Search WWH ::




Custom Search