Solved

IRQ7 printer interrupt

Posted on 1997-02-28
3
583 Views
Last Modified: 2006-11-17
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++);
}
0
Comment
Question by:sky123
3 Comments
 
LVL 3

Expert Comment

by:rmichels
Comment Utility
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
 
LVL 4

Accepted Solution

by:
jos010697 earned 100 total points
Comment Utility
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
 

Expert Comment

by:phillips
Comment Utility
What is not working in your program? Is the function feedb() executed or not? What voltage and current are you using?

regards

phillips
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

728 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

15 Experts available now in Live!

Get 1:1 Help Now