Irgendwie wills mit Interupt nicht:
Code:#include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> uint8_t timer = 0; uint8_t msecond = 0; SIGNAL (SIG_OVERFLOW0) { if (timer++ % 16 == 0) msecond++; }; int wait(time) { TCNT0 = 0; msecond = 0; while(1) { if (msecond >= time) return 0; } } int main() { TIMSK |= (1<<TOIE1); TCCR0 |= (1<<CS00)|(1<<CS02); DDRC = 0xFF; int time = 1000; PORTC = 0xFF; sei(); while(1) { PORTC |= (1<<2); wait(time); PORTC &= ~(1<<2); wait(time); } return 0; }
Lesezeichen