# Unexplained behavior pic port b on change interrupt

I am trying to configure the port b interrupt on change interrupts to work with a program I am writing with MC XC8 demo version. I am using a PIC16F628A I am using this code to initialize the pic for interrupt reading. However it seems when I start up my program an interrupt is called. I don't understand why this is happening as the datasheet says interrupts will only be generated for pins set as an input and I have set all of port B to be output. Could someone please explain this strange behavior

int main()
{
TRISA2 = 0;
TRISA3 = 0;
PORTB = 0;
TRISB = 0;
CMCON = 0x07;
initialise();
writeCommand(0b00001111);
writeCommand(0b00000110);
writeString("Hello World ", 11);
GIE = 1;
RBIE = 1;
PEIE = 0;
while(1);
}

void interrupt interruptRoutine()
{
if(RBIF)
{
writeString("Interrupt", 9);
RBIF = 0;
}
}


I'm guessing that the interruptRoutine gets called between RBIE = 1; and PEIE = 0;. That's a brief opportunity between instructions for an already-pending interrupt to fire. (note that the interrupt latency could make it appear that it happened an instruction or two later than it actually did) So you might want to rearrange your interrupt configuration instructions to close that gap.