• C

IRQ7 printer interrupt

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.

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)();

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

disable();

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);

enable();

while(i<10);

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

}

void interrupt feedbk()
{
      printf("%d\n", i++);
}
sky123Asked:
Who is Participating?
 
jos010697Connect With a Mentor Commented:
Have a look at your setvect() function; it sets the feedbk
handler to interrupt vector LPT_IRQ which is defined as
interrupt vector 0x0f (15 decimal). Shouldn't that be 0x07?

kind regarrds,

Jos aka jos@and.nl
0
 
rmichelsCommented:
A few comments:

Calling printf from the interrupt routine may be causing problems.  It could be taking too much time.  How many interrupts per second are you running?

Also, the variable i should have the keyword volatile

int volatile i;

This keeps the compiler from optimizing i into a register in your while (i < 10) loop.

What exactly does not work?

0
 
phillipsCommented:
What is not working in your program? Is the function feedb() executed or not? What voltage and current are you using?

regards

phillips
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.