This topic shows how to use PORTB change interrupt, this interrupt occurs when an input port changes its state. The pins responsible for this interrupt are RB4, RB5, RB6 and RB7.
PIC16F84A PORTB interrupt on change (IOC) example circuit:
As shown in the circuit schematic above there is an LED and 4 pushbuttons. The interrupt occurred when a pushbutton is pressed or depressed. When the interrupt occurred the LED toggles its state. The video below describes the circuit and the code.
PIC16F84A PORTB interrupt on change (IOC) example CCS C code:
// PIC16F84A PORTB interrupt on change example
// http://ccspicc.blogspot.com/
// electronnote@gmail.com
#include <16F84A.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(crystal=8000000)
#INT_RB
void rb_isr(void)
{
clear_interrupt(INT_RB); // Clear RB port change interrupt flag bit
output_toggle(PIN_A0);
}
void main()
{
set_tris_b(0xF0);
clear_interrupt(INT_RB); // Clear RB port change interrupt flag bit
enable_interrupts(INT_RB); // Enable RB port change interrupt
enable_interrupts(GLOBAL); // Enable all unmasked interrupt
output_low(PIN_A0);
while(TRUE) ; // Endless loop
}
PIC16F84A PORTB interrupt on change (IOC) example video: