#include <avr/io.h>
#include <avr/interrupt.h>
#include "pin_macros.h"
unsigned char led=0;
ISR(INT0_vect) {
if (led){
b0_high;
led = 0;
} else {
b0_low;
led = 1;
}
}
int main (void)
{
b1_input; //switch
b0_output; //led output
MCUCR = 1<<isc01; //set INT0 as falling edge trigger
GIMSK = 1<<INT0; //enable INTO in global interrupt mask
sei(); //enable interrupt
while(1) {
;; //interrupt do the rest
}
}
B1 is connected to a switch, and B0 is connected to a LED.
When B1 is pressed, it would toggle the LED On or Off.
Download the whole project : http://labs.bitartist.org/test_int0.tar.gz
Reference:
http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html