LCD interfacing with 8051-8 bit mode


LCD stands for Liquid Crystal Display used to display numbers, strings and special characters as per the application. It is one of the widely used modules in embedded system.

Advantage of LCD over LEDs is its ability to display any number, alphabet, special characters and user defined symbol (at extra effort for programming) without increasing number of pins required to be connected with controller.

Let us start with basics of LCD. JHD 162A 16*2 LCD is widely used and easily available in market. It has total 16 pins which can be divided into three categories.

  1. Power Control pins: 1,2,3,15,16
  2. Control Pins: 4,5,6
  3. Data Pins: 7 to 14

Functions of pins are as follows.

Pin number Pin Name Function
1 Gnd Ground pin
2 Vcc Supply for LCD (4.7-5.3V)
3 Vee Contrast Control
4 RS Register select

0-Command Register

1-Data Register

5 R/W Read/Write

0-Write to LCD

1-Read from LCD

6 E Enable pin
7-14 DB0-DB7 Data pins
15 V+ Supply for back-light
16 Gnd Ground pin of back-light supply

LCD needs to be configured properly. To configure LCD, we must know the command structure which is as given below.

How to get details of command for LCD

Commands for LCD

This table must be understood properly for programming.

Well to reduce your efforts, generally required commands are short listed here.

LCD commands

Basic commands for LCD

Once you are aware of command structure, let’s move ahead.

LCD can operate in two modes.

  1. Command Mode: In this mode, RS pin is at logic 0 and the data on pin 7-14 represents the command which specifies the actions to be performed like clear LCD, go to home position, blink cursor etc.
  2. Data Mode: In this mode, RS pin is at logic 1 and data op pin 7-14 represents the data to be displayed on LCD.

While operating in data mode, we must keep in mind that the pattern to be displayed on dot matrix is already stored in internal memory of LCD. It is given below.

RAM Data of LCD Characters

Pattern stored in LCD RAM

So to display any character on LCD, we must provide ASCII value of that on data pins and LCD is smart enough to do the rest. To convert any number into ASCII, we must add 48 decimal value to it. So ASCII of 0 is 48, of 1 is 49 etc.

How many pins does the LCD need ?

As provided earlier, LCD has 8 data pins and 3 control pins. So it needs 11 pins  of controller for operation. But by smart thinking, we can reduce it to six. Let’s see how we can do that.

RW pin is for specifying read or write operation. Well if LCD is output device so where we have to read it ? Let’s understand this properly.

LCD is slow compared to micro-controllers and it needs time to perform the operations. Assume that controller is asking LCD to print data continuously. When LCD will receive command for that, it will start displaying on LCD but if controller will send another data and if LCD has not finished the task of displaying first data, the data received at later stage will be lost and will not be displayed on it.

To avoid this, LCD has one method known as busy flag. In this, MSB of data pins i.e. Pin 14 is used as busy flag. Once LCD will start performing and actions, it will raise pin 14 high to indicate that it is in busy state. Once the operation is completed, it will bring it down. Controller must check the status of pin 14 before sending further data or command to avoid any loss of data.

Here it is necessary to read pin 14 and RW has to be made high to read. We can save 1 controller pin here. Although LCD is slow, it is able to finish execution of command within few machine cycles. So after giving any command or data, if we provide delay of few microseconds, LCD will finish its task within that much time. So we don’t have to read status of pin14 and we can permanently ground it and save controller pin.

Another beautiful option available is to use LCD in 4-bit mode. Here the data will be sent in two nibbles instead of a complete byte at a time. In this, only higher nibble of data pins has been connected with controller and pins 7-10 of LCD are in NC state.

In this way, we need only 6 pins (4 bit data bus, RS and E) are required for LCD interfacing.

First we will interface LCD in 8 bit mode. Later on we will proceed for 4 bit mode.

LCD interfacing with 8051

LCD interfacing with 8051 (8 bit mode)

Please log in to view code.

You may also like...

Leave a Reply

Specify Facebook App ID and Secret in Super Socializer > Social Login section in admin panel for Facebook Login to work

Specify LinkedIn Client ID and Secret in Super Socializer > Social Login section in admin panel for LinkedIn Login to work

Your email address will not be published. Required fields are marked *