[SOLVED] Cant hit breakpoint in Interrupt on Change ISR: MPLAB sim / XC8 / 16F877A

Thread Starter

Rf4l

Joined Nov 22, 2016
11
Hi there. After successfully demoing my "Hello world" program...blinking LEDs...well toggling different port bits, i decided to up the anti a lil bit. So im trying to write a program that will display on PORT C the value of a counter that increments everytime the value on PORTB Pin 7 changes.

Im using MPLAB X IDE v3.45 & XC8 v1.38, and I am performing simulations using the simulator and registers (Variable, SFR and File) to confirm the contents of Ports, variables and registers. To change the value of Port B Pin 7, im using the "I/O Pin" simulator.

I currently have a breakpoint on line 22. dummy = PORTB; and i witness the following:

- The PORTB register toggles between 0x80 and 0x00 as I toggle PORTB Pin 7 on and off
- The interrupt register INTCON has the value 0x88 meaning my program correct sets bits GIE & RBIE (global interrupts and interrupt on change respectively

However:
- the INTCON.RBIF flag never gets set. therefore
- my interrupt on change subroutine never executes hence why
- the program never haults on my breakpoint

I am not sure if this may help, but when I am looking at the Special Function Registers (SFR) i notice that the INTCON register updates every now and then. I can tell because the font is usually black and turns red when there is a different value. it happens pretty quick, but i *think* it changes to 0x00 and then back to 0x88. This seems a bit odd to me because I would have imagined GIE and RBIE would stay set and then only the RBIF bit would set and then be cleared because of the interrupt.

Might anyone be able to point out what I am missing, or perhaps point me in the right direction ?

C:
:
#include <pic16f887.h>

char counter = 0;
char dummy = 0;

void main(void)
{
    TRISB = 0x80;                //Make Port B pin 7 input
    INTCONbits.RBIF = 0;    //clear port change interrupt flag
   
    INTCONbits.GIE = 1;     //enable global interrupts
    INTCONbits.RBIE = 1;    //enable port change interrupt
    while(1){
        PORTC = counter;       //update port c with value of counter
    }
}

void interrupt ISR (void){
    dummy = PORTB;           //dummy ready of port b
    INTCONbits.RBIF = 0;     //clear interrupt on change flag
    counter++;                       //increment counter
}
 

jpanhalt

Joined Jan 18, 2008
7,863
GIE is disabled (cleared) upon any interrupt. It is reset with the RETFIE instruction when the programs returns from the interrupt. Interrupt flags have to be cleared in software, which is best done during the interrupt and before returning. I am surprised that RBIE clears during your interrupt. Are you sure?

John
 

AlbertHall

Joined Jun 4, 2014
8,314
This program works for me - when toggling RB7 it stops at a breakpoint set at line 20 in your listing. I am using the same versions of software as you. I am using the asynchronous input and toggling RB7.
upload_2016-11-22_10-43-6.png
 

Thread Starter

Rf4l

Joined Nov 22, 2016
11
GIE is disabled (cleared) upon any interrupt. It is reset with the RETFIE instruction when the programs returns from the interrupt. Interrupt flags have to be cleared in software, which is best done during the interrupt and before returning. I am surprised that RBIE clears during your interrupt. Are you sure?

John
Hi John, thanks for your response, however I believe you may have mis read my post. I never get into the interrupt routine, so I do not believe that's what clears the RBIE flag.
 

Thread Starter

Rf4l

Joined Nov 22, 2016
11
This program works for me - when toggling RB7 it stops at a breakpoint set at line 20 in your listing. I am using the same versions of software as you. I am using the asynchronous input and toggling RB7.
View attachment 115751
Wow really ?!?!

The asynchronous input eh. I cant wait to try that when I get home. I can recall seeing the stimulous options in the menu there, but since the "I/O Pin" simulator worked for toggling the bits during my "hello world" I figured I would stick to that.

But thank you for trying this out for me. Will give it a go when I get home !
 

Thread Starter

Rf4l

Joined Nov 22, 2016
11
likely you didn't disable watchdog timer and it is resetting the mcu periodically (up until 0x88).
Hi dannyf, I haven't paid any attention to the WDT but thanks for pointing that out. Will have to read up on how it would affect my programming.
 

Thread Starter

Rf4l

Joined Nov 22, 2016
11
if you understand what your code does, you will know what the simulation is all about.
ok dannyf. I see whats going on here.

Im curious though, if you needed to make minor but necessary changes for your simulation to work, how then did AlbertHall get it to work with no mods.

Unfortunately I can't do any testing at the moment, but you and AlbertHall have given me somethings to try and learn more about when I get home. thank you. I appreciate it.
 

Thread Starter

Rf4l

Joined Nov 22, 2016
11
This program works for me - when toggling RB7 it stops at a breakpoint set at line 20 in your listing. I am using the same versions of software as you. I am using the asynchronous input and toggling RB7.
View attachment 115751
I've tried using the same async stimulus and that did not work for me.

Do you get any watch dog timer messages in the Simulator Output window at the bottom while the program is running ?

I get the message, "W0004-CORE: Watchdog Timer has caused a Reset."
 

Thread Starter

Rf4l

Joined Nov 22, 2016
11
likely you didn't disable watchdog timer and it is resetting the mcu periodically (up until 0x88).
This was true. disabled the WDT and now GIE and RBIE remain set....

however unfortunately, I still am not able to launch that Interrupt Sub Routine.
 

AlbertHall

Joined Jun 4, 2014
8,314
however unfortunately, I still am not able to launch that Interrupt Sub Routine.
Could you zip up the whole project directory and attach it here then I will see if it doesn't work for me and can possibly work out why?
 

AlbertHall

Joined Jun 4, 2014
8,314
For the PIC16F887 you need to select pins for interrupt on change. Add the line 'IOCBbits.IOCB7 = 1;' somewhere in the setup.
The reason my version worked was because I took the processor type from the thread subject line - PIC16F877 - and on that processor IOC is not pin selectable.
 

Thread Starter

Rf4l

Joined Nov 22, 2016
11
For the PIC16F887 you need to select pins for interrupt on change. Add the line 'IOCBbits.IOCB7 = 1;' somewhere in the setup.
The reason my version worked was because I took the processor type from the thread subject line - PIC16F877 - and on that processor IOC is not pin selectable.
Wow I totally missed that. Thank you.

Seems like the WDT was causing the program to not function as I wanted it (thanks dannyf) so I tried:
"WDTCONbits.SWDTEN = 0;" - is that not how you disable the WDT in c ?

Anyway, i disabled it using asm and it worked fine:

#asm
CLRWDT
#endasm

Many thanks AlbertHall & dannyf !
 
Top