You are on page 1of 7

LCD INTERFACING

8051 MICROCONTROLLER S.S.A.S.I.T.(E.C.DEPT)

LCD INTERFACING USING 8051 MICROCONTROLLER (AT89C51)

SUMMARY:it is very important to keep a track of the working of almost all the automated and semiautomated devices, be it a washing machine, an autonomous robot or anything else. This is achieved by displaying their status on a small display module. LCD (Liquid Crystal Display) screen is such a display module and a 16x2 LCD module is very commonly used. These modules are replacing seven segments and other multi segment LEDs for these purposes. The reasons being: LCDs are economical, easily programmable, have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. LCD can be easily interfaced with a microcontroller to display a message or status of a device. This topic explains the basics of a 16x2 LCD and how it can be interfaced with AT89C51 to display a character.

CKT DIAGRAM:-

SANKDASARIYA SHAILESH B.

ENRL NO.090760111025

LCD INTERFACING
8051 MICROCONTROLLER S.S.A.S.I.T.(E.C.DEPT)

DISCRIPTION:A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers. 1. Command/Instruction Register- stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc. 2. Data Register- stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. Commonly used LCD Command codes:

HEX CODE 1 2 4 6 E 80 C0 38

COMMAND TO LCD INSTRUCTION REGISTER CLEAR SCREEN DISPLAY RETURN HOME DECREMENT CURSOR INCREMENT CURSOR DISPLAY ON, CURSOR BLINKING FORCE THE CURSOR TO THE BEGINNING OF THE 1ST LINE FORCE CURSOR TO THE BEGINNING OF THE 2ND LINE USE 2 LINES AND 5X7 MATRIX

SANKDASARIYA SHAILESH B.

ENRL NO.090760111025

LCD INTERFACING
8051 MICROCONTROLLER S.S.A.S.I.T.(E.C.DEPT) Programming the LCD: 1. Data pin8 (DB7) of the LCD is busy flag and is read when R/W = 1 & RS = 0. When busy flag=1, it means that LCD is not ready to accept data since it is busy with the internal operations. Therefore before passing any data to LCD, its command register should be read and busy flag should be checked. 2. To send data on the LCD, data is first written to the data pins with R/W = 0 (to specify the write operation) and RS = 1 (to select the data register). A high to low pulse is given at EN pin when data is sent. Each write operation is performed on the positive edge of the Enable signal. 3. To send a command on the LCD, a particular command is first specified to the data pins with R/W = 0 (to specify the write operation) and RS = 0 (to select the command register). A high to low pulse is given at EN pin when data is sent.

Displaying single character A on LCD The LCD is interfaced with microcontroller (AT89C51). This microcontroller has 40 pins with four 8-bit ports (P0, P1, P2, and P3). Here P1 is used as output port which is connected to data pins of the LCD. The control pins (pin 4-6) are controlled by pins 2-4 of P0 port. Pin 3 is connected to a preset of 10k? to adjust the contrast on LCD screen. This program uses the above concepts of interfacing the LCD with controller by displaying the character A on it.

SANKDASARIYA SHAILESH B.

ENRL NO.090760111025

LCD INTERFACING
8051 MICROCONTROLLER S.S.A.S.I.T.(E.C.DEPT)

C CODE://Program of LCD interfacing


#include<reg51.h> #define cmdport P2 #define dataport P3 sbit rs = cmdport^0; //register select pin sbit rw = cmdport^1; // read write pin sbit e = cmdport^2; //enable pin void delay(unsigned int msec) // Function to provide time delay in msec. { int i,j ; for(i=0;i<msec;i++) for(j=0;j<1275;j++); } void lcddata(unsigned char m) //Function to send data to LCD { P3=m; rs=1; rw=0; e=1; delay(1); e=0; delay(100); return; } void lcdcmd(unsigned char item) //Function to send command to LCD { dataport=item; rs=0; rw=0; e=1; delay(1); e=0; } void main() { lcdcmd(0x30); delay(100); lcdcmd(0x0E); delay(100); lcdcmd(0x01); delay(100); lcdcmd(0x06); delay(100); lcdcmd(0x86); delay(100); lcddata('B'); lcddata('Y'); lcddata(' '); lcddata('E'); lcddata('C'); lcddata(' '); lcddata('D'); lcddata('E'); lcddata('P'); lcddata('T');

// for using 8-bit 2 row mode of LCD // turn display ON for cursor blinking //clear screen //display ON // bring cursor to position 6 of line 1

SANKDASARIYA SHAILESH B.

ENRL NO.090760111025

LCD INTERFACING
8051 MICROCONTROLLER S.S.A.S.I.T.(E.C.DEPT)
}

COMPONANT:LCD:LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

SANKDASARIYA SHAILESH B.

ENRL NO.090760111025

LCD INTERFACING
8051 MICROCONTROLLER S.S.A.S.I.T.(E.C.DEPT)

AT89C51 MICROCONTROLLER:AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. AT89C51 has 4KB of Flash programmable and erasable read only memory (PEROM) and 128 bytes of RAM. It can be erased and program to a maximum of 1000 times. In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit bi-directional ports, i.e., they can be used as both input and output ports. Except P0 which needs external pull-ups, rest of the ports have internal pullups. When 1s are written to these port pins, they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed individually. Port P0 and P2 are also used to provide low byte and high byte addresses, respectively, when connected to an external memory. Port 3 has multiplexed pins for special functions like serial communication, hardware interrupts, timer inputs and read/write operation from external memory. AT89C51 has an inbuilt UART for serial communication. It can be programmed to operate at different baud rates. Including two timers & hardware interrupts, it has a total of six interrupts.

SANKDASARIYA SHAILESH B.

ENRL NO.090760111025

LCD INTERFACING
8051 MICROCONTROLLER S.S.A.S.I.T.(E.C.DEPT)

SANKDASARIYA SHAILESH B.

ENRL NO.090760111025

You might also like