External Interrupt on PIC16F887 not working // MPLABX XC8 C

trebla

Joined Jun 29, 2019
599
But your LCD routine is wrapped into two infinite loops and i cannot see any break instructions which can take program flow out from there. Please post the updated code, i can't see any LED related instruction in ISR routine.
 
Last edited:

upand_at_them

Joined May 15, 2010
939
If you can't get interrupts working start with a simple program that only handles an interrupt. You need to get to the least common denominator. Turn on an LED in your ISR.
 

JohnInTX

Joined Jun 26, 2012
4,787
Just curious but are you running the PK4 in the debug mode and have you set a breakpoint at the first statement of the interrupt routine? Right off I don’t see any reason why it shouldn’t respond to the external interrupt. Maybe it IS responding and you have other problems in seeing the results.

I got some compiler warnings when I compiled your code. You should fix those. Also, you are calling LCD routines from both main and interrupt code. The compiler is reporting that it has duplicated some of them. That will also keep any data local to the interrupt or main routine which could account for some of what you are seeing.

Those delays in the interrupt service and cd() will be troublesome eventually.

EDIT:
So looking at your interrupt code - formatted better here - note that you call cd() (clear display) after any interrupt.
C:
void __interrupt() ISR() {
    if (INTCONbits.INTF == 1) {
        if (PORTDbits.RD6 == 1) {
            if (sel[cursel] == 0) {
                sel[cursel] = selmax[cursel];
            }
            else {
                sel[cursel] = sel[cursel] - 1;
            }
        }
        else {
            if (sel[cursel] == selmax[cursel]) {
                sel[cursel] = 0;
            } else {
                sel[cursel] = sel[cursel] + 1;
            }
        }
    INTCONbits.INTF = 0;
    }// if INTF==1
    cd(); // CLEARS DISPLAY ON ANY INTERRUPT
    __delay_ms(200);
}// IRQ service
I ran the code in MPSIM and injected a high-going pulse into RB0. It interrupted and hit the breakpoint set at the top of the interrupt routine.
BreakPoint.jpg
So.. I think it's interrupting fine but you have problems in the code flow.
Good luck!
 
Last edited:
Top