Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 1000000UL // 1MHz
volatile uint16_t timerVal = 0;
void InitTimer() {
TCCR1B = (1<<WGM12) | (1<<CS12) | (1<<CS10); // CTC Mode, CLK/1024
TIMSK1 = (1<<OCIE1A); // Output Compare A Match Interrupt Enable
OCR1A = 10000; // Top value
}
int main(void) {
timerVal = 0;
InitTimer();
sei();
while(1) {
if(timerVal == 1) {
DDRA = 0x06;
timerVal = 0;
}
}
return 0;
}
ISR(TIMER1_COMPA_vect) {
timerVal++;
}
Mal schnell programmiert, kA obs stimmt.
mfg
Lesezeichen