/* Interrupt alle 50ms, 4 MHz Systemtakt, 8Bit-Timer 0, Overflow-Interrupt, Wechsel an PB0
Taktzahl:   Phi*Sollzeit = 4Mhz*50ms = 200.000
Vorteiler:  Taktzahl/Werteanzahl = 200.000/256 = 781 aus {1,8,64,256,1024} => 1024
Vorsteller: Werteanzahl - Taktzahl/Vorteiler = 256 - 200.000/1024 => 61
Probe:      (Werteanzahl-Vorsteller)*Vorteiler/Phi =(256-61)*1024/4MHz = 49,9ms
*/
#include <avr/io.h>
#include <avr/interrupt.h>

int main(){          // Hauptprogramm
  PORTB = 0xff;
  DDRB = 0xff;
  TCCR0B = 5;        // Vorteiler 1: /1; 2: /8; 3: /64; 4: /256; 5: /1024
  TIMSK |= 1<<TOIE0; // TimerOverflowInterruptEnable0
  sei();             // globale Interruptfreigabe
  while(1);          // Endlosschleife
  return 0;
}

ISR(TIMER0_OVF_vect){ // Interrupt Service Routine
  TCNT0 = 61;         // wieder vorstellen
  PORTB ^= 1;           // Ausgang PB0 invertieren (PINB = 1)
}