Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
    • What Is
    • News
      • EE Design News
      • DIY Reviews
      • Guest Post
      • Sponsored Content
  • 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
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Difference between Commands and Data Send to 16×2 Character Lcd

April 13, 2019 By EG Projects

All the character lcd’s of any size 8×1, 8×2 , 10×2 , 16×1 , 16×2 , 16×4 , 20×2 , 20×4 , 24×2 , 30×2 , 32×2 , 40×2, 40×4 contains HD44780 lcd controller in them. If not HD4478 then a controller compatible to it. HD44780 is responsible to accept data from external controller, verify data if correct then recognize if its a data to display on lcd screen or its a command to set lcd parameters. HD44780 has fixed and countable commands to initialize character lcd.

Valid statements accepted by HD44780 Lcd controller

The only thing we must be concerned of is what character/data we can send to lcd?size of data and data type. Well we can send two types of statements to lcd. One is command and the other one is data. Since all the character lcd’s provide 8 data lines for communication so both the command and data size must not exceed 8 bits.  

Valid Data accepted by HD44780 lcd controller

we can send alphabets upper and lower case, some Chinese and Japanese language characters and numeric characters to display them to lcd. We can only display the characters shown below on our lcd screen. Below characters are defined in the flash of hd44780 controller.   
HD44780 lcd controller supported Characters

HD44780 lcd controller supported Characters

Special characters accepted by Hd44780 ccontroller

Hd44780 reserves a space of 64 bytes in its ROM(read only memory). We can generate special 8 custom characters in this ram and invoke them to display on lcd when desired. The size of individual custom character is a 5×8 matrix. Where 5 represents number of coulombs and 8 represents number of rows. Custom characters are independent of shape we can make a shape of our desired look in 5×8 dot matrix.   
16x2 lcd custom 5x8 character generator

16×2 lcd custom 5×8 character generator

Character lcd can display characters in 5×8 and 5×10 dimension only(In the above picture from datasheet of HD44780 controller you can find some characters of size 5×10). If you want to display characters in any other dimension than better use a graphical lcd. Graphical lcd’s are some what independent of the size constraint. For example a 128×64 size of graphical lcd has 64 rows and 128 coulombs. Each row and coulomb intersection represents a dot or pixel. Hencce we can display character of our size on graphical lcd. But we can’t display character bigger than the size of character lcd. 
Some of the tutorial/projects related to this tutorial are  

  • How to Use Character Lcd in 4-bit Mode ?
  • Lcd in 4-bit mode with Pic Microcontroller
  • Lcd in 4-bit mode with Arduino

Valid commands accepted by HD44780 lcd controller

Any embedded electronic device can not work with out initialization and settings. So HD44780 also has a set of pre-defined commands. Which sets the lcd parameters. Like back light on/off, scroll characters, move forward/backward display scroll bar etc. The former parameters are all set by commands. Every parameter has its own fixed command.     
16x2-lcd-hd44780-controller-command-set

16×2-lcd-hd44780-controller-command-set

Their are two registers in every character lcd Data and Command. When we want to send data we have to send it to Data register of lcd. When we want to send commands we have to send it to command register of 16×2 lcd. To switch between data and command register of lcd we only need to control one pin on lcd(I will talk about it later in tutorial). 

Now how to send data and commands/data to lcd? Below is a small code which can help you to understand the difference between commands and data send to lcd.

The scenario is that i have microcontroller. Lcd rs(register select) ,rw(read/write) ,en(enable) pins are connected to pins 5 , 6 , 7 of  microcontroller.

sbit rs = P3^7;             //External controller Pin    
sbit rw = P3^5;            
//External controller Pin               
sbit en = P3^6;            //External controller Pin 

  • lcdcmd() function is sending commands to lcd.
  • lcddata() function  is sending data to lcd.

Their is only just difference between the function names and the rs(register select) pin statement. In command function it is 0. In data function it is 1. This is the main difference which you have to understand read the text below very carefully.

Commands and Data send to Lcd

Command and Data send to Lcd Difference with example

 lcd commands

void lcdcmd(unsigned char value)
  {
    P1 = value;      
    rs = 0;
    rw = 0;
    en = 1;            
    MSDelay(50);
    en = 0;
MSDelay(50);
  }

when we call the lcdcmd() function we put our command in the function such as lcdcmd(0x38). 0x38 is command its description is below. This is an 8-bit command. Its equivalent binary is 01011000.
​
This 8-bit value is send to Port 1 . Port 1 is connected to eight data pins of lcd D0-D7.

when rs(register set) is zero 0 it means that we selected command register and  their is command on the data pins of lcd.

 lcd data

void lcddata(unsigned char value)
  {
    P1 = value;  
    rs = 1;
    rw = 0;
    en = 1;          
    MSDelay(50);
    en = 0;
    MSDelay(50);

  }

when we call the lcddata() function we put our data in the function such as lcddata(‘a’). ‘a’ is a character. This is also an 8-bit data.

​
This 8-bit value is send to Port 1 . Port 1 is connected to eight data pins of lcd D0-D7.

when rs(register set) is one 1 it means that we selected data register and their is data on data pins..

Then comes the stroke pin en(enable). Enable pin provides a push/pulse signal to display what is on data lines of lcd. Initially it is zero but when we put data on data pins and initialize rs 0(for command) or 1(for data) and initialize rw with 1(to read from lcd) or 0(to write to lcd). Then we made en pin high 1. This provides lcd a pulse stroke signal which prints the data or command what ever is present on data pins of lcd. After providing stroke wait for some micro seconds to fully provide enough pulse which can push/move data and can display it on lcd screen. After providing stroke again we must brought en(enable) back to low in order to make it ready to give another pulse to lcd to display another character.

Related Articles Read More >

A Bluetooth-controlled datalogger robot
touch bell push
How to design a touchless bell push using Arduino
SMS-enabled scrolling message board using Arduino
Interfacing stepper motor with 8051(89c51,89c52 ) microcontroller

Featured Tutorials

  • Screenshot of Raspbian OS on Raspberry Pi RPi Python Programming 03: Raspberry Pi as Linux System
  • Raspberry Pi Models RPI Python Programming 02: Raspberry Pi Models
  • Raspberry Pi 4 RPi Python Programming 01: Introduction to Raspberry Pi 4
  • RPi Python Programming 05: Introduction to Python
  • RPi Python programming 04 RPi Python programming 04: Setting up Raspberry Pi Linux computer
  • Python Basics RPi Python Programming 06: Python basics

Stay Up To Date

Newsletter Signup

EE Training Center Classrooms

“ee

“ee

“ee

“ee

Recent Articles

  • Arduino’s L293D motor driver shield guide
  • NXP launches its first Wi-Fi 6E Tri-Band system-on-chip
  • Nexperia launches industry’s first 80 V RETs for high-voltage bus circuits
  • TDK releases low-profile medical sensors
  • Getting started with Raspberry Pi
...

RSS EDABOARD.com Discussions

  • What the best way to store data of size ( 90,000 * 32) bit (taken from a text file) using VHDL?
  • HSPICE Simulation refuses to match the Spectre Simulation
  • How to draw a helical coil around a rectangular core in Maxwell?
  • Where can I find the description of each layer in TSMC's pdk?
  • Same geometry but slightly different results

RSS Electro-Tech-Online.com Discussions

  • Where has the fun gone?
  • Where can I find a pole pig?
  • Voltage based relay
  • XC8 v2.31 Help: Integer Arithmetic With Numbers Larger Than 32 Bits?
  • new to Ardunio but trying to compile
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 © 2021 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
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
    • What Is
    • News
      • EE Design News
      • DIY Reviews
      • Guest Post
      • Sponsored Content
  • 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
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering