Ch10 AVR Interrupt Programming
Ch10 AVR Interrupt Programming
These bits, along with the I bit, must be set high for an interrupt to be responded to. Upon activation of
the interrupt, the I bit is cleared by the AVR itself to make sure another interrupt can not interrupt the
microcontroller while it is servicing the current one. At the end of the ISR, the RETI instruction will
make I = 1 to allow another interrupt to come in.
int main ()
{
DDRB |= 0x20; // make DDRB.5 output
OCR0 = 40;
TCCR0 = 0x09; // CTC mode, internal elk, no prescaler
TIMSK = (1<<OCIE0); //enable TimerO compare match int.
sei(); // enable interrupts
DDRC = 0x00; // make PORTC input
DDRD = 0xFF; // make PORTD output
while (1) // wait here
PORTD = PINC;
}
#include "avr/io.h"
#include "avr/interrupt.h"