You are on page 1of 9

LCD16x2 Interfacing in 8-bit with 8051

IntroductionLCDs (Liquid Crystal Displays) are used for displaying


status or parameters in embedded systems.

LCD 16x2 is 16 pin device which has


8 data pins (D0-D7) and
3 control pins (RS, RW, EN).
The remaining 5 pins are for supply and 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 need, we can send the required data in data mode.

8/28/2018 RVS TCC MPMC BY PRADEEV


Hardware Connection
LCD 162 Pins 89c51 Pins
data pins D0-D7 PORT1
RS PORT2.0
RW PORT2.1
E PORT2.2
LCD interfacing program with 8051 microcontroller
To initialize LCD
1. Power ON LCD
2. Wait for 15ms, Power on initialization time for LCD16x2
3. Send 0x38 command (initialize. 2 line, 5x8 matrix, 8-bit
mode)
4. Send any Display ON command (0x0E, 0x0C)
5. Send 0x06 command (increment cursor)
Command write function
Send command to 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.
Data write function
Send command to data port
Make RS pin low, RS=1 (data reg.)
Make RW pin low, RW=0 (write operation)
8/28/2018 Give High toMPMC
RVS TCC LowBYpulse at Enable (E) minimum of 450 ns
PRADEEV
8/28/2018 RVS TCC MPMC BY PRADEEV
8/28/2018 RVS TCC MPMC BY PRADEEV
To initialize LCD
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)

; P2.0 EQU RS
; P2.1 EQU RW
; P2.2 EQU E
ORG 0000H ;
MOV A, #38H ; INITIATE LCD
ACALL COMMWRT ;
ACALL DELAY ;

MOV A, #0EH ; DISPLAY ON CURSOR ON


ACALL COMMWRT ;
ACALL DELAY ;

MOV A, #01H ; CLEAR LCD


ACALL COMMWRT ;
8/28/2018 RVS TCC MPMC BY PRADEEV
ACALL DELAY ;
MOV A, #84H ; CURSOR AT LINE 1 POSITION 4
ACALL COMMWRT ;
ACALL DELAY ;

Data

MOV A, #'A' ; SEND ASCII DATA


ACALL DATAWRT ;
ACALL DELAY ;

AGAIN :
SJMP AGAIN ;

8/28/2018 RVS TCC MPMC BY PRADEEV


Command write function
Send command to 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.

COMMWRT:
MOV P1, A ;
CLR P2.0 ; RS = 0 FOR COMMAND REGISTER
CLR P2.1 ; R/W = 0 FOR WRITE
SETB P2.2 ; E = 1 FOR HIGH PULSE
ACALL DELAY ;
CLR P2.2 ; E = 0 FOR LOW PULSE
RET

8/28/2018 RVS TCC MPMC BY PRADEEV


Data write function
Send command to data port
Make RS pin low, RS=1 (data reg.)
Make RW pin low, RW=0 (write operation)
Give High to Low pulse at Enable (E) minimum of 450 ns

DATAWRT:
MOV P1, A ;
SETB P2.0 ; RS = 1 FOR DATA REGISTER
CLR P2.1 ; R/W = 0 FOR WRITE
SETB P2.2 ; E = 1 FOR HIGH PULSE
ACALL DELAY ;
CLR P2.2 ; E = 0 FOR LOW PULSE
RET

8/28/2018 RVS TCC MPMC BY PRADEEV


Delay
LCD Power on delay: after power on, we can’t send commands immediately,
LCD16x2 needs self-initialization time 15ms. While programming we need to
take care of providing sufficient power on delay> 15ms, and then send
command to LCD.

After providing commands to execute, LCD16x2 takes time in microseconds


but for 0x01 command (Clear display), it takes 1.64ms to execute. So after
giving this command, we need to give sufficient delay> 1.63milliseconds.

DELAY :
MOV R3, #50H ;
BACK:
MOV R4, #255H ;
HERE:
DJNZ R4, HERE ;
DJNZ R3, BACK ;
RET
END
8/28/2018 RVS TCC MPMC BY PRADEEV