Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IRQ7 printer interrupt

Posted on 1997-03-01
1
Medium Priority
?
488 Views
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 :)

David

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++);
}
0
Comment
Question by:sky123
1 Comment
 

Accepted Solution

by:
klos earned 100 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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

824 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