PIC16F84A LCD interfacing code (using 3 pins only) + Proteus simulation
This post provides the LCD interfacing code using only 3 pins of PIC16F84A microcontroller. 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 make an LED blink with PIC16F84A microcontroller. If you don’t then please read this page first, before proceeding with this article.
PIC16F84A microcontroller has 13 IO pins. A 4×4 keypad needs 8 pins to interface with controllers. LCD needs at least 6 pins to interface with controllers. In order to interface keypad and LCD, both with PIC16F84A we need at least 14 pins. So it is not possible to directly attach LCD and keypad both with PIC16F84A even in 4bit mode. To make this possible, a serial to parallel shift register IC (4094) is used in this circuit. In this way by only using 3 pins of PIC16F84A microcontroller, we can interface LCD with it in 4bit mode. This is shown below in the figure.
In the above figure, RA0 pin is being used as Enable pin for LCD. RA1 pin is used as Clock pin and RA2 pin is used as Data pin for 4094 IC. When code starts running, then Hello is displayed on the LCD screen as shown in the above figure.
In the code you can easily select pins to be used for interfacing with the LCD. Following figure shows the pin selection code.
Here for example, you can change RA0 to RA3 if you want to attach Enable pin of the LCD on pin2 of PIC16F84A. You will also need to change LCD_E_Dir to TRISA3 for RA3.
The code for the main function is shown below.
LCD interfacing code using 3 pins for 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.
JLCPCB – Prototype 10 PCBs for $2 + 2 days Lead Time
China’s Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw
Current Project / Post can also be found using:
- Scrolling in LCD by PIC 16F84A using CCSC Compiler
- 4094 ic