Exp No 5
Exp No 5
Exp No 5
89c51 Pins
RS PORT2.0
RW PORT2.1
E PORT2.2
Experiment No.:5
LCD INTERFACING WITH 8051 MICROCONTROLLER
Aim
Components Required
2 In System Programmer 1
5 LCD (16X2) 1
Software Required
1. Keil Microvision 5
2. ProgISP
Theory
LCDs (Liquid Crystal Displays) are used for displaying status or parameters in
embedded systems.
LCD 16x2 is 16 pin device that has 8 data pins (D0-D7) and 3 control pins (RS, RW, EN).
The remaining 5 pins are for the supply and the backlight for the LCD.
The control pins help us configure the LCD in command mode or data mode. They also
help configure read mode or write mode and also when to read or write.
LCD 16x2 can be used in 4-bit mode or 8-bit mode depending on the requirement of the
application. In order to use it we need to send certain commands to the LCD in
command mode and once the LCD is configured according to our needs, we can send the
required data in data mode.
LCD16x2 with 8051 Interfacing Diagram
Procedure
3. Create a new Project file under which the “.c” file containing the code for the
experiment must be created.
5. To create the hex file, click the ‘Target’ command, and in the dialog box that
displays after, enter the crystal frequency to be 11.0592 MHz, go to the Output
window, where you enable the option to create a hex file, and once again the file
must be compiled using the ‘Build’ command.
6. Once the hex file is created, connect the Trainer Kit to the In-System Programmer
using Jumper wires, and connect the In-System Programmer to the Laptop using the
data cable.
7. Open ProgISP software. Make sure that all the necessary drivers are installed
along with the software. Enter the details of the microcontroller used and ensure
that the software has read the presence of the microcontroller.
8. In the right-side panel of the window, click the ‘Load Flash’ button and select the
hex file that had been created earlier.
9. After the file gets uploaded, click the ‘Auto’ button, to download the program
onto the microcontroller from the laptop.
10. Once the program is downloaded into the microcontroller, the output can be
observed and verified.
Programming LCD16x2
Initialize LCD16x2
Power ON LCD
Wait for 15ms, Power-on initialization time for LCD16x2
Send 0x38 command (initialize. 2 line, 5x8 matrix, 8-bit mode)
Send any Display ON command (0x0E, 0x0C)
Send 0x06 command (increment cursor)
Embedded C Code
sbit RS = P2^0;
sbit EN = P2^1;
void initlcd(void);
void cmd_lcd(unsigned char command);
void data_lcd(unsigned char databyte);
void Print_String(unsigned char *message);
//----------------------------------MAIN PROGRAM--------------------------------------//
void main(void)
{
unsigned char string[]="MP&MC LAB";
initlcd(); //initialise lcd
while(1)
{
}
}
//----------------------------------LCD funtions--------------------------------------//
void initlcd()
{
cmd_lcd(0x38); // 2 lines(16*2), 5*7 matrx
delay_ms(5);
//----------------------------------Delay Routine--------------------------------------//
The interfacing of 16X2 LCD with 8051 microcontroller kit was successfully
completed.
Questions
1. Give the IC number for LCD.
2. What is this two black circle like things on the back of the LCD?