#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
char valor;
char estado = 0;
char anterior = 0;
int main(void) {
DDRB |= (1 << DDB5); // pinMode 13 output
DDRD &= ~(1 << DDD2); // pinMode 2 input
PCICR |= (1 << PCIE2); // Barramentpo
PCMSK2 |= (1 << PCINT18); // Seleção registrador/pino
SREG |= (1 << SREG_I); // Habilitar interrupção
while(1);
}
ISR(PCINT2_vect) {
valor = (PIND & (1 << PIND2)) == (1 << PIND2);
if (valor == 1 && anterior == 0) {
if (estado == 1)
estado = 0;
else
estado = 1;
}
if (estado == 1)
PORTB |= (1 << PORTB5);
else
PORTB &= ~(1 << PORTB5);
anterior = valor;
_delay_ms(50);
}