#include <avr/io.h>
#include <avr/interrupt.h>
//Oscilador externo.
//tambien tengo que hacer el de intensidad del led.
void io_init() {
DDRB = (1<<PB7);
PORTB = (1<<PB7);
}
//esta inicializacion es para utilizar el oscilador externo, con este oscilador se puede hacer 1-8 segundos sin problemas.
void timer_init () {
//1. Disable the Timer/Counter2 interrupts by clearing OCIE2x and TOIE2.
TIMSK2 = 0;
//2. Select clock source by setting AS2 as appropriate.
ASSR = (1<<AS2);
//3. Write new values to TCNT2, OCR2x, and TCCR2x.
TCNT2 = 0;
TCCR2A = (1<<WGM21);
TCCR2B = (7<<CS20);
OCR2A = 32 - 1;
//4. To switch to asynchronous operation: Wait for TCN2UB, OCR2xUB, and TCR2xUB.
while (ASSR&0x1F) ;
//5. Clear the Timer/Counter2 Interrupt Flags.
TIFR2 = 7;
//6. Enable interrupts, if needed.
TIMSK2 = (1<<OCIE2A);
sei();
}
ISR (TIMER2_COMPA_vect) {
PORTB = ((~PINB) & (1<<PB7));
}
void main () {
io_init();
timer_init();
while (1) ;
}