The microcontroller PIC16F84A has a unique external interrupt at RB0 pin (hardware interrupt). 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 is a small example shows how to use PIC16F84A external interrupt.
PIC16F84A external interrupt example circuit:
In the circuit schematic above we have just a button and an LED , the button is connected to the external interrupt RB0/INT pin and the LED is connected to RA0 pin. When the button pressed, an interrupt occurred and the LED will toggle its state.
// PIC16F84A external interrupt example
// http://ccspicc.blogspot.com/
// electronnote@gmail.com
#include <16F84A.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(crystal=8000000)
#INT_EXT
void ext_isr(void)
{
output_toggle(PIN_A0);
}
void main()
{
output_low(PIN_A0);
ext_int_edge(H_TO_L); // Interrupt on falling edge of RB0/INT pin
clear_interrupt(INT_EXT); // Clear RB0/INT external interrupt flag bit
enable_interrupts(INT_EXT); // Enable RB0/INT external interrupt
enable_interrupts(GLOBAL); // Enable all unmasked interrupt
while(TRUE) ; // Endless loop
}
PIC16F84A external interrupt example video:
The following video has some details about the circuit and the CCS C code.