Hallo
sei() und cli() sind in interrupt.h. Ich habe dir mal mein Programm auf's nötigste geputzt, ich hoffe, es funzt so:
Die Funktion delay() habe ich inzwischen so gelöst:Code:#include <avr/io.h> // I/O Port definitions #include <avr/interrupt.h> // Interrupt macros uint8_t x, y, z; void delay(uint16_t d) { uint16_t d1, dummy; for (d1=d; d1>0; d1--) dummy^=d1; } void init(void) { cli(); DDRA |= 16; DDRC |= 3; TCCR0 = (0 << WGM00) | (1 << WGM01); // CTC-Mode TCCR0 |= (0 << COM00) | (0 << COM01); // ohne OCR-Pin TCCR0 |= (0 << CS02) | (1 << CS01) | (0 << CS00); // prescaler /8 TIMSK = (1 << OCIE0); // Interrupt ein OCR0 = 9; // 100kHz? sei(); } ISR(TIMER0_COMP_vect) { static uint16_t count=0; if(count>x) PORTA &= ~16; else PORTA |= 16; if(count>y) PORTC &= ~1; else PORTC |= 1; if(count>z) PORTC &= ~2; else PORTC |= 2; if(count<1000)count++; else count=0; }; int main(void) { init(); z=105; y=110; x=90; delay(50000); z=90; delay(10000); while(1); return 0; }
GrußCode:volatile uint16_t count, time; void delay(uint16_t d) // Warteschleife { d+=time; while(d>time); } und in der ISR: if (count < 1000) count++; else { count=0; time++; }
mic







Zitieren

Lesezeichen