Untitled

 avatar
unknown
plain_text
2 years ago
919 B
5
Indexable
#include <avr/io.h>
#include <avr/interrupt.h>

volatile unsigned int anzahlOverflows;
volatile unsigned int anzahlCompareMatches;

ISR(TIMER1_OVF_vect)
{
    anzahlOverflows++;
}

ISR(TIMER1_COMPA_vect)
{
    anzahlCompareMatches++;
    OCR1A += 200;
}

int main(void)
{
    unsigned int anzahlMainLoop = 0;
    anzahlOverflows = 0;
    anzahlCompareMatches = 0;
    
    DDRB = 0xFF;
    
    // Timer/Counter1 initialisieren
    TCCR1B |= (1 << CS11) | (1 << CS10);  // Prescaler 64 (Frequenzteiler)
    TIMSK |= (1 << TOIE1) | (1 << OCIE1A);  // Timer/Counter1 Overflow Interrupt und Output Compare Interrupt aktivieren
    
    // Compare Match Register konfigurieren
    OCR1A = 200;  // Interrupt nach 200 Zählschritten auslösen
    
    sei();  // Globale Interrupts aktivieren
    
    while (1)
    {
        PORTB = anzahlMainLoop;
        anzahlMainLoop++;
    }
}
Editor is loading...