Exp No 5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

LCD 16x2 Pinout

LCD16x2 with 8051 Pin Connection

89c51 Pins

Data Pins D0-D7 PORT1

RS PORT2.0

RW PORT2.1

E PORT2.2

Experiment No.:5
LCD INTERFACING WITH 8051 MICROCONTROLLER
Aim

To interface a Liquid Crystal Display (16X2) with 8051 Microcontroller.

Components Required

S.NO COMPONENTS QUANTITY

1 8051 Microcontroller Trainer Kit 1

2 In System Programmer 1

3 Jumper Wires As Required

4 Laptop with Data Cable 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

1. Give the connections as per the interfacing diagram.

2. Open Keil Software. Enter the type of microcontroller (AT89C52) that is to be


used in the window that is displayed at first.

3. Create a new Project file under which the “.c” file containing the code for the
experiment must be created.

4. Compile the code in the .c file by using the ‘Build’ command.

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

#include <reg51.h> //Header Declaration


#include <string.h> //String Header Declaration

void delay_ms(unsigned int ms); // Delay function Declaration

//----------------------------------LCD pins and functions Declaration---------------------------//

#define LCD P1 // LCD Data Pins

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)
{

cmd_lcd(0x80); //Print the String at First Line


Print_String(string);

cmd_lcd(0x0c); //Cursor Off


delay_ms(1000);

cmd_lcd(0x01); //Clear Screen


delay_ms(100);

}
}

//----------------------------------LCD funtions--------------------------------------//

void initlcd()
{
cmd_lcd(0x38); // 2 lines(16*2), 5*7 matrx
delay_ms(5);

cmd_lcd(0x0E); //Display On, Cursor ON


LCD16x2 Command write function

 Send command to the data port


 Make RS pin low, RS=0 (command reg.)
 Make RW pin low, RW=0 (write operation)
 Give High to Low pulse at Enable (E) minimum of 450ns.

LCD16x2 Data write function

 Send command to the data port


 Make RS pin High, RS=1 (data reg.)
 Make RW pin low, RW=0 (write operation)
 Give High to Low pulse at Enable (E) minimum of 450 ns
delay_ms(5);
cmd_lcd(0x01); //Clear Screen
delay_ms(5);
cmd_lcd(0x06); //Increment cursor
delay_ms(5);
cmd_lcd(0x80); //Cursor Home (1st line 1st position)
delay_ms(100);
}

void cmd_lcd(unsigned char command)


{
EN = 1;
RS = 0;
LCD=command;
EN = 0;
delay_ms(1);
}

void data_lcd(unsigned char databyte)


{
EN = 1;
RS = 1;
LCD=databyte;
EN = 0;
delay_ms(1);
}

void Print_String(unsigned char *message)


{
while(*message!='\0')
{
data_lcd( *message);
message++;
}
}

//----------------------------------Delay Routine--------------------------------------//

void delay_ms(unsigned int ms)


{
unsigned char t1;
unsigned int t2;

for(t1=0; t1<ms; t1++){


for(t2=0; t2<114; t2++);
}
}
Result

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?

3. How do you import the Hex file to 8051?


4. What is the command word for clearing LCD Screen?
5. Differentiate LED and LCD.
6. What is the significance of RS pin in LCD?
7. Give the specification / features of LCD used in this experiment.
8. How to adjust the brightness of the LCD?
9. What are the registers present in LCD?
10. Give the hex code commands for “cursor blinking, display on” and “Force cursor to
the beginning”.
11. Show the interfacing of LCD to an Arduino.
12. What is the use of CG RAM in LCD?
13. How to create the letter ‘b’ in CG-RAM?
14. What are the different modes in which LCD can be used? Which mode is
advantageous?
15. Study the Graphics LCD and give an example for the same.
16. What is the use of CGROM in LCD?
17. What is the use of Busy Flag in LCD?
18. How many port pins are required to interface LCD to 8051?

You might also like