INTERFACING LCD WITH 8051 MIROCONTROLLER with code
INTERFACING LCD WITH 8051 MIROCONTROLLER: In this article you will learn how to interface lcd with 8051 microcontroller. It is not very hard for interfacing lcd with 8051 microcontroller when you already know how to use kiel for programming of 8051 and how to used input output ports of 8051 microcontroller. LCD is used for displaying alphabets, numbers or some messages etc. We already learnt about the use of LCD using PIC microcontroller in previous article. Now in this tutorial we will study how to interface LCD with 8051 microcontroller. 8051 is basic level of using controllers, so it’s a bit difficult as compared to PIC microcontroller and LCD interfacing code is also changed here. you can also scroll text on lcd as we did in pic microcontroller tutorial.
- 1 16×2 LCD:
- 2 LCD PIN DISCRIPTION
- 3 LCD interfacing WORKING
- 4 LCD INTERFACING WITH 8051 MICROCONTROLLER
- 5 TO INITIALIZE LCD for interfacing with 8051 microcontroller
- 6 Video simulation of lcd interfacing with 8051 microcontroller
- 7 CODE of lcd interfacing with 8051 microcontroller
We can use any type of LCD like 16×2, 8×1, 16×4, 8×2, 16×1, 20×1, 20×2 etc. Here we will use 16×2 Liquid Crystal Display. It can display 32 characters at a time in two rows. LM016L is a 16×2 LCD module.There are 16 pins in this LCD module, the pin configuration us given below:
LCD PIN DIAGRAM:
LCD PIN DISCRIPTION
Pin 1 GND (0v)
Pin 2 Vcc (5v)
Pin 3 VEE (contrast adjustment through variable resistor)
Pin 4 RS (command register when low, data register when high)
Pin 5 R/W (high for read from register, low for write to the register)
Pin 6 EN (sends data to data pins when high to low pulse is given)
Pin 7-14 DB0-DB7 (8-bit data pins)
Pin 15 LED+ (backlight, Vcc 5v)
Pin 16 LED- (backlight, GND 0v)
LCD interfacing WORKING
EN pin is for enabling the module. A high to low transition at this pin will enable the LCD module. ThisLM016L has two built in registers namely:
- Data register
- Command register
Data register: It is for placing the data which is to be displayed. Data can be any character, alphabet or number.High logic at the RS pin will select the data register. By making RS pin high and putting data in the 8 bit data line (DB0 to DB7), the LCD module will recognize it as a data to be displayed.
Command register:It is for placing the commands. There is a set of commands for LCD to perform specific tasks. Low logic at the RS pin will select the command register.By making RS pin low and putting data on the data line, the LCD module will recognize it as a command.Some of the instructions/commands are given below:
Code (in Hex) Working of LCD commands
0x01 Clear displays
0x02 return home
0x06 for entry mode
0x80 Force cursor to beginning of 1st line
0xC0 Force cursor to beginning of 2nd line
0x90 Force cursor to beginning of 3rd line
0xD0 Force cursor to beginning of 4th line
0x08 Display off, cursor off
0x0E Display on, cursor on
0x0C Display on, cursor off
0x0F Display on, cursor blinking
0x10 Shift cursor position to left
0x14 Shift cursor position to right
0x38 2 lines and 5×7 matrix (8-bit mode)
0x28 2 lines and 5×7 matrix (4-bit mode)
R/W pin is for selecting between read and write modes. High level at this pin enables read mode and low level at this pin enables write mode.
DB0 to DB7 are the data pins. The data to be displayed and the commands are placed on these pins.
For glowing backlight LED, LED+ (anode of back light LED)is connected to Vcc through a suitable series current limiting resistor (for contrast adjustment). LED-(cathode of the back light LED) is connected to ground.
LCD INTERFACING WITH 8051 MICROCONTROLLER
This LCD can be operated in 4-bit mode (using only 4 data lines) or 8-bit mode (using all 8 data lines). Here we will useit in 8-bit mode. First of all LCD is initialized and then it can be used for sending data and commands. Reset and Enable of LCD is connected to port 1 of 8051 microcontroller. Data lines of LCD are connected to port 2 of 8051 microcontroller. R/W is connected to ground since we have to just write data and command (not read operation). This gives a little ease so that we don’t need to make this pin low in the code.
TO INITIALIZE LCD for interfacing with 8051 microcontroller
To initialize LCD with 8051 microcontroller, following instruction are to be executed:
0x38 (is used for 8-bit data initialization)
0x0C (display on, cursor off)
0x01 (for clearing screen)
0x80 (force cursor to beginning of 1st line)
For displaying any character whether it is number, alphabet or character, following steps should be follow:
- For display data, register select (RS pin) should be high, RS = 1.
- Place data byte on the data register.
- Pulse the Enable pin (EN pin) from high to low.
- Configure the R/W to write mode. For write mode,R/W = 0.
- Repeat above steps for sending another data.
TO SEND COMMAND:
To instruct LCD for performing specific task for example displaying character in second row instead of one, following steps should be taken:
- For command mode, register select (RS pin) should be low, RS = 0.
- Place data byte on the command register.
- Pulse the Enable pin (EN pin) from high to low.
- Read/Write should be low (write mode), R/W = 0.
- Repeat above steps for sending another command.
PROTEUS SIMULATION of lcd interfacing with 8051 microcontroller:
Video simulation of lcd interfacing with 8051 microcontroller
CODE of lcd interfacing with 8051 microcontroller
sbit RS = P1^0;
sbit E = P1^1;
sbit led = P1^2;
P0 = 0x00; //not used
P1 = 0x00; //output port for setting RS and EN
P2 = 0x00; //used as data output port
P3 = 0x00; //not used
led = 1;
writecmd(0x01); //clear display
Current Project / Post can also be found using:
- Lcd displays programs with pic microcontroller pdf