How to use interrupts?

Hi pple,

Can some1 tell me how to use interrupts? I know the
basic concept and have used it with microcontrollers
but would like to learn it with PC's

Suppose i want to read data from the parallel port.
How can i use interrupts to do this? Just a brief pseudocode
will do...the only thing i know is that i have to enable
interupts first with enable() or _enable depending on the compiler(and then disableit in the end) and that I have to somehow use the respective interrupt request (which can be identified with Device Manager for Windows).

Can anyone help me out with the this?

Thx a lot
Bondfire

Comments

  • [b][red]This message was edited by stober at 2005-6-17 14:45:45[/red][/b][hr]
    google for "programming the parallel port". If you havn't done that already, it would have saved you a days wasted time.

    http://www.lvr.com/parport.htm






  • I already know how to program the parallel port. I want to learn
    about using interrupts in general; I just chose the parallel port for exemplification purposes.

    : [b][red]This message was edited by stober at 2005-6-17 14:45:45[/red][/b][hr]
    : google for "programming the parallel port". If you havn't done that already, it would have saved you a days wasted time.
    :
    : http://www.lvr.com/parport.htm
    :
    :
    :
    :
    :
    :
    :

  • : I already know how to program the parallel port. I want to learn
    : about using interrupts in general; I just chose the parallel port for exemplification purposes.
    [blue]
    Take a look at this:
    http://www.ctyme.com/rbrown.htm
    This site is a list of virtually every interrupt
    there is.

    The way to use interrupts is compiler dependent.
    With Borland, you could try the REGS union and
    int86(), or geninterrupt() to generate INTs. Of course,
    this req. a 16-bit compiler, or inline ASM.

    A an example, this code switches DOS into a mode 13h:
    [/blue][code]
    #include // Should work with TurboC 2.1

    REGS out;
    out.h.ah=0;
    out.h.al=0x13; // video mode
    int86 (0x10,&out,&out); // generate int 10h[/code][blue]
    Is this what you wanted?[/blue]
  • [b][red]This message was edited by stober at 2005-6-17 18:8:11[/red][/b][hr]
    Here is the basic idea of how to write an interrupt handler function. First use getvect() to get the pointer to the current handler, then setvect() to install your handler. If you want to keep the chain of interrupt handlers intact, in your handler function call the old handler function either at the beginning or the end of your function.

    http://www.coding-zone.co.uk/cpp/howtos/200401interrupt.shtml

    It only works with 16-bit MS-DOS compilers and will not work with MS-Windows compilers.
  • Thx for ur replies guys.

    Well i'm not really sure if thats wot i wanted...i'll have to work on your replies first.

    What i was looking for and I hope is possible is this: the main function of some program is executing as usual doing something..when an interrupt event occurs, normal program execution is suspended and control is handed to the interrupt function...when the interrupt function finishes, control is then handed back to the main program where it resumes from where it left off....this way there is an immediate detection of an input in contrast to polling for input.

    Any idea on whether the codes you gave can accomplish this?

    Thx

    : : I already know how to program the parallel port. I want to learn
    : : about using interrupts in general; I just chose the parallel port for exemplification purposes.
    : [blue]
    : Take a look at this:
    : http://www.ctyme.com/rbrown.htm
    : This site is a list of virtually every interrupt
    : there is.
    :
    : The way to use interrupts is compiler dependent.
    : With Borland, you could try the REGS union and
    : int86(), or geninterrupt() to generate INTs. Of course,
    : this req. a 16-bit compiler, or inline ASM.
    :
    : A an example, this code switches DOS into a mode 13h:
    : [/blue][code]
    : #include // Should work with TurboC 2.1
    :
    : REGS out;
    : out.h.ah=0;
    : out.h.al=0x13; // video mode
    : int86 (0x10,&out,&out); // generate int 10h[/code][blue]
    : Is this what you wanted?[/blue]
    :

  • : Thx for ur replies guys.
    :
    : Well i'm not really sure if thats wot i wanted...i'll have to work on your replies first.
    :
    : What i was looking for and I hope is possible is this: the main function of some program is executing as usual doing something..when an interrupt event occurs, normal program execution is suspended and control is handed to the interrupt function...when the interrupt function finishes, control is then handed back to the main program where it resumes from where it left off....this way there is an immediate detection of an input in contrast to polling for input.
    [blue]
    Thats done automatically by the processor--thats why they're
    called interrupts--the interrupt the normal flow of the program.

    Are you looking for an interrupt to handle input? If so,
    check out the link in my above post.

    Or, are you looking to create your own Interrupt routine?
    If so, check stobers second response.[/blue]

    : Any idea on whether the codes you gave can accomplish this?
    [blue]
    Im a litte confused at what you are asking..If the above
    doest help much, please provide more detail at what you
    are trying to accomplish.[/blue]
  • : : Thx for ur replies guys.
    : :
    : : Well i'm not really sure if thats wot i wanted...i'll have to work on your replies first.
    : :
    : : What i was looking for and I hope is possible is this: the main function of some program is executing as usual doing something..when an interrupt event occurs, normal program execution is suspended and control is handed to the interrupt function...when the interrupt function finishes, control is then handed back to the main program where it resumes from where it left off....this way there is an immediate detection of an input in contrast to polling for input.
    : [blue]
    : Thats done automatically by the processor--thats why they're
    : called interrupts--the interrupt the normal flow of the program.
    :
    : Are you looking for an interrupt to handle input? If so,
    : check out the link in my above post.
    :
    : Or, are you looking to create your own Interrupt routine?
    : If so, check stobers second response.[/blue]
    :
    : : Any idea on whether the codes you gave can accomplish this?
    : [blue]
    : Im a litte confused at what you are asking..If the above
    : doest help much, please provide more detail at what you
    : are trying to accomplish.[/blue]
    :

    I'm looking to create my own Interrupt routine...i guess i'll work
    on Stober's idea for a while and see if i can do it...Thx
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories