Lecture Topic 1.3.3
Lecture Topic 1.3.3
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
is also bigger and heavier. All of us have seen an LCD, but no one knows the exact working of it. Let us take a
look at the working of an LCD.
Here we are using alphanumeric LCD 16×2. A 16×2 LCD display is a 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 are: 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 a 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 the 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.
16×2 LCD Pin Diagram
Pin Description
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
13 DB6
14 DB7
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 a 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 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
Interfacing LCD with Microcontroller – CIRCUIT DIAGRAM
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 to Port 2 (P2)
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.
void dat(unsigned char b)
{
lcd_data=b;
rs=1; rw=0;
en=1;
lcd_delay(); en=0;
}
Send String
We cannot send more than 8 bits at the same time. Because data lines are only having 8 bits. So how
we can send string? Any guess? Yeah, you are correct. We have to send the string by
character. See this code.
void lcd_init()
{
cmd(0x38);
cmd(0x0e);
cmd(0x01);
cmd(0x06);
cmd(0x0c);
cmd(0x80);
}
LCD Interfacing with 8051 – FULL CODE
#include <reg51.h>
#define lcd_data P2
sbit rs=P0^0;
sbit rw=P0^1;
sbit en=P0^2;
void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
void lcd_delay();
void lcd_init()
{
cmd(0x38); cmd(0x0e);
cmd(0x01); cmd(0x06);
cmd(0x0c); cmd(0x80);
}
void cmd(unsigned char a)
{
lcd_data=a;
rs=0; rw=0;
en=1;
lcd_delay();
en=0;
}
void dat(unsigned char b)
{
lcd_data=b;
rs=1; rw=0;
en=1;
lcd_delay(); en=0;
}
void show(unsigned char *s)
{
while(*s) {
dat(*s++);
}
}
void lcd_delay()
{
unsigned int lcd_delay;
for(lcd_delay=0;lcd_delay<=6000;lcd_delay++);
}
int main()
{
unsigned int j;
lcd_init();
while(1) {
cmd(0x80);
show(" Welcome To ");
cmd(0xc0);
show(" EMBETRONICX.COM");
for(j=0; j<30000; j++);
cmd(0x01);
for(j=0; j<30000; j++);
}
}
LCD Interfacing with 8051 – Working
A. TEXTBOOKS/REFERENCE BOOKS
i. TEXTBOOKS
T1 Kenneth Ayala, The 8051 Microcontroller, Cengage Learning India, 3rd Edition, Nov 2007
T2 B. Kanta Rao, Embedded Systems, PHI, 1st Edition, January 2011
T3 John Boxall, Arduino Workshop: A Hands-On Introduction with 65 Projects, No Starch Press, 1st
Edition, May 2013
ii.REFERENCE BOOKS
R1 B. Ram, Fundamentals of Microprocessors and Microcontrollers, DRP, 8th Edition, Nov 2021
R2 Massimo Banzi, Getting Started with Arduino, Make Community LLC, 3rd Edition, Jan 2015
R3 Jeremy Blum, Exploring Arduino: Tools and Techniques for Engineering Wizardry, Wiley, 1st Edition,
Aug 2013
B. Video Links:
1. https://www.youtube.com/watch?v=PDnPSiblELg
2. https://www.youtube.com/watch?v=pihAdSek7oM
3. https://youtu.be/aJYrjSLdAyg?si=XoIglSllQ3AQvFGd