#define IRQ0 __vector_1 #define TIMER __vector_7 #define SIGNAL __attribute__ ((signal)) #define PORTB (*(volatile unsigned char *)(0x38)) #define DDRB (*(volatile unsigned char *)(0x37)) #define DDRD (*(volatile unsigned char *)(0x31)) #define INPUTD (*(volatile unsigned char *)(0x30)) #define GIMSK (*(volatile unsigned char *)(0x5b)) #define SREG (*(volatile unsigned char *)(0x5f)) #define TCCR0 (*(volatile unsigned char *)(0x53)) #define TIMSK (*(volatile unsigned char *)(0x59)) #define MCUCR (*(volatile unsigned char *)(0x55)) int ir_sense = 0; int counter = 0; void TIMER(void) SIGNAL; void TIMER(void) { // Quando counter for igual a 57, terĂ¡ passado 4 segundos desde que a IRQ0 foi ativada counter++; if (counter == 57) { PORTB = 0x00; TCCR0 = TCCR0 & 0xf8; counter = 0; } } void IRQ0(void) SIGNAL; void IRQ0(void) { if (ir_sense == 0) { TCCR0 = TCCR0 | 0x05; MCUCR = MCUCR | 0x03; ir_sense = 1; } else { TCCR0 = TCCR0 & 0xf8; MCUCR = MCUCR & 0xfe; PORTB = 0xff; ir_sense = 0; counter = 0; } } int main(void) { SREG = SREG | 0x80; TIMSK = TIMSK | 0x02; GIMSK = GIMSK | 0x40; TCCR0 = TCCR0 & 0xf8; MCUCR = MCUCR | 0x03; MCUCR = MCUCR & 0xfe; DDRB = 0xff; DDRD = 0x00; PORTB = 0xff; while(1) { } return 0; }