//================================================================================ //
// Interruptions Arduino MEGA ATMEGA 2560
//================================================================================ //
#define F_CPU 16000000 UL
#include <avr/io.h>
#include <util/delay.h>
//============== Macro definitions for working with bits ======================== //
#define set_bit(y, bit)(y |= (1 << bit)) // sets the x bit of the variable Y to 1
#define clear_bit(y, bit)(y &= ~(1 << bit)) // sets bit x of variable Y to 0
#define toggle_bit(y, bit)(y ^= (1 << bit)) // changes the logical state of bit x of variable Y
#define test_bit(y, bit)(y & (1 << bit)) // returns 0 or 1 depending on the bit reading
//================================================================================ //
// ISR(INT0_vect);
int main(void){
Serial.begin(9600);
clear_bit(DDRD, PD0); // set pin button as input
set_bit(PORTD, PD0); // define button pin as HIGT for enable pull up resistor
set_bit(DDRH, PH3); // set PH3 as input for led
clear_bit(PORTH, PH3); // turn of LED for default
sei(); // habilita interrupções globais, ativando o bit I do SREG
// set_bit(EICRA, ISC01); // enable request interruption for the falling edge
// set_bit(EICRA, ISC11);
set_bit(EIMSK, INT0); // enable int0 for external interruptions
while(1){
// Serial.print(test_bit(PIND, PD0));
}
Serial.end();
return 0;
}
ISR(INT0_vect) {
_delay_ms(100);
if(test_bit(PIND, PD0)){
Serial.print("@");
}else{
Serial.print("-");
}
}