Thursday, March 10, 2016

PIC16F877A External interrupt


PIC16F877A has one external interrupt at RB0/INT pin. When an interrupt occurred, the microcontroller immediately executes the code attached with the interrupt, after finishing the interrupt code the microcontroller returns to the main code. This topic shows to configure and use the external interrupt.
PIC16F877A External interrupt example circuit:
The following circuit schematic shows a simple circuit that turns on and off the LED connected to RC0 using a pushbutton connected to RB0 pin. The external interrupt is used to toggle the status of the LED.
pic16f877a external hardware interrupt rb0 int ccs pic c circuit
PIC16F877A External interrupt example CCS C code:

// PIC16F877A external interrupt
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F877A.h>
#use delay(crystal=8000000)

#INT_EXT
void ext_isr(void)
{
   clear_interrupt(INT_EXT);
   output_toggle(PIN_C0);
}
void main()
{
   output_low(PIN_C0);
   ext_int_edge(H_TO_L);
   clear_interrupt(INT_EXT);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   while(TRUE) ; // Endless loop
}