Interrupt on change Example not working Please help...

Status
Not open for further replies.

asking

Full Member level 5
Joined
Sep 21, 2010
Messages
279
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Visit site
Activity points
3,377
Code:
unsigned char x;

// Interrupt Handler
void interrupt()
{
  // RB Port Change Interrupt
  if(PIR1.RBIF == 1)   // if the RB Port Change Interrupt flag is set...
  {
    PORTA.F1 = ~PORTA.F1;//LED on/off on press of switch 
    x = PORTB;      // Need to read or write to the port to clear mismatch condition
    PIR1.RBIF =0;
  }

}
// code starts here...
void main()
{
TRISA = 0b00000000;
TRISB = 0b00100000; //RB5 defined as input and push switch connected to it

  // Set Interrupt Enable bits
  INTCON.RBIE = 1;    // bit 3 RB Port Change Interrupt Enable

  //Set global Interrupt Enable bits
  INTCON.GIE = 1;     // global interrput enable

  while(1)  //endless loop
  {
  }
}

I just want to toggle led on PortA1 on/off when i press push button on RB5 ...i have made the above code but i don't know why its not working please help...
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…