1. mpuvdd

    Thread Starter Active Member

    Feb 11, 2007
    Hello everyone,
    I'm currently learning basic C programming and came across a section on interrupts in my book. It really doesn't explain them in depth, but I understand that they're somehow useful in timing, etc, and that they are like a subroutine. Well could someone please explain them more in depth; how they work, how they're used, etc; or send me a link with useful and easy to understand info.
    Thanks so much,
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    An interrupt is a signal that causes a processor to halt whatever operation is in progress. This is a function designed into the processor, and may be enabled or disabled by the program. Interrupts are used to handle outside events that are too time critical to wait for a polling routine to test for the event's presence.

    Typically, an interrupt causes the processor to jump to a handling routine. The routine should immediately lockout further interrupts. Then it saves the processor state on the stack. Then it handles the interrupt, executing whatever code necessary to input/output data, or change the state of the control register for an interface card. After the event handler, it machine state is restored, interrupts are enabled, and the processor jumps back to the next instruction that would have been executed before the interrupt.

    Interrupt routines are written in assembler. Processors generally have specific instructions that PUSH registers onto the satck, and then POP them off to restore the machine state.
  3. lesin akbar

    Active Member

    Dec 16, 2007
    hi friend ,
    so you know what a subroutine is,good. In a microcontroller we use basically 2 methods to execute a subroutine(function).they are Polling and Interrupts.
    for ex: suppose ur mom asked you to switch of the motor when the tank is filled, here this is your task( switching off the motor ). Now either u can sit in front of the tank and wait till the tank is filled or u can choose some one else to inform you when the tank is filled, so that you can do other works and need not ur precious time.
    now if you choose the first method then that is "Polling" and you cannot do any other job, and thus it wastes ur time. Now the second method is called "Interrupt" here some one will inform you when u are in need.
    Hope this will help u for a start.
  4. hgmjr


    Jan 28, 2005
    Beenthere and lesin_akbar have both done a good job of summarizing the concept of interrupts.

    I found this tutorial on interrupts that describes the concept in more detail than can be explained in the context of a forum such as this.

    This tutorial is specific to one particular microcontroller but the beauty of interrupts is that implementation may vary slightly from micro to micro but the basic concept is the same.

    If you have a specific microcontroller in mind then you can go to the manufacturer's datasheet for even greater details on the implementation.