INTERFACING LCD WITH 8051 MIROCONTROLLER With Code

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code


Menu 

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.

Table of Contents 

16×2 LCD:
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:

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 1/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

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.

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 2/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

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


https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 3/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

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)

TO SENDDATA:

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.
https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 4/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

PROTEUS SIMULATION of lcd interfacing with 8051 microcontroller:

Video simulation of lcd interfacing with 8051


microcontroller

lcd interfacing with 8051 microcontroller

CODE of lcd interfacing with 8051 microcontroller

#include<reg51.h>

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 5/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

voidlcd_init(void);

voidwritecmd(int);

voidwritedata(char);

void delay(int);

sbit RS = P1^0;

sbit E  = P1^1;

sbit led = P1^2;

inti=0;

void main()

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;

lcd_init();

writedata('W');                               

delay(5000000);

writedata('e');                                

delay(5000000);

writedata('l');  

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 6/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

delay(5000000);                             

writedata('c');

delay(5000000);                                                                 

writedata('o');

delay(5000000);                                

writedata('m');

delay(5000000);                                

writedata('e');

delay(5000000);

writedata(' ');                               

delay(5000000);

writedata('T');                               

delay(5000000);

writedata('o');

delay(5000000);

writecmd(0x01);                      //clear display

writedata('w');                                

writedata('w');                              

writedata('w');  

writedata('.');

writedata('m');                         

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 7/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

writedata('i');

writedata('c'); 

writedata('r');

writedata('o');

writedata('c');                         

writedata('o');

writedata('n'); 

writedata('t');

writedata('r');

writedata('o');

writedata('l');

writecmd(0xc0);                      //enter in second row

writedata('l');

writedata('e');

writedata('r');

writedata('s');                         

writedata('l');

writedata('a'); 

writedata('b');

writedata('.');

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 8/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

writedata('c');                         

writedata('o');

writedata('m');

delay(5000000);

delay(5000000);

delay(5000000);

delay(5000000);

void lcd_init(void)

writecmd(0x38);    //for 8 bit mode

writecmd(0x0C);    //display on, cursor off

writecmd(0x01);    //clear display

writecmd(0x80);    //force cursor to beginning of 1st line

void writedata(char t)    //data function

   RS = 1;            

   P2 = t;                       //Data transfer

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 9/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

E  = 1;            

delay(150);

E  = 0;           

delay(150);

voidwritecmd(int z)     //command function

   RS = 0;            

   P2 = z;                      //Data transfer

E  = 1;            

delay(150);

E  = 0;            

delay(150);

void delay(int a)          //Delay function

inti;

for(i=0;i<a;i++);   }

 8051 microcontroller tutorials and projects


https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 10/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

Subscribe to Blog via Email


Enter your email address to subscribe to this blog and receive notifications of
new posts by email.

Email Address

SUBSCRIBE

2 thoughts on “INTERFACING LCD WITH 8051


MIROCONTROLLER with code”

Getachew Nega
February 22, 2017 at 5:34 pm

Thanks for the invaluable information. But I have a question for you, how
much second is the delay given by delay(5000000) and delay(150)?
Thanks in advance for your feedback!

Reply

fasil
December 27, 2020 at 11:58 pm

could you send me interfacing pir.gsm.buzzer with 8051 microcontroller

Reply

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 11/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

Leave a Comment

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

POST COMMENT

8051 Tutorials
Getting Started 8051
LED blinking 8051
LCD Interfacing 8051
Keypad Interfacing
DC Motor Interfacing

Stepper Motor Interfacing


Servo Motor Interfacing
https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 12/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

8051 Timers
External Interrupts 8051
ADC0804 Interfacing

EEPROM interfacing
Optocoupler interfacing
serial communication 8051

Subscribe to Blog via Email

Email Address

SUBSCRIBE

PCB Assembly Services

Categories
https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 13/14
9/5/21, 10:25 AM INTERFACING LCD WITH 8051 MIROCONTROLLER with code

Select Category

Recent Posts
ESP32 Server Client Wi-Fi Communication using Arduino IDE

ESP32 Web Server Hosting Files from Micro SD card (Arduino IDE)

ESP32 ESP-NOW Two way Communication (Arduino IDE)

OLED Display Interfacing with ESP32 – Display Text, Draw shapes and Images

ESP32 Data Logging Temperature Sensor Readings to microSD card (Arduino IDE)

Copyright © 2013-2021
Microcontrollerslab.com All Rights Reserved

https://microcontrollerslab.com/interfacing-lcd-8051-mirocontroller-code/ 14/14

You might also like