# PORTB Help

I was looking through Kevin’s Encoder program and noticed that in order to use the extra encoders, Kevin had to use the bundled interrupts. In order to distinguish between the interrupts, Kevin used PORTB to see which of the 4 fired. I was wondering what the PORTB extacly is, and how can I implement this myself.

Thanks Stephen

``````else if (INTCONbits.RBIF && INTCONbits.RBIE) // encoder 3-6 interrupt?
{
Port_B = PORTB; // remove the "mismatch condition" by reading port b
INTCONbits.RBIF = 0; // clear the interrupt flag
Port_B_Delta = Port_B ^ Old_Port_B; // determine which bits have changed
Old_Port_B = Port_B; // save a copy of port b for next time around

if(Port_B_Delta & 0x10) // did external interrupt 3 change state?
{
#ifdef ENABLE_ENCODER_3
Encoder_3_Int_Handler(Port_B & 0x10 ? 1 : 0); // call the encoder 3 interrupt handler (in encoder.c)
#endif
}
if(Port_B_Delta & 0x20) // did external interrupt 4 change state?
{
#ifdef ENABLE_ENCODER_4
Encoder_4_Int_Handler(Port_B & 0x20 ? 1 : 0); // call the encoder 4 interrupt handler (in encoder.c)
#endif
}
if(Port_B_Delta & 0x40) // did external interrupt 5 change state?
{
#ifdef ENABLE_ENCODER_5
Encoder_5_Int_Handler(Port_B & 0x40 ? 1 : 0); // call the encoder 5 interrupt handler (in encoder.c)
#endif
}
if(Port_B_Delta & 0x80) // did external interrupt 6 change state?
{
#ifdef ENABLE_ENCODER_6
Encoder_6_Int_Handler(Port_B & 0x80 ? 1 : 0); // call the encoder 6 interrupt handler (in encoder.c)
#endif
}
}``````

dont worry about it. FYI though, it’s an I/O port on the microcontroller. (i know this cuz i’m trying to learn the PIC). for more info, look to the pic18f8722 data sheet, but try to avoid going into the chip architechture oif at all possible, unless you really want to.

PORTB is a register value for each of (1-7)? digital_io. It says what each bit is in the datasheet, I would suggest taking a look at that.

basically

``````Port_B_Delta = Port_B ^ Old_Port_B; // determine which bits have changed
``````

that line uses the XOR to compare the new value to the old one. so if you have 10010101 as your old one and 10000101 as your new one the “Port_B_Delta” will be 00010000 which is also = 0x10 in hex and = 16 in our regular number system.

which is where this comes into play:

``````
if(Port_B_Delta & 0x10) // did external interrupt 3 change state?
{
``````

or something like that…