Information Technology Reference
In-Depth Information
}
void disable_interrupts(void)
{
int ch;
disable();
outportb(IMR, ch & ~IRQ7);
enable();
}
void reset_vectors(void)
{
setvect(0x0f,oldvect);
}
16.5.4 Program explanation
The initial part of the program enables the interrupt on the parallel port by setting bit 4 of the
control register to 1:
void setup_parallel(void)
{
outportb(CONTROL, inportb(CONTROL) | 0x10); /* Set Bit 4 on control port*/
}
After the serial port has been initialized the interrupt service routine for the
IRQ7
line is set to
point to a new 'user-defined' service routine. The primary parallel port
LPT1:
normally sets
the
IRQ7
line active when the
ACK
line goes from a high to a low. The interrupt associated
with
IRQ7
is 0Fh (15). The
getvect()
function gets the ISR address for this interrupt, which
is then stored in the variable
oldvect
so that at the end of the program it can be restored.
Finally, in the
set_vectors()
function, the interrupt assigns a new 'user-defined' ISR (in
this case it is the function
pl_interrupt()
):
void set_vectors(void)
{
int int_mask;
disable(); /* disable all ints */
oldvect=getvect(0x0f); /* save any old vector */
setvect (0x0f,pl_interrupt); /* set up for new int serv */
}
At the end of the program the ISR is restored with the following code:
void reset_vectors(void)
{
setvect(0x0f,oldvect);
}
To enable the
IRQ7
line on the PIC, bit 5 of the IMR (interrupt mask register) is to be set to a
0 (zero). The statement
ch = inportb(IMR) & 0x7F;
achieves this as it bitwise ANDs all the bits, except for bit 7, with a 1. This is because any bit