PIC16F84A PORTB Interrupt on change
This topic shows how to use PIC16F84A microcontroller 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. The compiler used in this example is CCS PIC C.
PIC16F84A PORTB interrupt on change (IOC) example circuit:
Example circuit schematic is shown below.
As shown in the circuit schematic above there is an LED and 4 push buttons. The interrupt will occur when at least one push button is pressed or depressed. When the interrupt occurs the LED toggles its state. The video below describes the circuit and the code.
PIC16F84A PORTB interrupt on change (IOC) example CCS C code:
The C code below was tested with CCS C compiler version 5.051.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // PIC16F84A PORTB interrupt on change example // http://simple-circuit.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:
The video below shows Proteus simulation of the example.
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.