/* Interrupt alle 100ms, 4 MHz Systemtakt, 8Bit-Timer 0, Overflow-Interrupt, Wechsel an PB0
Taktzahl:      Phi*Sollzeit = 4Mhz*100ms = 400.000
Vorteiler:     Taktzahl/Werteanzahl = 400.000/256 = 1562! aus {1,8,64,256,1024} => 1024
ISRTeilfaktor: Taktzahl/Werteanzahl/Vorteiler = 400.000/256/1024 = 1,5 Aufrunden: 2
Vorsteller:    Werteanzahl - Taktzahl/Vorteiler/ISRTeilfaktor = 256 - 400.000/1024/2 = 60,7 => 61
Probe:         (Werteanzahl-Vorsteller)*Vorteiler/Phi*ISRTeilfaktor =(256-61)*1024/4MHz*2 = 99,8 ms
*/
#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
  static unsigned char teiler=0;
  TCNT0 = 61;         // wieder vorstellen
  teiler++;
  if(teiler>=2){      // Teilfaktor in ISR
    teiler=0;
    PORTB ^= 1;           // Ausgang PB0 invertieren (PINB = 1)
  }
}