#include <avr/io.h>
#include <util/delay.h>
//Interrupt Service Routine for INT0
volatile int state=LOW;
byte bit5;
ISR(INT0_vect){
state ^= bit5;//exclusive OR
}
int main() {
init();
DDRD = 0x0; //PORTD bit 2 as input
PORTD = 0x04;//configure to use pull up resistor
/* set PORTB BIT IN PIN 13 as output */
DDRB |= 0x20;// DDRB5 pin 13 as output
EIMSK |= 0b00000001;//Enable ext interrupt INT0
EICRA |= 0b00000010;//Trig. INT0 on falling edge
bit5 = 1 << 5;//set bit 5 to 1 shifting 5 times
sei();//Enable interrupts
while (true) {
PORTB = state;//change state
}
return 0;
}
// #include <avr/io.h>
// int main()
// {
// init();
// DDRD = 0x00;//configure DDRD1, pin 2 as input
// DDRB = 0x20;
// PORTD = 0x04;//configure to use pull up resistor
// //PORTB = 0x20;
// Serial.begin(9600);//set serial to 9600 bps
// do{
// byte input=PIND & 0x04; //read pin 2 in port D
// input = input >> 2;
// Serial.println(input);
// if (input == 0){
// PORTB = 0x20;
// }
// else {
// PORTB = 0x00;
// }
// }while(true);
// }