Professional Documents
Culture Documents
Microcontroller
Liquid Crystal Display LCD
• 16x2 LCD means that there are two rows in which 16 characters can be
displayed per line, and each character takes 5X7 matrix space on LCD.
• 16 pins in the LCD module
• Ability to display number character and graphics
• Ease of programming
• Decline prices
1 VSS Ground pin
2 VCC Power supply pin of 5V
3 VEE Used for adjusting the contrast commonly attached to
the potentiometer.
4 RS is the register select pin used to write display data to the
LCD (characters), this pin has to be high when writing the data
to the LCD. During the initializing sequence and other
commands this pin should low.
5 R/W Reading and writing data to the LCD for reading the data
R/W pin should be high (R/W=1) to write the data to LCD R/W
pin should be low (R/W=0)
6 E Enable pin is for starting or enabling the module. A high to
low pulse of about 450ns pulse is given to this pin.
DB0-DB7 Data pins for giving data(normal data like numbers
characters or command data) which is meant to be displayed
15 LED+ Back light of the LCD which should be connected to
Vcc
16 LED- Back light of LCD which should be connected to
ground.
Command Instructions
•C0 Force cursor to beginning of second line
•Hex Code Command to LCD Instruction Register
•0F LCD ON, cursor ON •38 2 lines and 5×7 matrix
•01 Clear display screen
•02 Return home •83 Cursor line 1 position 3
•04 Decrement cursor (shift cursor to left) •3C Activate second line
•06 Increment cursor (shift cursor to right) •08 Display OFF, cursor OFF
•05 Shift display right •C1 Jump to second line, position 1
•07 Shift display left •OC Display ON, cursor OFF
•0E Display ON, cursor blinking •C1 Jump to second line, position 1
•80 Force cursor to beginning of first line •C2 Jump to second line, position 2
Programming LCD to 8051
• Programming steps:
• STEP1: Initialization of LCD.
• STEP2: Sending command to LCD.
• STEP3: Writing the data to LCD.
• Initializing LCD:
• 0×38 is used for 8-bit data initialization.
• 0xFH for making LCD on and initializing the cursor.
• 0X6H for incrementing the cursor which will help to display another character in the LCD
• 0x1H for clearing the LCD
• To send a command to the LCD:
• E=1; enable pin should be high
• RS=0; Register select should be low
• R/W=1; Read/Write pin should be high
• Writing the data to LCD:
• E=1; enable pin should be high
• RS=1; Register select should be high
• R/W=0; Read/Write pin should be low.
Program for LCD Interfacing with 8051 Microcontroller
void lcd_data(unsigned char disp_data) //Function to
#include<reg51.h> send display data to LCD
#define display_port P2 //Data pins connected to { display_port = disp_data;
port 2 on microcontroller
rs= 1; rw=0; e=1;
sbit rs = P3^2; //RS pin connected to pin 2 of port 3
msdelay(1);
sbit rw = P3^3; // RW pin connected to pin 3 of port 3
e=0;
sbit e = P3^4; //E pin connected to pin 4 of port 3
}
void lcd_init() //Function to prepare the LCD and get it
void msdelay(unsigned int time) // Function for creating ready
delay in milliseconds.
{
{ unsigned i,j ;
lcd_cmd(0x38); // using 2 lines and 5X7 matrix of LCD
for(i=0;i<time;i++)
msdelay(10);
for(j=0;j<1275;j++);
lcd_cmd(0x0F); // turn display ON, cursor blinking
}
msdelay(10);
void lcd_cmd(unsigned char command) //Function to
send command instruction to LCD lcd_cmd(0x01); //clear screen
{ display_port = command; msdelay(10);
rs= 0; rw=0; e=1; lcd_cmd(0x81); // bring cursor to position 1 of line 1
msdelay(1); msdelay(10);
e=0; }
void main()
{
unsigned char a[10]="MBSD LAB"; //string of 14 characters with a null terminator.
int l=0;
lcd_init();
while(a[l] != '\0') // searching the null terminator in the sentence
{
lcd_data(a[l]);
l++;
msdelay(50);
}
}
Program for LCD Interfacing with 8051
Microcontroller (AT89C51)
Home Task