I want to toggle the LED3 of the microcontroller when the button SW0 is pressed. I developed this code but it is not working and I dont know what is wrong. I search in the documentation and many foros trying to find the error but I still dont know what is wrong. I think the problem is in the confguration of the interrupt, but I am not sure about this.Can someone help me? Thank you.
int main(){
EIMSK = 1<<INT0; // Enable INT0
EIFR = (1 << INT0);
MCUCR |= 1<<ISC01 | 1<<ISC00; // Trigger INT0 on rising edge
DDRB = 0x04;//Set port B LED3 as output the other pins as input
PORTB = 0x04; //Pin3 that is output/led turn off, input pull up
DDRD &= ~(1<<PIND2); // Set PD2 as output (Used for interrupt INT0)
PORTD = 1<<PIND2; // Enable PD2 pull-up resistor
sei(); //Set global interrupt flag, to allow SW0 interrupts
while(1) {}; //Infinite loop to wait for the interrupt
return 0;
}
ISR(INT0_vect) {
PORTB ^= 1 << 3; //toggle LED3
}
PORTB ^= 1 << 3
, which is 0x8 thenDDRB = 0x04;
is wrong. \$\endgroup\$