8051 – LCD Interfacing

Hi All… Our last tutorial we were seen How to Interface LED and Switch. So today we are going to see LCD interfacing with 8051 Microcontroller. Before Interfacing we should know something about that module. Let’s start.

LCD interfacing with 8051 Microcontroller


We always use devices made up of Liquid Crystal Displays (LCDs) like computers, digital watches and also DVD and CD players. They have become very common and have taken a giant leap in the screen industry by clearly replacing the use of Cathode Ray Tubes (CRT). CRT draws more power than LCD and are also bigger and heavier. All of us have seen a LCD, but no one knows the exact working of it. Let us take a look at the working of a LCD.

Here we are using alphanumeric LCD 16×2. A 16×2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on.

A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5×7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

Pin Diagram

Pin Description

 Pin No




Ground (0V)



Supply voltage; 5V (4.7V – 5.3V)



Contrast adjustment; through a variable resistor



Selects command register when low; and data register when high

Register Select


Low to write to the register; High to read from the register



Sends data to data pins when a high to low pulse is given



8-bit data pins

















Backlight VCC (5V)



Backlight Ground (0V)



The LCD display module requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. If a 4-bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for the data bus). If an 8-bit data bus is used the LCD will require a total of 11 data lines (3 control lines plus the 8 lines for the data bus).

The three control lines are referred to as EN, RS, and RW.

The EN line is called “Enable.” This control line is used to tell the LCD that you are sending it data. To send data to the LCD, your program should make sure this line is low (0) and then set the other two control lines and/or put data on the data bus. When the other lines are completely ready, bring EN high (1) and wait for the minimum amount of time required by the LCD datasheet (this varies from LCD to LCD), and end by bringing it low (0) again.

The RS line is the “Register Select” line. When RS is low (0), the data is to be treated as a command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1), the data being sent is text data which should be displayed on the screen. For example, to display the letter “T” on the screen you would set RS high.

The RW line is the “Read/Write” control line. When RW is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or reading) the LCD. Only one instruction (“Get LCD status”) is a read command. All others are write commands–so RW will almost always be low.

Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation selected by the user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2, DB3, DB4, DB5, DB6, and DB7.


Now let’s move to programming.


RS is connected to Port 0.0 (P0.0)

RW is connected to Port 0.1 (P0.1)

EN is connected to Port 0.2 (P0.2)

Data lines are connected into Port 2 (P2)

Programming the LCD

Send Data

To send data on the LCD, data is first written to the data pins with R/W = 0 (to specify the write operation) and RS = 1 (to select the data register). A high to low pulse is given at EN pin when data is sent. Each write operation is performed on the positive edge of the Enable signal.

Send String

We cannot send more than 8 bits at the same time. Because data lines are only having 8bits. So how we can send string? Any guess? Yeah you are correct. We have to send the string by character. See this code.

Send Command

To send a command on the LCD, a particular command is first specified to the data pins with R/W = 0 (to specify the write operation) and RS = 0 (to select the command register). A high to low pulse is given at EN pin when data is sent.

LCD Initializing

To initialize the LCD we have to use certain commands.


Now see the full code below.



[ Image : Output ]

That’s all guys. But this is just a basic. Here i haven’t used any hardware. I’m simply using Proteus. But if you use hardware it should work. But you should give proper connections. Here if you want try something please try these exercises given below.


  1. Scroll “EMBETRONICX” in the first row of LCD.
  2. When i press switch it should display the switch status weather ON or OFF. You can connect switch any pin in 8051.
0 0 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newest Most Voted
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
%d bloggers like this: