Information Technology Reference
In-Depth Information
which is ANDed with a 0 results in a 0. The bit mask 0x7F has been defined with the macro
IRQ7:
void enable_interrupts(void)
{
int ch;
disable();
ch=inportb(IMR);
outportb(IMR, ch & IRQ7);
enable();
}
At the end of the program the interrupt on the parallel port is disabled by setting bit 7 of the
IMR to a 1; this disables IRQ7 interrupts:
void disable_interrupts(void)
{
int ch;
disable();
outportb(IMR, ch & ~IRQ7);
enable();
}
The ISR for the IRQ7 function is set to pl_interrupt() . It outputs the value of outval ,
which is incremented each time the interrupt is called (note that there is a roll-over statement
which resets the value of outval back to zero when its value is 255). At the end of the ISR
the end of interrupt flag is set in the interrupt control register with the statement out-
portb(ICR, EOI);, as follows :
void interrupt far pl_interrupt(void)
{
disable();
outportb(DATA,outval);
if (outval!=255) outval++; else outval=0;
int_flag=TRUE;
outportb(ICR,EOI);
enable();
}
The main() function calls the initialisation and the de-initialisation functions. It also contains
a loop which continues until any key is pressed. Within this loop, the keyboard is tested to
determine if a key has been pressed. The interrupt service routine sets int_flag . If the main
routine detects that it is set it displays the message 'New value sent' and resets the flag:
int main(void)
{
set_vectors();
outportb(CONTROL, inportb(CONTROL) | 0x10);
/* set bit 4 on control port to logic one */
do
{
if (int_flag)
{
printf("New value sent\n");
int_flag=FALSE;
}
} while (!kbhit());
Search WWH ::




Custom Search