Hallo zusammen!
Habe mir heute ein kleines Testprogramm geschrieben, um einfach mal zu sehen ob das so funktioniert was ich mir vorstelle.
Der Gedanke dabei war in der while-Schleife die Variable c auszuwerten. In der Interruptroutine, welche durch einen Button auf INT0 ausgelöst wird, soll der Wert von 1 auf 2 bzw. von 2 auf 1 geändert werden.
c bekommt im Programm direkt nach den Interruptinitialiesierungen den Wert 2. Meine LEDs blinken auch so wie es sein soll. Wenn ich den Button nun einmal betätige blinken die LED auch wieder richtig. Wird der Interrupt erneut ausgelöst ändert sich an dem Blinkverhalten allerdings nichts. Was ist da falsch gelaufen?
Hier mal der Code
Über eure Hilfe wäre ich sehr dankbar.PHP-Code:#define F_CPU 1000000UL
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#define LED1 0
#define LED2 1
#define LED3 2
#define LED4 3
int a = 1;
int b = 2;
int c;
int d;
int main(void)
{
DDRB = 0b00001111;
//Einstellung Interrupt
PORTD = 0b00000100;
GIMSK = (1<<INT0);
sei();
c = 2;
while (1)
{
if (c == 1)
{
PORTB |= ((1<<LED1) | (1<<LED3));
PORTB &= ~((1<<LED2) | (1<<LED4));
_delay_ms(500);
PORTB |= ((1<<LED2) | (1<<LED4));
PORTB &= ~((1<<LED1) | (1<<LED3));
_delay_ms(500);
}
else if (c == 2)
{
PORTB ^= ((1<<LED1) | (1<<LED2) | (1<<LED3) | (1<<LED4));
_delay_ms(500);
}
}
}
ISR(INT0_vect)
{
if((PINB & (1<<PINB1)) == 0)
{
if (c == 1)
{
d = b;
}
else if (c == 2)
{
d = a;
}
c = d;
return;
_delay_ms(100);
}
}
Gruß
Lichti01







Zitieren
Hoffentlich liegt das Ziel auch am Weg 

Lesezeichen