#include <avr/io.h>
#include <avr/interrupt.h>
int freq = 0;
ISR(TIMER0_COMPA_vect){ // Interrupt Service Routine
static unsigned char teiler=0;
teiler++;
if(teiler>=freq){ // Teilfaktor in ISR
teiler=0;
if (freq>0) PORTB ^= 1; // Ausgang PB0 invertieren (PINB = 1)
}
}
void setup(){
PORTB = 0xff;
DDRB = 0xff;
TCCR0B = 2;
TIMSK |= 1<<OCIE0A; // Timer/Counter0 Output Compare Match A Interrupt Enable
sei(); // globale Interruptfreigabe
}
void loop()
{
for (int n=1; n < 20; n++)
{
delay(2000);
freq=n;
}
cli();
delay(50000);
freq=0;
sei();
}