Sunday, 11 January 2015

How to interface 16x2 LCD using 8051/AT89c51 with 4 data lines

LCD Interfacing with 8051/AT89c51 using 4-data lines

Here I am writing program to interface LCD using 8051/AT89c51 Microcontroller with using only 4 data lines. For interfacing a LCD you must have some idea about LCD Pins. The LCD which is normally available in market is of 16-pin.LCD pin description is explained below:-

PIN NUMBER
SYMBOL
FUNCTION
1.
VSS
GROUND
2.
VDD
+5V
3.
VEE
Contrast Adjustment
4.
RS
Register Selection Signal
5.
R/W
H/L , Read/write Signal
6.
E
H->L,  Enable Signal
7.
D0
H/L ,Data Bus Line
8.
D1
H/L ,Data Bus Line
9.
D2
H/L ,Data Bus Line
10.
D3
H/L ,Data Bus Line
11.
D4
H/L ,Data Bus Line
12.
D5
H/L ,Data Bus Line
13.
D6
H/L ,Data Bus Line
14.
D7
H/L ,Data Bus Line
15.
A/VEE
Backlight Anode
16.
K
Backlight cathode

As per the pin details of LCD explained in above table the important pin used to display character on LCD are RS,R/W,E and data lines (D0-D7) .Through RS pin we can select the LCD data register or LCD command register. If RS pin is HIGH then data register is selected or if RS pin is LOW then command register is selected. R/W is for selecting read or write operation if R/W pin is HIGH then read operation is selected if R/W pin is LOW then write operation is selected. Enable pin is to enabling data reception. Pin D0 to D7 are data lines through which LCD received command or data in 8-bit format.

Now to interfacing LCD on 4 data lines i have connected higher 4-bit of Port1 (i.e. P1.4 – P1.7) to higher the 4 data lines (i.e. D4-D7) you can see Connection diagram used to interface LCD using 4 data lines is given in below image:-


Now you can see in the connection diagram that RS is connected to P2.0 and R/W pin is ground for Write operation and Enable (E) pin is connected to P2.1.Also considered that higher 4 data lines are connected to higher 4 bit of port 1.

In this Program I have print my name (VAIBHAV SINGHAL) in first line and my profession   (i.e. FIRMWARE Engineer) in second line. The main file of program is shown in below image:-


 In the image of above program you can see I have first initialized the LCD by sending commands 0x02 to reset LCD,0x28 for 2 lines and 5x7 matrix and also for selecting LCD in 4- bit mode,0x0C to ON the display,0x01 to clear LCD screen and 0x06 for cursor increment. After initializing LCD i have write command to start writing from 1 line and send my name then send command to write data from second line i have wrote my profession.

Now in above program I have used to functions one to write command and the other is to send string on LCD. Definition of both function is given in image below:-


In above image you can see both functions. In “LCD_write_command” function register firstly I have selected the command register by putting RS pin LOW and then after I have pull low higher 4 bit of port1 which is connected to data lines and then I have put higher 4 bit of data and then enables data reception by putting Enable pin high for very short time after that I have put zero to data lines and then after ihave send the lower 4 bit to data lines.

 In “LCD_Send_String” function I have send complete string to LCD by using “LCD_write_data” function. Full details of this function is given in image below:- 


The “LCD_write_data” function is same as of “LCD_write_command” function except that I have select data register in this function by putting RS pin high.           
This is all about to write characters on 16x2 LCD by using 4 data lines.

Download Link

To download complete code of LCD interfacing using 8051/89c51 with 4-data lines click here.
For downloading controller's datasheet or hardware manual click on download tab.   









No comments: