This post provides an example code to use PIC16F84A pins as inputs. After going through this example, you will understand how to make PIC16F84AΒ pins as inputs and how to read their value in the code. This code is written in C language using MPLAB with HI-TECH C compiler.You can download this code from the βDownloadsβ section at the bottom of this page.
It is assumed that you know how to blink an LED with PIC16F84AΒ microcontroller. If you donβt then please readΒ this pageΒ first, before proceeding with this article.
Following figure shows the circuit used to demonstrate how to get input in PIC16F84AΒ micro-controller.
In this figure,Β PIC16F84AΒ is running on external crystal of 20MHz[1]. RA0 pin is being used as the input pin. When the push button is in the pushed state then,Β RA0Β pin is high, otherwiseΒ RA0Β pin is low. Whenever RA0 pin is high, then RB0 pin (Attached with the LED) is also made high just to indicate correct reading of RA0 pin status in the micro-controller.
Code
The code for reading the status of RA0 pin is shown below.
Downloads
Input pin code using PIC16F84A was compiled inΒ MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10.Β To download code andΒ ProteusΒ simulationΒ click here.
For more detail: How to use PIC16F84A pin as input (Code+Proteus simulation)