LCD interfacing with PIC16F877 Code and Simulation
In this tutorial you will find Proteus simulation and Code of "How to interface 16x2 LCD with PIC16F877 using MPLAB X IDE and XC8 compiler". You may download code, schematic and Proteus simulation from download section at the bottom of this page.
In this post I assumed that you must know following if not then please read them before proceeding any further in this post:
In figure 1. I have used PIC16F877 with PortB connected to an LCD as data and address bus whereas Register Select (RS) and Enable (E) pins are connected to Pins RC0 and RC1 respectively. Whereas MCLR is connected to 5VDC which means Controller is in Normal Operating mode (see datasheet for further details). I have set Crystal frequency 10MHz.
|Figure 1: Proteus Simulation.|
In the following figure 2. We have a main function in which we initialize LCD and a while loop to display strings on LCD and update LCD after every 1 seconds. approx. Note that first string is displayed in first line by moving cursor to first line address and second string is displayed on second line by moving cursor to second line address.
|Figure 2: main C file.|
In the following figure 3 we have LCD.h file in which we have all the #define like LCD data bus, LCD enable and register select pins. First and second line addresses.
|Figure 3. LCD.h|
In Initialize_LCD() I made Enable and RS(Register Select) pins and portB as output by setting their Tristate registers. And then I write some commands to LCD which are necessary for initialization as describes in LCD datasheet.
|Figure 4. Initialize LCD.|
In figure 5. we have Toggle_Enable_Pin_LCD() which is used to toggle Enable pin after every command or data send to LCD according to datasheet. In Initialize_LCD() I made Enable and RS(Register Select) pins and portB as output by setting their Tristate registers. And then I write some commands to LCD which are necessary for initialization as describes in datasheet.
|Figure 5. Toggle Enable pin.|
This function is used to write commands to LCD In which we have RS low.
|Figure 6. Write command to LCD.|
This function is used to write Data to LCD In which we have RS High.
|Figure 7. Write Data to LCD.|
You may download Code which is written in C language. Using MPLAB X IDE and compiler xc8 for 8 bit Microcontrollers. Click here
If you learned something interesting please consider donation. Which would help me to produce such content for young engineers Thank you.
- GPS interfacing with PICmicrocontroller.
- How to interface 4x4 Keypad with PIC.
- Two wirelessly communicating Circuitsusing Xbee
- How to get interrupt on change oflogic on Pins (Input Change Notification).
- Over Voltage Protection
- Step by step home made PCB tutorial
- How to measure Negative and Positivetemperature using LM35
- AC Voltmeter RMS + Peak voltage
For all topics Click here
All the text and graphics contained on this page belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission.
© Copyright 2014 IbrahimLabs. All rights reserved.