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

LCD DISPLAY

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

a 8051 - LCD Interfacing

Pin Description

 Pin No

Function

Name

1

Ground (0V)

Ground

2

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

Vcc

3

Contrast adjustment; through a variable resistor

VEE

4

Selects command register when low; and data register when high

Register Select

5

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

Read/write

6

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

Enable

7

8-bit data pins

DB0

8

DB1

9

DB2

10

DB3

11

DB4

12

DB5

13

DB6

14

DB7

15

Backlight VCC (5V)

Led+

16

Backlight Ground (0V)

Led-

 

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.

LCD COMMANDS

dd 8051 - LCD Interfacing

Now let’s move to programming.

CIRCUIT DIAGRAM

dd 8051 - LCD Interfacing

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.

FULL CODE

OUTPUT

output 8051 - LCD Interfacing

 

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.

Tasks

  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.

Download our new Android app. You can learn all Embedded Tutorials from your Android Phone easily.

Click Here to Download App!