Ja sicher, hab ich wohl was Vergessen...
Jetzt aber.Code:#include <avr/io.h> // I/O Port definitions #include <avr/interrupt.h> // Interrupt macros #define F_CPU 16000000 #define timer 238 //0.01ms volatile int ms1 = 0; volatile int ms2 = 0; volatile int ms3 = 0; void timer_init(void){ TCNT0 = timer; TIMSK |= (1<<TOIE0); //Interupts aktivieren sei(); TCCR0 |= (1<<CS01); //Prescaler 8 } ISR(TIMER0_OVF_vect){ TCNT0 = timer; //Endausschlag LINKS if(ms1>=150){ PORTB &= ~(1<<PORTB1); if(ms1<=3800) ms1++; else{ ms1 = 0; } } else PORTB |= (1<<PORTB1); ms1++; /* if(ms2>=150) PORTB &= ~(1<<PORTB2); else PORTB |= (1<<PORTB2); if(ms2<=2000) ms2++; else ms2 = 0; if(ms3>=150) PORTB &= ~(1<<PORTB3); else PORTB |= (1<<PORTB3); if(ms3<=2000) ms3++; else ms3 = 0; */ } int main(void){ DDRB |= (1<<PORTB1) | (1<<PORTB2) | (1<<PORTB3); //B... AUSGANG PORTB &= ~((1<<PORTB1) | (1<<PORTB2) | (1<<PORTB3)); //B.. Low //GLOBALE INTERUPTS AKTIVIERT timer_init(); while(1){ } return 0; }
Die 3800 kannst Du noch etwas optimieren.
Gruß
PS Mit der OCUnit geht es wirklich besser.







Zitieren
Lesezeichen