Hi all,
I am trying to use the external interrupt of an 18f microcontroller. I want the program to operate as follow:
Turn LED connected to port D.0 OFF
Turn LED connected to port D.1 ON
If external interrupt INT0 is activated, invert the LEDs from on to off
Can someone tell me what is wrong with the ISR code below please? I did debug the program and it remains looping in the main function no matter if the interrupt is active of not.
I am trying to use the external interrupt of an 18f microcontroller. I want the program to operate as follow:
Turn LED connected to port D.0 OFF
Turn LED connected to port D.1 ON
If external interrupt INT0 is activated, invert the LEDs from on to off
Can someone tell me what is wrong with the ISR code below please? I did debug the program and it remains looping in the main function no matter if the interrupt is active of not.
Code:
#pragma code main = 0x00
#pragma code Interrupt_HIGHpriority = 0x08
#pragma Interrupt_HIGHpriority
void Interrupt_HIGHpriority(void);
void main(void)
{
TRISBbits.TRISB0 = 1;
TRISDbits.TRISD0 = 0;
TRISDbits.TRISD1 = 0;
INTCON = 0;
RCON = 0;
INTCONbits.INT0IF = 0;
RCONbits.IPEN = 0;
INTCONbits.GIE = 1;
INTCONbits.INT0IE = 1;
INTCON2bits.INTEDG0 = 0;
while(1)
{
LATDbits.LATD0 = 0;
LATDbits.LATD1 = 1;
}
}
//Interrupt Service Routine
void Interrupt_HIGHpriority(void)
{
INTCONbits.GIE = 0;
LATDbits.LATD0 = 1;
LATDbits.LATD1 = 0;
while(1){}
INTCONbits.GIE = 1;
INTCONbits.INT0IF = 0;
}
#pragma code
Last edited: