Code:#include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> volatile uint16_t ImpulsZaehler1; uint16_t a = 50; //mitte 1,6ms // Timer interrupt 4000Hz (4Mhz Quarz) void Timer0B_ON (void) { // Mode #2 (CTC) TCCR0B = (1 << CS00) | (1 << WGM01); OCR0B = 200; TIMSK |= (1 << OCIE0B); } ISR (SIG_OUTPUT_COMPARE0B) { if (++ImpulsZaehler1 >= 100) { ImpulsZaehler1 = 0; } } int main(void) { Timer0B_ON(); DDRD = (1 << PD6); sei(); while(1) { uint16_t iz; // atomic cli(); iz = ImpulsZaehler1; sei(); if (iz < a) { PORTD &= ~(1 << PD6); } else { PORTD |= (1 << PD6); } } // while (1) } // main
Lesezeichen