Hi Versuche mich gerade an Interrupts in C an einem Atmel Atmega8 und ich bekomme das nicht auf die Reihe!! Ich möchte nach einer gewissen Zeit das sich das Interrupt von alleine auslöst! Mein code wird in WIN AVR als Falsch angezeigt was könnte es sein? # define F_CPU 1000000L // 1MHz CPU clock # include <util/delay.h> // Bibliotheken # include <avr/io.h> #include <avr/io.h> #include <avr/interrupt.h> int main (void) // Hauptteil { DDRB |= 0xff; PORTB |= 0xff; DDRC |= 0xff; PORTC |= 0xff; DDRD |= 0xff; PORTD |= 0xff; while (1) // Endlosschleife { PORTC =0x00; _delay_ms (200); //PORT C Beginn des Lauflichts PORTC &= ~_BV (PC0) ; // Port C0 an 100ms warten _delay_ms (100) ; PORTC |= _BV (PC0) ; // PORT C0 aus 100 ms warten PORTC &= ~_BV (PC1) ; // PORT PC1 an 100 ms warten _delay_ms (100) ; PORTC |= _BV (PC1) ; // PORT PC1 aus 100ms warten PORTC &= ~_BV (PC2) ; // PORT PC2 an 100 ms warten _delay_ms (100) ; PORTC |= _BV (PC2) ; // // PORT PC2 aus 100ms warten PORTC &= ~_BV (PC3) ; // PORT PC3 an 100ms warten _delay_ms (100) ; PORTC |= _BV (PC3) ; // // PORT PC3 aus 100ms warten PORTC &= ~_BV (PC4) ; // PORT PC4 an 100ms warten _delay_ms (100) ; PORTC |= _BV (PC4) ; // // PORT PC4 aus 100ms warten PORTC &= ~_BV (PC5) ; // PORT PC5 an 100ms warten _delay_ms (100) ; PORTC |= _BV (PC5) ; // // PORT PC5 aus 100ms warten PORTC &= ~_BV (PC6) ; // PORT PC6 an 100ms warten _delay_ms (100) ; PORTC |= _BV (PC6) ; // PORT PC6 aus 100ms warten PORTB =0x00; _delay_ms (200); // PORTB Beginn des Lauflichts PORTB &= ~_BV (PB0) ; // PORT PB0 an 100ms warten _delay_ms (100) ; PORTB |= _BV (PB0) ; // PORT PB0 aus 100ms warten PORTB &= ~_BV (PB1) ; // PORT PB1 an 100ms warten _delay_ms (100) ; PORTB |= _BV (PB1) ; // PORT PB1 aus 100ms warten PORTB &= ~_BV (PB2) ; // PORT PB2 an 100ms warten _delay_ms (100) ; PORTB |= _BV (PB2) ; // PORT PB2 aus 100ms warten PORTB &= ~_BV (PB3) ; // PORT PB3 an 100ms warten _delay_ms (100) ; PORTB |= _BV (PB3) ; // PORT PB3 aus 100ms warten PORTB &= ~_BV (PB4) ; // PORT PB4 an 100ms warten _delay_ms (100) ; PORTB |= _BV (PB4) ; // PORT PB4 aus 100ms warten PORTB &= ~_BV (PB5) ; // PORT PB5 an 100ms warten _delay_ms (100) ; PORTB |= _BV (PB5) ; // PORT PB5 aus 100ms warten PORTB &= ~_BV (PB6) ; // PORT PB6 an 100ms warten _delay_ms (100) ; PORTB |= _BV (PB6) ; // PORT PB6 aus 100ms warten PORTB &= ~_BV (PB7) ; // PORT PB7 an 100ms warten _delay_ms (100) ; PORTB |= _BV (PB7) ; // PORT PB7 aus PORTD =0x00; _delay_ms (200); // PORT D Beginn des Lauflichts PORTD &= ~_BV (PD0) ; // PORT PD0 an 100ms warten _delay_ms (100) ; PORTD |= _BV (PD0) ; // PORT PD0 aus 100ms warten PORTD &= ~_BV (PD1) ; // PORT PD1 an 100ms warten _delay_ms (100) ; PORTD |= _BV (PD1) ; // PORT PD1 aus 100ms warten PORTD &= ~_BV (PD2) ; // PORT PD2 an 100ms warten _delay_ms (100) ; PORTD |= _BV (PD2) ; // PORT PD2 aus 100ms warten PORTD &= ~_BV (PD3) ; // PORT PD3 an 100ms warten _delay_ms (100) ; PORTD |= _BV (PD3) ; // PORT PD3 aus 100ms warten PORTD &= ~_BV (PD4) ; // PORT PD4 an 100ms warten _delay_ms (100) ; PORTD |= _BV (PD4) ; // PORT PD4 aus 100ms warten PORTD &= ~_BV (PD5) ; // PORT PD5 an 100ms warten _delay_ms (100) ; PORTD |= _BV (PD5) ; // PORT PD5 aus 100ms warten PORTD &= ~_BV (PD6) ; // PORT PD6 an 100ms warten _delay_ms (100) ; PORTD |= _BV (PD6) ; // PORT PD6 aus 100ms warten PORTD &= ~_BV (PD7) ; // PORT PD7 an 100ms warten _delay_ms (100) ; PORTD |= _BV (PD7) ; // PORT PD7 aus // globale Variablen volatile uint8_t flag; int main() { // IO konfigurieren DDRB = 0xFF; DDRC = 0xFF; DDRD = 0xFF; // Timer2 konfigurieren TCCR2 = 6; // Vorteiler 256 -> ~65ms Überlaufperiode TIMSK |= (1<<TOIE2); // Timer Overflow Interrupt freischalten // Interrupts freigeben sei(); // Endlose Hauptschleife while(1) { if (flag == 1) { // Neuer Timerzyklus ? flag = 0; // hier steht jetzt in Normalfall ein grosser Programmblock ;-) PORTD ^= (1 << PD5); // LED toggeln } } } ISR( TIMER2_OVF_vect ) { flag = 1; }
Egsler wrote: > Mein code wird in WIN AVR als Falsch angezeigt was könnte es > sein? Genauer geht's nicht?
Was schon mal definitiv falsch ist, ist die Tatsache, dass es in Deinem Programm zwei Funktionen mit dem Namen main() gibt, wobei die eine sogar innerhalb der anderen definiert ist! Außerdem solltest auch Du die Formatierungsoptionen diese Forums für C-Code nutzen!
@ Egsler (Gast) >Hi Versuche mich gerade an Interrupts in C an einem Atmel Atmega8 und Vielleicht versuchst du erstmal die Forenregeln zu lesen, um festzustellen, dass lange Quelltexte ind den Anhang gehören. Auch nicht falsch Netiquette. >Ich möchte nach einer gewissen Zeit das sich das Interrupt von alleine >auslöst! Ist ein Timer, dann lies mal was zum Thema Interrupt. MFG Falk
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.