Thread: PORTB Help
View Single Post
  #1   Spotlight this post!  
Unread 28-01-2008, 20:59
cprogrammer's Avatar
cprogrammer cprogrammer is offline
Registered User
FRC #1595 (Gremlins)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Washington
Posts: 42
cprogrammer will become famous soon enoughcprogrammer will become famous soon enough
Question 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
}
}

Last edited by cprogrammer : 28-01-2008 at 21:38.