1
\$\begingroup\$

I am working with a PIC16F877A on a simulator on MPLABX 5.35 with XC8 compiler ver 2.32. I am trying to understand and work with the external interrupt, I am facing a few issues while debugging.

#include <xc.h> 
#define _XTAL_FREQ 1000000 
void __interrupt() check(void){
 
 __delay_ms(4);
 INTCONbits.INTF = 0;
 return;
}
void main(void){
 TRISBbits.TRISB0 = 1; //setting RB0 for input
 OPTION_REGbits.INTEDG = 0; //setting falling edge trigger
 INTCONbits.INTE = 1; //setting external interrupt (RBO) to on
 INTCONbits.GIE = 1; //setting enabling global interrupts
 INTCONbits.INTF = 0; //setting external interrupts flags to off
 
 
 while(1){
 
 }
 
 
}

I'm looping a while loop and fire check() when there is a change in RB0.

enter image description here

I am using stimulus to change the RB0 value to fire the ISR. To check whether it's firing I placed a breakpoint at __delay_ms(4). But when I debug, for some reason it does not fire the ISR. During debug mode, it just seems to be stuck in the while loop. I tried to use the SLEEP(); macro but that did not work as it would just go to the end of the main function (I am not sure if that is sleep macro, I am assuming that it's the end of the program).

enter image description here

When I fire the low pulse through the stimulus, it does not change to the check function, its just stuck in the while loop. What am is supposed to do the debug the interrupt so I can get seeable output.

Mike
2,6192 gold badges17 silver badges31 bronze badges
asked Apr 16, 2021 at 14:17
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

In MPLAB, open from the menu: Windows->Simulator->IOPin. Then select to see RB0 in the I/O pins tab. On RESET RB0 will be zero (0). On the stimulus click RB0 (set High) at least once, and verify that in the IOPin tab that RB0 is high. Then in the stimulus tab click the RB0 (pulse low), and you should get an interrupt. (Remember to set a breakpoint in the interrupt code to break your code in the interrupt). Because you have selected falling edge trigger, the signal has to go from a high to a low to be able to trigger the interrupt.

answered Apr 16, 2021 at 15:22
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Well, I did as you said, I checked the I/O pins, the set high is working fine but when I try to pulse low it's not working. Is there any alternative to pulsing low? \$\endgroup\$ Commented Apr 17, 2021 at 13:03
  • \$\begingroup\$ never mind, I just used clock stimulus instead of pulsing low manually and safe to say it works. \$\endgroup\$ Commented Apr 17, 2021 at 13:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.