In this project, we will have brief discussion on how to interface 16×2 LCD module to AT89C51, which is an 8051 family microcontroller. We use LCD display for the displaying messages in a more interactive way to operate the system or displaying error messages etc. Interfacing 16×2 LCD with 8051 microcontroller is very easy if you understanding the working of LCD.
Hence, in this project, I will not only give the information of LCD and also provide the code in C language which is working fine without any errors.
Also get an idea about Interfacing LEDs with 8051 Mirocontroller
Outline
ToggleA Brief Note on 16×2 LCD
16×2 Liquid Crystal Display which will display the 32 characters at a time in two rows (16 characters in one row). Each character in the display is of size 5×7 pixel matrix. This matrix differs for different 16×2 LCD modules, if you take JHD162A, this matrix goes to 5×8. There are 16 pins in the LCD module, the pin configuration us given below
Ground pin
Power supply pin of 5V
Used for adjusting the contrast commonly attached to the potentiometer.
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.
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)
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
Back light of the LCD which should be connected to Vcc
Back light of LCD which should be connected to ground.
So by reading the above table you can get a brief idea how to display a character. For displaying a character you should enable the enable pin (pin 6) by giving a pulse of 450ns, after enabling the pin6 you should select the register select pin (pin4) in write mode. To select the register select pin in write mode you have to make this pin high (RS=1), after selecting the register select you have to configure the R/W to write mode that is R/W should be low (R/W=0).
Follow these simple steps for displaying a character or data
- E=1; enable pin should be high
- RS=1; Register select should be high
- R/W=0; Read/Write pin should be low.
To send a command to the LCD just follows these steps:
- E=1; enable pin should be high
- RS=0; Register select should be low
- R/W=0; Read/Write pin should be low.
Commands: There are some preset commands which will do a specific task in the LCD. These commands are very important for displaying data in LCD. The list of commands given below:
For switching on LCD, blinking the cursor.
Clearing the screen
Return home.
Decrement cursor
Increment cursor
Display on and also cursor on
Force cursor to beginning of the first line
Force cursor to beginning of second line
Use two lines and 5x7 matrix
Cursor line 1 position 3
Activate second line
Jump to second line position 3
Jump to second line position1
To get the detailed information, Click Here and Download the Datasheet
Interfacing 16×2 LCD with 8051 Circuit Diagram
Components Required
- AT89C51 (8051 Microcontroller)
- 16X2 LCD Display
- 11.0592MHz Crystal
- 2 X 33pF Capacitors
- 2 X 10 KΩ Resistors
- 1 KΩ X 8 Resistor Pack
- 10 KΩ Potentiometer
- 330Ω Resistor
- Push Button
- 10μF/16V Capacitor
- 8051 Programmer
- 5V Power Supply
- Connecting Wires
Circuit Explanation
The crystal oscillator, along with two 33pF Capacitors, are connected to XTAL1 and XTAL2, which will provide the system clock to the microcontroller.
RST Pin is pulled-LOW with the help of a 10KΩ Resistor. With the help of a 10μF Capacitor and a Push Button, you can reset the 8051 Microcontroller. EA is pulled-HIGH with the help of a 10KΩ resistor.
The data pins of the LCD are connected to PORT0 (first, the PORT0 pins must be pulled-HIGH with the help of a 1KΩ Resistor Pack). RS and E are connected to PORT2 pins P2.0 and P2.1.
A 10KΩ Potentiometer is used to adjust the contrast of the LCD.
Programming LCD to 8051
Coming to the programming you should follow these steps:
- STEP1: Initialization of LCD.
- STEP2: Sending commands to LCD.
- STEP3: Writing the data to LCD.
[Also Read: How To Make an Adjustable Timer ]
Initializing LCD
To initialize LCD to the 8051 the following instruction and commands are to be embed in to the functions
- 0x38 is used for 8-bit data initialization.
- 0xoC for making LCD display on and cursor off.
- 0X01 for clearing the display of the LCD.
- 0x80 for positioning the cursor at first line .
Sending Commands to the LCD
- E=1; enable pin should be high
- RS=0; Register select should be low for sending commands
- Placing the data on the data registers
- R/W=0; Read/Write pin should be low for writing the data.
Writing the Data to the LCD
- E=1; enable pin should be high
- RS=1; Register select should be high for writing data
- Placing the data on the data registers
- R/W=0; Read/Write pin should be low for writing the data.
Important Post – Interfacing 7 Segment Display with 8051 Microcontroller
Code
Additional Codes
The programs given below will use above functions and display the complete string which is given by the programmer to display the data. We have provided two demo codes working properly and easy to understand.
Code 1
Code 2
Related Post: Real Time Clock (RTC) Interfacing PIC18F
20 Responses
hi….this is sandhya….we are dng project using lcd display. so we want program coding in keil for displaying the received data….?
Yes we can.
Wow, this article is good, my sister is analyzing such things, thus I am going to let know her.
if u had answer, send me the pgm. B’cz i have the same project.
Below is a simple code written in assembly using keil..The code displays HELLO.
The code is written for 8051 uc. For info on pin connections or other things,email me- srihariash@gmail.com
ORG 0000H
HERE: MOV A,#38H
ACALL CMND
MOV A,#0FH
ACALL CMND
MOV A,#06H
ACALL CMND
MOV A,#01H
ACALL CMND
MOV A,#080H
ACALL CMND
MOV A,#’ ‘
ACALL DISP
MOV A,#’H’
ACALL DISP
MOV A,#’E’
ACALL DISP
MOV A,#’L’
ACALL DISP
MOV A,#’ L’
ACALL DISP
MOV A,#’O’
ACALL DISP
SJMP HERE
CMND: MOV P2,A
CLR P3.5
CLR P3.4
SETB P3.3
CLR P3.3
RET
DISP: MOV P2,A
SETB P3.5
CLR P3.4
CLR P3.3
SETB P3.3
RET
END
how to burn the generated hex code by keil to 8051
superb site i have seen , coz programing is very good written nd undetstood quite easily….
thank you………..
NGDFM,HD FVULDVBDVFDVHBDKFHVBFDMVHBDMFVBMVVHG
very simplified program. This is the best code I found over internet.
i understood how to display simple characters.
but suppose i want to display a string(eg: “my name is xyz”) then what should i do?
should i just put the string in lcddata funcion? or do ineed to manually shift the data to left for showing space and other characters in same line?
Hi…sir am pratibha…we are ding LCD display project we want code and diagram plz give me
code is uploaded in the post..Go through it completely.
Sir I am designing digital presaure measurment display…I am confuse that I give a anlog signal to adc and it convert that into digital and I want to display preesure according to signal applied to the adc 0808 how can I do that..??
my son, i understand your concern if u just go to the good morning store and buy a pressure 8056 washing hammer
need a code for displaying in LCD using xmc4500 please
GOOD Explanation !
Can i pls get a complete report on this project
I want to read real time values from sensors through microcontroller and display it here. Will this code work or if no then can anyone help me with the code in keil vision software
Too many void are present in program
Hi. Can I get the code in assembly format?