IRQ7 printer interrupt

Posted on 1997-03-01
Last Modified: 2012-08-13
I'm currently doing a project which needs to interface the PC's parallel port to a motor. The motor's optocoupler is connected to pin 10 (ACK pin) of the parallel port. This optocoupler outputs square waves, which is a measure of the motor's speed.

When there's a voltage transition, IRQ7 will be executed. Now, the problem is how to write a handler for IRQ7. When IRQ7 is asserted, how do I tell it to execute my own interrupt handler for IRQ7.

Please help.

Thanks :)


My rough program is as shown below, but it can't work!

/* Test IRQ (ACK pin 10) of the parallel port LPT1 */
/* The optocoupler's output is connected to pin 10 */
/* A high to low transition will assert IRQ7, print value of i, and increase i */

#include <conio.h>
#include <dos.h>

#define LPT_IRQ            0x0f      /* LPT1 interrupt number */
#define contr_reg      0x37a

void interrupt feedbk(void);

int i = 0;

void main()
unsigned char a;
void interrupt (*oldfunc)();

oldfunc = getvect(LPT_IRQ);  /* Save old interrupt vector */


setvect(LPT_IRQ, feedbk);  /* Install new interrupt */

/* Enable LPT1 IRQ7 */
/* Set bit 4 (IRQ) to high */
a = inportb(contr_reg);
a |= 0x10;
outportb(contr_reg, a);



setvect(LPT_IRQ, oldfunc); /* Restore original interrupt */


void interrupt feedbk()
      printf("%d\n", i++);
Question by:sky123
1 Comment

Accepted Solution

klos earned 50 total points
ID: 1249679
The primary problem I see with your code is that you are not enabling the interrupt through the PIC (Programmable Interrupt Controller).  You need to clear bit 7 of the interrupt mask register to enable the IRQ 7 to interrupt the processor.  Do this by the following:

        outportb(0x21, inportb(0x21)&0x7f);

I would recommend doing this after the setvect() call.  When you're done with the interrupt, be sure to reset the bit as follows:

        outportb(0x21, inportb(0x21)|0x80);

You also need to do the EOI (end of interrupt) inside your interrupt routine like this:

        outportb(0x20, 0x67);   /* I prefer specific EOI */

Lastly, I must let you know that you shouldn't do a "printf()" or any other functions in your interrupt handler that may use the operating system.  In general, the interrupt handler should do as little work as possible, and let the foregroung (your main program) do any real processing.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now