Expt No 10 - LCD MSG Display
Expt No 10 - LCD MSG Display
Expt No 10 - LCD MSG Display
The pins of LCD are made available to interface it with microcontroller. The pining information
of the LCD is as follows.
VSS (Pin 1): It is the 0V supply or ground.
VDD (Pin 2): should be connected to the positive supply. Although the manufacturers specify a
5V DC supply.
VEE (Pin 3): It is the contrast control pin. It is used to adjust the contrast of the display and should
be connected to a DC supply. A potentiometer is usually connected to the power supply with its
wiper arm connected to this pin and the other leg of the potentiometer connected to the ground.
RS (Pin 4): It is the register select (RS) and when this pin is LOW, data transferred to the LCD is
treated as commands. When RS is HIGH, character data can be transferred to and from the module.
R/W (Pin 5): It is the read/write pin. This pin is pulled LOW in order to write commands or
character data to the LCD module. When this pin is HIGH, character data or status information
can be read from the LCD module.
EN (Pin 6): It is the enable pin, which is used to initiate the transfer of commands or data between
the module and the microcontroller. When writing to the display, data is transferred only on the
HIGH to LOW transition of this pin.
D0 to D7 (Pins 7 to 14): Those are the eight data bus lines. Data can be transferred between the
microcontroller and the LCD module using either a single 8-bit byte or two 4-bit nibbles. In the 4
bit case, only the upper four data lines (D4 to D7) are used. The 4-bit mode has the advantage of
requiring fewer I/O lines to communicate with the LCD.
The LCD module is interfaced with 8051 microcontroller as shown in fig 3 below. The higher
nibble port pins of P1 are connected to higher four data lines of LCD. The control lines of the LCD
i.e. En, RW and RS are connected to P3.0, P3.1 and P3.2 respectively. The potentiometer is
connected to adjust the contrast of the LCD module.
Fig 3: LCD interfacing with 8051
The LCD module has a set of preset command instructions. Each command will make the
module to do a particular task. The commonly used command and their functions are given in the
table below.
Commands Function
20 Initialize LCD 1 line, 5x7 Matrix, 4 bit mode
28 Initialize LCD 2 lines, 5x7 Matrix, 4 bit mode
38 Initialize LCD 2 lines, 5x7 Matrix, 8 bit mode
0F Display on, cursor blinking
08 Display off, cursor off
0C Display on, cursor off
01 Clear LCD
PROCEDURES:
i) CMDWRT: This procedure writes the command to LCD for its initialization and settings.
ii) DATAWRT: This procedure writes the ASCII data to LCD.
iii) SEPARATOR: As LCD is connected to microcontroller in 4 bit mode, this procedure splits
upper and lower nibble of 8 bit command/data and stores upper nibble in U variable and lower
nibble in L variable.
Conclusion: In this way, we have interfaced and programmed the 16x2 LCD with 8051
microcontroller and studied the commands of LCD and its function.
; Print 'SE IT' on 16x2 LCD interfaced in 4 bit mode
; DATA LINES => P1.4 = LCD_D4, P1.5 = LCD_D5, P1.6 = LCD_D6, P1.7 = LCD_D7
; CONTROL LINES => P3.0 = LCD_EN, P3.1 = LCD_RW, P3.2 = LCD_RS
;--------------------------------------------------------------------
; PORT VARIABLE DECLIRATION
U EQU 31H
L EQU 32H
EN EQU P3.0
RW EQU P3.1
RS EQU P3.2
;----------------------------------------------------------------------
ORG 00h
MOV P1, #00H ; PORT P1 AS OUTPUT (LED DATA/COMMAND PORT)
MOV P3, #00H ; PORT P3 AS OUTPUT (LED CONTROL SIGNAL PINS)
CLR RW
;--------------------------------------------------------------------
; LCD INITILIZATION
ACALL DELAY ; Give LCD some time.
MOV P1, #20H ; initialize. LCD 1 line, 5x7 Matrix, 4 bit mode
ACALL CMDWRT ; Call command Subroutine
ACALL DELAY ; Give LCD some time.
;-------------------------------------------------------------------------
; DISPLAYING DATA ON THE LCD
;--------------------------------------------------------------------------
; SUBROUTINE TO SEPRATE HIGHER AND LOWER NIBBLE
SEPARATOR:
MOV U, A
ANL U, #0F0H
SWAP A
ANL A, #0F0H
MOV L, A
RET
;--------------------------------------------------------------------------
; WRITING COMMAND TO LCD
CMDWRT:
CLR RS ; RS=0 FOR COMMAND WRITE
; CLR RW ; R/W= FOR WRITE, DONE INITIALLY
ACALL SEPARATOR
RET
;---------------------------------------------------------------------------
; WRITING DATA TO LCD
DATAWRT:
SETB RS ; RS=1 FOR DATA
; CLR RW ; R/W=0 F0R WRITE, DONE INITIALLY
ACALL SEPARATOR
RET
;--------------------------------------------------------------------------
; DELAY SUBROUTINE
DELAY:
MOV R1, #10H
;---------------------------------------------------------------------------
END
;---------------------------------------------------------------------------