#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
void delay(double td) {
// set up timer with prescaler = 64 and CTC mode
TCCR1B |= (1 << WGM12)|(1 << CS12)|(1 << CS10);
TCNT1 = 0; // initialize counter
OCR1A = (uint16_t) td*F_CPU/1024.0-1.0;
TIMSK1 |= (1 << OCIE1A); // enable compare interrupt
sei(); // enable global interrupt
}
int main(void) {
DDRB |= (1 << PB0); // connect led to pin PC0
delay(1.0);
while(1) {};
}
ISR (TIMER1_COMPA_vect)
{
PORTB ^= (1 << PB0); // toggle led here
}