Tuesday, October 9, 2012

Using RB0 External Interrupt of PIC 16F877A


This is a demonstration for the RB0 external interrupt of PIC 16F877A,  below are features of the external interrupt that we are using.

An input ( depending on how we set it up ) on the RB0 triggers the interrupt, either the signal goes from 0 to 1, called the rising edge, or as the signal goes from 1 to 0, called the falling edge. This sets the interrupt flag, and if the interrupt is enabled ( and we are not already in an interrupt ) the microcontroller goes to the interrupt subroutine.




The use of the RB0/Int to should be clear that the use of RB0/Int function of a picmicro requires the setting of the:
GIE(7): set to 1 to enable global interrupts
INTE(4): set to 1 to enable interrupts on pin RB0
PEIE(6): to disable other periferal interrupts
and the set of the INTEDG bit(6) of the OPTION_REG register simply to select the  rising or falling edge, of the signal.

When switch is pressed RB0 goes from 0 to 1 causing an interrupt which calls the interrupt() routine. The interrupt routine increment the value of PORD by one. 

Code

  void interrupt(void)
{
  PORTD++;          //Increment PORTD value by one
  //delay_ms(500);
  INTCON.INTF = 0;          // clear the interrupt flag
}
void main(void)
{
  TRISB = 0x01;
  TRISD = 0x00;
  INTCON.GIE = 1;                  //Enable Global Interrupt
  INTCON.INTE = 1;                //Enable RB0/INT external Interrupt
  INTCON.PEIE = 0;                //Disable all unmasked peripheral interrupt
  OPTION_REG.INTEDG = 1;    //Interrupt on rising edge
  PORTD=0;
do
  {
   } while(1);
}





tags: PIC, PIC 16F877A, PIC 16F877A circuits, PIC 16F877A external interupt, PIC 16F877A projects, MikroC PIC Tutorial, pic interrupt, PIC Microcontroller Interrupt, MikroC, Microcontroller

0 comments:

Post a Comment