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 ?
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
}