Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Interfacing Lcd(8×1,8×2,10×1,10×2, 16×2, 16×4, 20×1, 20×2, 40×1,40×2) in 4 Bit Mode with Microchip Pic16f877A Microcontroller

By EG Projects

In this project i am going to interface 16×2 lcd display in 4-bit mode with Microchip Pic16f877 microcontroller. We can interface any size of character lcd display (8×1,8×2,10×1,10×2, 16×2,16×2,16×4,20×1,20×2,40×1,40×2 etc) in 4-bit mode with pic microcontrollers. In 4-bit interface mode only 4 lcd data lines are used to display data on lcd screen. Usually lcd is interfaced in 4-bit mode with microcontrollers to save I\O pins of microcontrollers. Before beginning any further i assume that you know difference between 4-bit and 8-bit lcd interfacing mode with microcntrollers. If not just take the below simple tutorial. Tutorial will help you in understating the basic difference, pros and cons of both the modes. It will also help you in understanding the code below easily.

  • Difference between 4-bit and 8-bit lcd working mode.​​

16×2 lcd in 4-bit mode with pic microcontroller – Project requirements

  • 16×2 character lcd.
  • Pic 16f877.
  • Potentiometer (For setting lcd contrast).
  • Crystal(20MHz).
  • Connecting wires.
  • Bread board or PCB for the circuit.
  • Power Supply. ​​

16×2 lcd in 4-bit mode

In 4-bit mode only 4-bit data is send to lcd at a time. Since 8-bit microcontrollers contains data in 8-bit form so we divide our data in to two nibbles(1-nibble=4-bits). First higher 4-bits(nibble) is send to lcd and then the lower 4-bits(nibble) with enable stroke signal. Only D4,D5,D6,D7 data pins of 16×2 lcd are used in 4-bit interface mode. D1,D2,D3,D4 are left empty. D4 is our least significant bit and D7 is highest significant bit in 4-bit interface mode. A typical interfacing diagram is given at the right side. 
Lcd interfacing with Pic Microcontroller in 4 Bit Mode

Lcd interfacing with Pic Microcontroller in 4 Bit Mode

Interfacing 16×2 Lcd with pic microcontroller in 4-bit mode – Project circuit diagram

Interfacing 16×2 lcd with Pic16f877 microcontroller is simple, if you have taken the above tutorial. The circuit of the project is also very simple. Port-B first 4 bits (RB0,RB1,RB2,RB3) of Pic16f877 microcontroller are used to send 4-bit data and commands to lcd. These four Pins(RB0,RB1,RB2,RB3) are Connected to four data pins of 16×2 lcd(D4,D5,D6,D7). Port-D pin# 5 is connected to rw(read-write) pin of lcd. Port-D pin# 6 is connected to rs(register select) pin of lcd. Port-D pin# 7 is connected to en(Enable) pin of 16×2 lcd. If you are newbie and have to idea about the working and pin configuration of lcd. Below is a good tutorial.

  • 16×2 lcd working pin configuration and internal structure.

​
Taking the upper tutorial will led you know how 16×2 lcd works & how to configure it.The circuit diagram of the project is given below. 

Interfacing 16x2 Lcd in 4-bit mode with pic16f877a microcontroller

Interfacing 16×2 Lcd in 4-bit mode with pic16f877a microcontroller

Interfacing 16×2 lcd in 4-bit mode with pic microcontroller- Project code

Coming to the code portion. Code is written in c language using Mp-lab ide by Microchip and high tech c compiler is used for compiling and generating hex code file. First header file htc.h is included. This header file must be included if you are using high tech c compiler for compilation of code. delay() function is used here for generating some delay. You can also use predefined delay function like __delay_us() etc.

Some functions and their working.
It is assumed that you know all about operators like (>>,& etc) and their functions. 

lcdcmd()

  • This function is sending high and low bytes of a command one by one to llcdcmd() function.
  • The statement llcdcmd(c>>4); is moving our high Byte (four high bits) to right and then sends them to llcdcmd function.
  • The statement llcdcmd(c); is sending our low Byte(four low bits) to llcdcmd function.

display()

  • This function is also working in the same way as lcdcmd(). The difference is it is sending data to ddisplay() function.

llcdcmd()
This function is separating four bits from our command and puts them on RB0,RB1,RB2,RB3 line and then sends them to lcd. The following instructions are separating four bits.
RB0=(value >> 0) & 0x01;
RB1=(value >> 1) & 0x01;
RB2=(value >> 2) & 0x01;
RB3=(value >> 3) & 0x01;

ddisplay()
This function is separating four bits from our 8-bit data and puts the 4-bit data on RB0,RB1,RB2,RB3 pins and then sends them to lcd. Following instructions are separating four bits.
RB0=(value >> 0) & 0x01;
RB1=(value >> 1) & 0x01;
RB2=(value >> 2) & 0x01;
RB3=(value >> 3) & 0x01;

If you dont know what is meant by commands and data send to 16×2 lcd here is a simple tutorial.

  • Difference between commands and data send to lcd.

In the main function i first called lcdint() function. This function is initializing our lcd. Refer to the data sheet of lcd if you dont know what is lcd initialization. Then i am sending data to 16×2 lcd which i want to display on lcd screen. I am displaying word “Microcontroller” on lcd display screen. 

Note: Although i declared the R/W pin in code (RD-5) but i am not using it. I made the lcd R/W pin directly ground. So now it remains always in write mode.
Download the project files and code with simulation. Simulation is made in proteaus and code is written using MP-lab ide and high tech c compiler. Please give us Your feed back on the project. If you have any questions regarding post or you dont understand any instruction please leave your comments below.

Filed Under: Microcontroller Projects, PIC Microcontroller

 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Designing Gate Driver Circuit and Switching Mechanism for Modified Sine Wave Inverter – (Part 9/17)
  • Completing Modified Sine Wave Inverter Design with Full Bridge Circuit and Step Up Transformer – (Part 10/17)
  • Designing an Offline UPS – Part (12 /17)
  • How to reduce Switching Time of a Relay – (Part 15/17)
  • Testing MOSFET – (Part 16/17)
  • Driving High Side MOSFET using Bootstrap Circuitry – (Part 17/17)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • Infineon offers DC-DC controller for full LED headlamps without a microcontroller
  • Vishay launches new high-precision, thin-film wraparound chip resistor
  • STMicroelectronics’ common-mode filters ensure signal integrity in serial interfaces
  • Renesas’ RA Family microcontrollers earn CAVP certification for cryptographic algorithms
  • MicroPython: Serial data communication in ESP8266 and ESP32 using UART

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd ldr led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics Research robot samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Simulation of resonator in HFSS
  • IRF450 MoSFET
  • HV Relays - Power Capacity
  • Switching frequency data not available
  • Voltage reference level - how to choose?

RSS Electro-Tech-Online.com Discussions

  • Adding Current Limit Feature to a Buck Converter
  • Background of Members Here
  • Passthrough charging-simple but impossible to achieve?
  • Opamp ciruit
  • DIY Mini 12v Router UPS malfunction
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering