-
Interrupt Problem
Hallo,
Ich benutzte den C18 compiler und habe folgendes Programm geschreiben.
Es soll auf einen Timerinterrupt und den Externen Interrupt auf RB0 reagieren. Er springt aber nie in die ISR. Ich finden keinen Fehler im Code.
Ich hoffe jemand von euch kann mir helfen. Danke im voraus.
Code:
#include <p18f4620.h>
#include <usart.h>
#include <PortB.h>
#pragma config OSC = HS
#pragma config DEBUG = OFF
#pragma config XINST = OFF
#pragma config WDT = OFF
#pragma config CP0 = OFF
#pragma config LVP = OFF
void ISR();
#pragma code high_vector_section=0x8
void high_vector (void)
{
_asm GOTO ISR _endasm
}
#pragma code
#pragma interrupt ISR
void ISR(void)
{
putrsUSART(">>Interrupt!\n\r");
if(INTCONbits.INT0IF)
{
putrsUSART(">>Interrupt PortB\n\r");
INTCONbits.INT0IF = 0; //claer the interrupt flag
}
else if(PIR1bits.TMR2IF)
{
putrsUSART(">>Interrupt Timer\n\r");
PIR1bits.TMR2IF = 0;
}
}
#pragma code
void main()
{
// Open the USART configured as 8N1, 9600 baud
OpenUSART ( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
32);
//4.424 --> 57600
//31.55 --> 9600
putrsUSART("\n\asdf\n\r");
TRISBbits.TRISB0 = 1; //RB0 input
PIR1 = 0; // Clear the peripheral interrupt flags
PIE1bits.TMR2IE = 1; //Enable the timer interrupt
INTCONbits.INT0IE = 1; //enable RB0 interrupt
INTCONbits.GIEH = 1; // enable global interrupts
T2CONbits.TMR2ON = 1;
putrsUSART(">>Init Complete!\n\r");
while(1){}
}
-
Meiner Meinung nach hast Du vergessen, die Peripheral Interrupts
einzuschalten.
INTCONbits.PEIE = 1;
mfg Siro
-
Danke für deine Antwort.
Es funktioniert aber leider trotzdem nicht.
-
Ich hab jetz ein paar änderungen am programm vorgenommen. Jetzt funktioniert der Timerinterupt, der exteren aber immer noch nicht.
Code:
#include <p18f4620.h>
#include <usart.h>
#include <PortB.h>
#pragma config OSC = HS
#pragma config DEBUG = OFF
#pragma config XINST = OFF
#pragma config WDT = OFF
#pragma config CP0 = OFF
void ISR();
void SetupInt0();
void SetupTimer0();
#pragma code high_vector=0x8
void high_vector(void)
{
_asm GOTO ISR _endasm
}
#pragma code
#pragma interrupt ISR
void ISR(void)
{
if(INTCONbits.TMR0IF)
{
putrsUSART(">>Timer Interrupt\n\r");
INTCONbits.TMR0IF = 0;
}
else if(INTCONbits.INT0IF)
{
putrsUSART(">>INT0\n\r");
INTCONbits.INT0IF = 0; //claer the interrupt flag
}
INTCONbits.GIE = 1;
}
#pragma code
void main()
{
// Open the USART configured as 8N1, 9600 baud
OpenUSART ( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
32);
TRISB=0xff;
SetupInt0();
SetupTimer0();
INTCONbits.PEIE = 1; //Peripheral Interrupt Enable
RCONbits.IPEN = 0; // No Interrupt Priority
INTCONbits.GIE = 1; //Global Interrupt Enable
while(1){}
}
void SetupInt0()
{
INTCONbits.INT0IF = 0; //Clear the External Interrupt INT0 Flag
TRISBbits.TRISB1 = 1; //RB0 input
INTCON2bits.INTEDG0 = 0; //External Interrupt Falling Edge Select bit
INTCONbits.INT0IE = 1; //External Interrupt INT0 Enable
}
void SetupTimer0()
{
T0CONbits.T0CS = 0; //Clock source = Internal instruction cycle clock (CLKO)
T0CONbits.T08BIT = 0; // 16Bit Timer
T0CONbits.PSA = 0; // Prescaler
T0CONbits.TMR0ON = 1; // Timer0 on
INTCONbits.TMR0IF = 0;//TMR0 Overflow Interrupt Flag bit
INTCONbits.TMR0IE = 1;// Timer0 Interrupt Enable
}
Vielleicht sieht ja noch irgendjemand den Fehler.