// Arduino uno default clock freqency 16Mhz
#include <avr/io.h>
#include <avr/interrupt.h>
unsigned long n_overflows = 0;
// Timer 2 Overflow Interrupt Service Routine
ISR(TIMER2_OVF_vect) {
// Task: toggle pin 12 at overflow and led (pin 13) at 1 sec.
n_overflows++;
PORTB ^= _BV(PORTB4);
if (n_overflows >= 62500){
n_overflows = 0;
PORTB ^= _BV(PORTB5);
}
}
int main() {
// Set pinmode
DDRB= _BV(DDB4) | _BV(DDB5);
// setting clock source
TCCR2B = _BV(CS21);
// enabling timer2 overflow interrupt
TIMSK2 = _BV(TOIE2);
// enabling global interrupts
sei();
while(1); // empty loop
}