1.2K
An AVR external interrupt example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include<avr/io.h> #include<avr/interrupt.h> // interrupt header file #include<util/delay.h> /** External Interrupt Program */ // Interrupt service Routine for INTO ISR(INT0_vect) { //_delay_ms(50); // Software Debounce delay PORTB ^= 1<<PINB0; _delay_ms(50); } int main ( void ) { DDRB |= 1<< PINB0 | 1<< PINB2; // setn PINB0 and PINB1 as output PORTB &= ~(1<< PINB0 | 1<< PINB2); DDRD &= ~(1<<PIND2); // PIND2 set as input.. This is the INT0 pin to which button is connected PORTD |= 1 << PIND2; // push PIND2 to high - internal pull up resisitor- short when button is pressed GIMSK = 1<<INT0; // enable interrupt on INTO pinD2 MCUCR = 1<<ISC01 | 1 << ISC00; // Trigger INTO on rising edge // enable global interrupts sei(); while (1) { PORTB ^= 1 << PINB2; _delay_ms(50); } } |