Solved

IRQ7 printer interrupt

Posted on 1997-03-01
1
463 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 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c language help - file paths 7 146
List out all word 7 289
Socket Programming (Unix) 8 127
Unable to start eclipse ? 17 141
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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

776 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