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

Interface 16x2 LCD with

8051 in 8-bit mode


Prof. Sunil MP
Assistant Professor
Department of Electronics and Communication Engineering
School of Electrical Engineering
JAIN(Deemed -to-be University
1
• As per the name the 16x2 has 2 lines with 16 characters on each lines.
• It supports all the ASCII characters and is basically used for displaying
the alpha numeric characters.
• Here each character is displayed in a matrix of 5x7 pixels.
• Apart from alpha numeric characters it also provides the provision to
display the custom characters by creating the pattern.
• Scope of this topic is to show how to display the alpha numeric
characters on LCD, Generating and displaying the custom characters.

2
3
An LCD screen consists of two lines each containing 16 characters. Each
character consists of 5x7 or 5x11 dot matrix. the most commonly used
display, i.e. the 5x7 with one space 5x8 character display.

4
5
Power IO LINES ---- GND, VCC, VEE, LEDA, LEDK

Control IO LINES ---- RS, RW, EN

DATA IO LINES ---- D0, D1, D2, D3, D4, D5, D6, D7

6
Display contrast depends on the power supply voltage and whether messages are
displayed. For this reason, varying voltage 0-Vdd is applied on the pin marked as
VEE. Trimmer potentiometer is usually used for that purpose.

7
Pin Number Symbol Pin Function
1 VSS Ground
2 VCC +5v
3 VEE Contrast adjustment (VO)
4 RS Register Select---0:Command, 1: Data
5 R/W Read/Write, R/W=0 Write & R/W=1 Read
6 EN Enable-Falling edge triggered
7 D0 Data Bit 0 (Not used in 4-bit operation)
8 D1 Data Bit 1 (Not used in 4-bit operation)
9 D2 Data Bit 2 (Not used in 4-bit operation)
10 D3 Data Bit 3 (Not used in 4-bit operation)
11 D4 Data Bit 4
12 D5 Data Bit 5
13 D6 Data Bit 6
14 D7 Data Bit 7/Busy Flag
15 A/LED+ Back-light Anode(+)
16 K/LED- Back-Light Cathode(-) 8
• Apart from the voltage supply connections the important pins from the
programming perspective are the data lines(8-bit Data bus), Register select,
Read/Write and Enable pin.

Data Bus:
• As shown in the above figure and table, an alpha numeric lcd has a 8-bit data bus
referenced as D0-D7.
• As it is a 8-bit data bus, we can send the data/cmd to LCD in bytes.
• It also provides the provision to send the the data/cmd in chunks of 4-bit, which
is used when there are limited number of GPIO lines on the microcontroller.

9
• Register Select(RS): The LCD has two register namely a Data register and
Command register.
• Any data that needs to be displayed on the LCD has to be written to the data
register of LCD.
• Command can be issued to LCD by writing it to Command register of LCD.
• This signal is used to differentiate the data/cmd received by the LCD.

• If the RS signal is LOW then the LCD interprets the 8-bit info as Command and
writes it Command register and performs the action as per the command.
• If the RS signal is HIGH then the LCD interprets the 8-bit info as data and copies
it to data register.
• After that the LCD decodes the data for generating the 5x7 pattern and finally
displays on the LCD.
RS MODE
0 Command register
1 data register 10
• Read/Write(RW): This signal is used to write the data/cmd to LCD and
reads the busy flag of LCD.
• For write operation the RW should be LOW(0) and RW OPERATION
0 WRITE
• for read operation the R/W should be HIGH(1).
1 READ
Enable(EN): This pin is used to send the enable trigger to LCD.
• After sending the data/cmd, Selecting the data/cmd register, Selecting the
Write operation.
• A HIGH-to-LOW pulse has to be send on this enable pin which will latch the
info into the LCD register and triggers the LCD to act accordingly.

11
CodeHex) Command to LCD Instruction Register

1 Clear display screen


2 Return Home
4 Decrement cursor (shift cursor to left)
5 Increment cursor (shift cursor to right)
6 shift display right
7 shift display left
8 Display off, cursor off
A Display off, cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to the beginning of 1st line
C0 Force cursor to the beginning of 2nd line
12
38 2 lines and 5 x 7 matrix
13
CGROM Memory
CGROM memory contains the default character map with all characters that can be
displayed on the screen. Each character is assigned to one memory location.

14
RS RW EN D0 D1 D2 D3 D4 D5 D6 D7

P3.7 P3.6 P3.5 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7

15
#include<reg51.h>
sbit rs = P3^7; //register select pin
sbit rw = P3^6; // read write pin
sbit en = P3^5; //enable pin

void delay(unsigned int msec) // Function to provide time delay in msec.


{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}

16
void lcdcmd(unsigned char x) //Function to send command to LCD
{
P2 = x;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
} void lcddata(unsigned char y) //Function to send data to LCD
{
P2 =y;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
}
17
void main()
{
P2=0X00;
rs=0; rw=0; en=0;
While(1)
{
lcdcmd(0x38); // for using 8-bit 2 row mode of LCD
delay(100);
lcdcmd(0x0E); // turn display ON, for cursor blinking
delay(100);
lcdcmd(0x01); //clear screen
delay(100);
lcdcmd(0x06); //display ON
delay(100);
lcdcmd(0x86); // bring cursor to position 6 of line 1
delay(100);
lcddata(‘J');
lcddata(‘A');
lcddata(‘I');
lcddata(‘N');
18
}}

You might also like