Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Contributions
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
  • What Is
  • Forums
    • EG Forum Archive
    • EDABoard.com
    • Electro-Tech-Online
  • 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
  • News
    • EE Design News
    • DIY Reviews
    • Guest Post
    • Sponsored Content
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Classrooms
    • Grid Infrastructure
    • Aerospace & Defense
    • Building Automation
    • Power Delivery
    • Factory Automation
    • Motor Drives
    • Medical Technology
  • Video

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

July 28, 2019 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.

Related Articles Read More >

Microcontroller Project: STM32 low power modes analysis
Decimal counter designed in vhdl
Display custom urdu language characters on 16×2 lcd using pic16f877a microcontroller
Arduino home security system using Sim900 Gsm module, Pir motion detector and magnetic door contact switch

Stay Up To Date

Newsletter Signup

Popular Posts

Serial data received from pc and displayed on 16×2 lcd using 8051(89c51,89c52) microcontroller UART port
NxN(8×1 , 8×2 , 10×2 , 16×1 , 16×2 , 16×4 , 20×2 , 20×4 ,24×2 , 30×2 , 32×2 , 40×2) Character lcd working, Pinout and description
Displaying ASCII Characters on 16×2 lcd using 8051(89c51,89c52) Microcontroller
How to generate and display self made Custom characters on 16×2 lcd

EE Training Center Classrooms

“ee

“ee

Recent Articles

  • RPi Python Programming 05 – Introduction to Python
  • Renesas’s RL78 prototyping board simplifies IoT endpoint equipment
  • Google co-founders step down from parent company
  • RPi Python programming 04 – Setting up Raspberry Pi Linux computer
  • NXP broadens the LPC5500 Arm Cortex -M33 microcontroller series
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 © 2019 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
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Contributions
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
  • What Is
  • Forums
    • EG Forum Archive
    • EDABoard.com
    • Electro-Tech-Online
  • 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
  • News
    • EE Design News
    • DIY Reviews
    • Guest Post
    • Sponsored Content
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Classrooms
    • Grid Infrastructure
    • Aerospace & Defense
    • Building Automation
    • Power Delivery
    • Factory Automation
    • Motor Drives
    • Medical Technology
  • Video