Solved

IRQ7 printer interrupt

Posted on 1997-03-01
1
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

630 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