PIC16F877A External Interrupt (RB0)
This PIC16F877A microcontroller tutorial provides the external interrupt code.As we know, PIC16F877A
microcontroller has one RB0/INT pin, this pin is used to service
external interrupts in the circuit shown below.
It is assumed that you know how to blink an LED with PIC16F877A microcontroller. If you don't then please read this page first, before proceeding with this article.
Circuit:
 |
Figure1: PIC16F877A External Interrupt |
In the above circuit, normally a low value is present on the RB0/INT pin because of the pull down resistor. But when push button is pressed then a low to high pulse on the RB0/INT pin generates the interrupt. And code is written in such a way that whenever interrupt is generated then RB4 pin is toggled.
Code:
 |
Figure 1: Main |
In the InitExternal_INT() function,
RB0 pin is made input to capture the push button signal. Then global
and INT pin interrupts are enabled.
 |
Figure2:Interrupt service routine |
|
|
In the RB0 INT
pin interrupt service routine code (shown above), RB4 pin is toggled.
This means that whenever you press the push button then LED attached
with RB4 pin will toggle its state.
 |
Figure3:Interrupt enabling code |
Downloads
External interrupt code for PIC16F877A as compiled in MPLAB X IDE with XC8 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.
Comments
Post a Comment