#define DDRB (*(volatile unsigned char *)(0x37)) #define PORTB (*(volatile unsigned char *)(0x38)) #define SREG (*(volatile unsigned char *)(0x5f)) #define TIMSK (*(volatile unsigned char *)(0x59)) #define TIFR (*(volatile unsigned char *)(0x58)) #define TCCR0 (*(volatile unsigned char *)(0x53)) #define TCNT0 (*(volatile unsigned char *)(0x52)) #define GIMSK (*(volatile unsigned char *)(0x5b)) #define MCUCR (*(volatile unsigned char *)(0x55)) #define ENTRADA 0xff #define SAIDA 0x00 #define ACENDE 0x00 #define APAGA 0xff #define IRQ0 __vector_1 #define IRQ7 __vector_7 #define SIGNAL __attribute__ ((signal)) int counter; //contador de overflows int main(void) { counter = 0; SREG = 0x80; //habilita as interrupções GIMSK = 0x40; MCUCR = 0x02; //habilita interrupção ao precionar o botao DDRB = ENTRADA; PORTB = APAGA; while(1) {} return 0; } void IRQ0(void) SIGNAL; void IRQ0(void) { static is_down = 0; //indica se o botão foi precionado ou liberado is_down = ~is_down; if (is_down) { TIMSK = 0x02; //habilita interrupção de tempo MCUCR = 0x03; //habilita interrupção ao liberar o botao TCCR0 = 0x05; //overflow para 256 } else { counter = 0; //reseta o contador TCCR0 = 0x00; TIMSK = 0x00; //desabilita interrupção de tempo MCUCR = 0x02; //habilita interrupção ao precionar o botaoi TCNT0 = 0x00; PORTB = APAGA; } } void IRQ7(void) SIGNAL; void IRQ7(void) { counter++; if (counter == 61) { counter = 0; PORTB = ACENDE; } }