volatile unsigned char intr_flag = 0; // To track the occurence of ext interrupt
void ext_intr_init(){
volatile unsigned char *INT_EICRA = 0x69, *INT_EICRB = 0x6A, *INT_EIMSK= 0x3D, *INT_SREG = 0x5F;
*INT_EICRA = 0x03; //INT0 as rising edge
*INT_EICRB = 0x00; //not using any other ext int
*INT_EIMSK = 0x01; //External Interrupt Request INT0;
*INT_SREG = 0x80; //ENabling I flag
}
void setup() {
// put your setup code here, to run once:
ext_intr_init();
volatile unsigned char* ddr_f = 0x30;
*ddr_f = 0x01; //0th bit as output
}
ISR(INT0_vect){
intr_flag = 1;
}
void loop() {
volatile unsigned char* out_f = 0x31;
if(intr_flag){
//handling debouncing logic by giving some delay
delay(300);
*out_f ^= 1; // Toggle LED on pin PF0
intr_flag = 0; // resetting the interrupt flag
}
}