INTERFACING OF LCD WITH 89C51



Liquid crystal display is very commonly used electronic display module and having a wide range of applications such as calculators, laptops, mobile phones etc. 16×2 character lcd display is very basic module which is commonly used in electronics devices and projects. It can display 2 lines of 16 characters.

Pinout and Pin Description of 16x2 LCD Module


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-

RS(Register select)

A 16X2 LCD has two registers, namely, command and data. The register select is used to switch from one register to other. RS=0 for command register, whereas RS=1 for data register.
Command Register: 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. Processing for commands happen in the command register.
Data Register:  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. When we send data to LCD it goes to the data register and is processed there. When RS=1, data register is selected.
Important command codes for LCD
Code (Hex)
working of lcd commands
1
Clear display screen
2
Return home
4
Decrement cursor (shift cursor to left)
6
Increment cursor (shift cursor to right)
5
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 beginning to 1st line
C0
Force cursor to beginning to 2nd line
90
Force cursor to beginning to 3rd line
D0
Force cursor to beginning to 4th line
38
2 lines and 5×7 matrix (8-bit mode)
28
2 lines and 5×7 matrix (4-bit mode)
n
Next line
t
Tab
r
enter


Program 1: To display "Hai" in LCD 
code:
#include<reg51.h>
sbit rs=P2^0;
sbit en=P2^1;
void cmd(int);
void data1(char);
void lcd();
void delay();
void display(char *);
void main()
{
 lcd();
 display("Hai");
}
void lcd()
{
 cmd(0x38);
 cmd(0x0e);
 cmd(0x01);
 cmd(0x06);
 cmd(0x80);
}
void cmd(int a)
{
 P3=a;
 rs=0;
 en=1;
 delay();
 en=0;
}
void data1(char x)
{
 P3=x;
 rs=1;
 en=1;
 delay();
 en=0;
}
void display(char *s)
{
 while(*s!='\0')
 {
  data1(*s);
  s++;
 }
}
void delay()
{
 int i,j;
 for(i=0;i<100;i++)
 for(j=0;j<100;j++);
}


simulation:



Download code Here:

Comments

Popular posts from this blog

INTERFACING SEVEN SEGMENT DISPLAY WITH 89c51

POINTERS