Interrupt Service Routine

Explanation

Example code for an Interrupt Service Routine (ISR).

  • ISR is a macro defined in the avr-gcc libraries.
  • TIMER0_OVF_vect is the interrupt vector, in this case overflow interrupt.
  • cli() and sei() are used here to avoid data share problems.
ISR(TIMER0_OVF_vect){
    cli();                    // Disable interrupts to avoid share data problems
    count--;
    if (ticks == 11){            // Check if a second (or around) has passed
        ticks = 0;
        if (count == 0x00){
            RESETLOWNIB;
            count = 0x0f;
        } 
        else{
            PORTB = (PORTB & 0xf0) | (count & 0x0f);
        }
        tone++;
        tone = tone % 32;        // Tone will go from 0 to 32 to select next sound
    }
    else{
        ticks++;
    }
    sei();
}
page_revision: 0, last_edited: 1209612874|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License