Kagerer
13.05.2008, 09:27
Hallo,
ich hab ein Problem mit dem Interrupt an einem ATMega16. Und zwar hab ich einen Taster an Int0 angeschlossen. Der Controller löst aber nicht zuverlässig die Interrupt-Routine aus, wenn ich den Taster betätige.
Hier mal der Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
// Ports initialisieren
void port_init()
{
// Alle Pins bis auf PD2 & PD3 als Ausgang schalten
DDRA = 0xff;
DDRB = 0xff;
DDRC = 0xff;
DDRD = 0b11110011;
//Pullup-Widerstand von PD2 aktivieren
PORTD |= (1<<PD2);
// Interrupt vorbereiten
MCUCR |= (1 << ISC01); // INT0 läst bei fallender Flanke aus
GICR |= (1 << INT0); // INT0 aktivieren
}
// Funktion zum Einschalten der LEDs
void led_on(uint8_t led)
{
if(led == 1) PORTA |= (1 << PA3);
if(led == 2) PORTB |= (1 << PB4);
if(led == 3) PORTA |= (1 << PA2);
if(led == 4) PORTD |= (1 << PD0);
if(led == 5) PORTC |= (1 << PC5);
if(led == 6) PORTB |= (1 << PB7);
if(led == 7) PORTC |= (1 << PC6);
if(led == 8) PORTB |= (1 << PB6);
if(led == 9) PORTC |= (1 << PC7);
if(led == 10) PORTB |= (1 << PB5);
if(led == 11) PORTA |= (1 << PA5);
if(led == 12) PORTA |= (1 << PA4);
if(led == 13) PORTB |= (1 << PB3);
if(led == 14) PORTA |= (1 << PA1);
if(led == 15) PORTB |= (1 << PB2);
if(led == 16) PORTA |= (1 << PA7);
if(led == 17) PORTB |= (1 << PB1);
if(led == 18) PORTA |= (1 << PA6);
if(led == 19) PORTB |= (1 << PB0);
if(led == 20) PORTA |= (1 << PA0);
if(led == 21) PORTD |= (1 << PD6);
if(led == 22) PORTC |= (1 << PC0);
if(led == 23) PORTD |= (1 << PD7);
if(led == 24) PORTC |= (1 << PC4);
if(led == 25) PORTD |= (1 << PD1);
if(led == 26) PORTC |= (1 << PC3);
if(led == 27) PORTD |= (1 << PD4);
if(led == 28) PORTC |= (1 << PC2);
if(led == 29) PORTD |= (1 << PD5);
if(led == 30) PORTC |= (1 << PC1);
}
// Funktion zum Ausschalten der LEDs
void led_off(uint8_t led)
{
if(led == 1) PORTA &= ~(1 << PA3);
if(led == 2) PORTB &= ~(1 << PB4);
if(led == 3) PORTA &= ~(1 << PA2);
if(led == 4) PORTD &= ~(1 << PD0);
if(led == 5) PORTC &= ~(1 << PC5);
if(led == 6) PORTB &= ~(1 << PB7);
if(led == 7) PORTC &= ~(1 << PC6);
if(led == 8) PORTB &= ~(1 << PB6);
if(led == 9) PORTC &= ~(1 << PC7);
if(led == 10) PORTB &= ~(1 << PB5);
if(led == 11) PORTA &= ~(1 << PA5);
if(led == 12) PORTA &= ~(1 << PA4);
if(led == 13) PORTB &= ~(1 << PB3);
if(led == 14) PORTA &= ~(1 << PA1);
if(led == 15) PORTB &= ~(1 << PB2);
if(led == 16) PORTA &= ~(1 << PA7);
if(led == 17) PORTB &= ~(1 << PB1);
if(led == 18) PORTA &= ~(1 << PA6);
if(led == 19) PORTB &= ~(1 << PB0);
if(led == 20) PORTA &= ~(1 << PA0);
if(led == 21) PORTD &= ~(1 << PD6);
if(led == 22) PORTC &= ~(1 << PC0);
if(led == 23) PORTD &= ~(1 << PD7);
if(led == 24) PORTC &= ~(1 << PC4);
if(led == 25) PORTD &= ~(1 << PD1);
if(led == 26) PORTC &= ~(1 << PC3);
if(led == 27) PORTD &= ~(1 << PD4);
if(led == 28) PORTC &= ~(1 << PC2);
if(led == 29) PORTD &= ~(1 << PD5);
if(led == 30) PORTC &= ~(1 << PC1);
}
// Programmcounter
volatile uint8_t progcounter = 0;
// INT0
ISR(INT0_vect) {
if(progcounter < 3) progcounter++;
else progcounter = 1;
}
// Hauptprogramm
int main()
{
// Ports initialisieren
port_init();
// Interrupts global aktivieren
sei();
// Endlosschleife
while(1){
if(progcounter == 1) led_on(30);
if(progcounter == 2) led_off(30);
}
return(0);
}
Ich hoffe, dass mir jemand bei meinem Problem weiterhelfen kann.
MfG
Christian
ich hab ein Problem mit dem Interrupt an einem ATMega16. Und zwar hab ich einen Taster an Int0 angeschlossen. Der Controller löst aber nicht zuverlässig die Interrupt-Routine aus, wenn ich den Taster betätige.
Hier mal der Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
// Ports initialisieren
void port_init()
{
// Alle Pins bis auf PD2 & PD3 als Ausgang schalten
DDRA = 0xff;
DDRB = 0xff;
DDRC = 0xff;
DDRD = 0b11110011;
//Pullup-Widerstand von PD2 aktivieren
PORTD |= (1<<PD2);
// Interrupt vorbereiten
MCUCR |= (1 << ISC01); // INT0 läst bei fallender Flanke aus
GICR |= (1 << INT0); // INT0 aktivieren
}
// Funktion zum Einschalten der LEDs
void led_on(uint8_t led)
{
if(led == 1) PORTA |= (1 << PA3);
if(led == 2) PORTB |= (1 << PB4);
if(led == 3) PORTA |= (1 << PA2);
if(led == 4) PORTD |= (1 << PD0);
if(led == 5) PORTC |= (1 << PC5);
if(led == 6) PORTB |= (1 << PB7);
if(led == 7) PORTC |= (1 << PC6);
if(led == 8) PORTB |= (1 << PB6);
if(led == 9) PORTC |= (1 << PC7);
if(led == 10) PORTB |= (1 << PB5);
if(led == 11) PORTA |= (1 << PA5);
if(led == 12) PORTA |= (1 << PA4);
if(led == 13) PORTB |= (1 << PB3);
if(led == 14) PORTA |= (1 << PA1);
if(led == 15) PORTB |= (1 << PB2);
if(led == 16) PORTA |= (1 << PA7);
if(led == 17) PORTB |= (1 << PB1);
if(led == 18) PORTA |= (1 << PA6);
if(led == 19) PORTB |= (1 << PB0);
if(led == 20) PORTA |= (1 << PA0);
if(led == 21) PORTD |= (1 << PD6);
if(led == 22) PORTC |= (1 << PC0);
if(led == 23) PORTD |= (1 << PD7);
if(led == 24) PORTC |= (1 << PC4);
if(led == 25) PORTD |= (1 << PD1);
if(led == 26) PORTC |= (1 << PC3);
if(led == 27) PORTD |= (1 << PD4);
if(led == 28) PORTC |= (1 << PC2);
if(led == 29) PORTD |= (1 << PD5);
if(led == 30) PORTC |= (1 << PC1);
}
// Funktion zum Ausschalten der LEDs
void led_off(uint8_t led)
{
if(led == 1) PORTA &= ~(1 << PA3);
if(led == 2) PORTB &= ~(1 << PB4);
if(led == 3) PORTA &= ~(1 << PA2);
if(led == 4) PORTD &= ~(1 << PD0);
if(led == 5) PORTC &= ~(1 << PC5);
if(led == 6) PORTB &= ~(1 << PB7);
if(led == 7) PORTC &= ~(1 << PC6);
if(led == 8) PORTB &= ~(1 << PB6);
if(led == 9) PORTC &= ~(1 << PC7);
if(led == 10) PORTB &= ~(1 << PB5);
if(led == 11) PORTA &= ~(1 << PA5);
if(led == 12) PORTA &= ~(1 << PA4);
if(led == 13) PORTB &= ~(1 << PB3);
if(led == 14) PORTA &= ~(1 << PA1);
if(led == 15) PORTB &= ~(1 << PB2);
if(led == 16) PORTA &= ~(1 << PA7);
if(led == 17) PORTB &= ~(1 << PB1);
if(led == 18) PORTA &= ~(1 << PA6);
if(led == 19) PORTB &= ~(1 << PB0);
if(led == 20) PORTA &= ~(1 << PA0);
if(led == 21) PORTD &= ~(1 << PD6);
if(led == 22) PORTC &= ~(1 << PC0);
if(led == 23) PORTD &= ~(1 << PD7);
if(led == 24) PORTC &= ~(1 << PC4);
if(led == 25) PORTD &= ~(1 << PD1);
if(led == 26) PORTC &= ~(1 << PC3);
if(led == 27) PORTD &= ~(1 << PD4);
if(led == 28) PORTC &= ~(1 << PC2);
if(led == 29) PORTD &= ~(1 << PD5);
if(led == 30) PORTC &= ~(1 << PC1);
}
// Programmcounter
volatile uint8_t progcounter = 0;
// INT0
ISR(INT0_vect) {
if(progcounter < 3) progcounter++;
else progcounter = 1;
}
// Hauptprogramm
int main()
{
// Ports initialisieren
port_init();
// Interrupts global aktivieren
sei();
// Endlosschleife
while(1){
if(progcounter == 1) led_on(30);
if(progcounter == 2) led_off(30);
}
return(0);
}
Ich hoffe, dass mir jemand bei meinem Problem weiterhelfen kann.
MfG
Christian