Thread: interupts 3-6??
View Single Post
  #10   Spotlight this post!  
Unread 28-01-2007, 21:41
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: interupts 3-6??

Quote:
Originally Posted by Joohoo View Post
I am currently trying to develope some code for multiple encoders and I need to use interupts 3-6

I have some code from kevin watson's site and it works, but I don't know why

How do you differentite between the interupt 3-6 even though it is the same register?

thanx
This is the code Mike is referring to:

-Kevin

Code:
 
if (INTCONbits.RBIF && INTCONbits.RBIE) // external interrupts 3 through 6?
 {
 
// This does two things. First we grab a copy of PORTB, which 
// contains the states of the four interrupts. Secondly, reading
// this register resets an internal flag that would otherwise cause 
// another interrupt to fire-off when you cleared the interrupt 
// flag in the next instruction...
  Port_B = PORTB;          
 
// This clears the interrupt flag, informing the processor that you've
// handled the interrupt
  INTCONbits.RBIF = 0;
 
// This line of code updates a variable using the exclusive-or operation.
// If the state of one of the interrupts has changed between the last
// time this function was called and now, a bit in Port_B_Delta will be
// set to one, signaling that that interrupt service routine needs to be
// called
  Port_B_Delta = Port_B ^ Old_Port_B;
 
// Now that we know which inputs have changed, save a copy of the
// current state so we'll know which one(s) changed next time.
  Old_Port_B = Port_B;
 
// This checks to see if the bit associated with interrupt 3 has changed
// and if it has, call the interrupt service routine
  if(Port_B_Delta & 0x10)
  {
// Call the interrupt 3 handler and include the current state of the
// interrupt pin. The wacky bit of code "Port_B & 0x10 ? 1 : 0" is the
// same thing as:
//
// if(Port_B & 0x10)
// {
// return(1)
// }
// else
// {
// return(0)
// }
// This is done to ensure the value sent into the interrupt
// handler is either 0 or 1.
   Int_3_Handler(Port_B & 0x10 ? 1 : 0);
  }
 
// Each one must be checked individually because more than one may
// have changed
  if(Port_B_Delta & 0x20)
  {
   Int_4_Handler(Port_B & 0x20 ? 1 : 0);
  }
  if(Port_B_Delta & 0x40)
  {
   Int_5_Handler(Port_B & 0x40 ? 1 : 0);
  }
  if(Port_B_Delta & 0x80)
  {
   Int_6_Handler(Port_B & 0x80 ? 1 : 0);
  }
 }
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org

Last edited by Kevin Watson : 28-01-2007 at 21:44.