CpE 364 Computer Engineering Department Laboratory #7
LAB-7: Interfacing Liquid Crystal Display (LCD)
Objectives:
• LCD Interfacing in Edsim51di.
• Writing Text characters to the LCD.
Materials:
• Edsim51 di simulator
Hitachi HD44780 LCD
Liquid Crystal Display (LCD) is a 16 Characters x 2 lines Backlit Display.
Background:
The LCD is a dot matrix liquid crystal display which displays alphanumeric, characters and symbols. LCD is
made up of glass, organic sealant, organic fluid and polymer based polarizes.
The 2402has a built in controller HD44780 which has 3-control lines as well as 4 or 8 I/O lines for data bus.
The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus.
The 3-control lines are referred to as EN, RS, and RW.
The EN line is called “Enable”. This control line is used by the LCD to latch information available at its
data inputs. To latch data to the LCD, your program should make sure this line undergoes a high to low
transition (i.e., SETB EN followed by CLR EN )
The RS line is the “Register select” line. When RS is low, the data is to be treated as a command whereas if
RS is high the data being sent is treated as text data to be displayed on the LCD screen.
The RW line is the “Read/Write” control line. When RW is low it specifies a write operation whereas a high
value on this line indicates a read operation.
Initialize LCD
Position cursor
Write text
yes
More text
No
End
Figure 1: Preparing LCD for Writing
1
CpE 364 Computer Engineering Department Laboratory #7
Abbreviation of different symbols used in Figure.2, is given in Table 1.
2. Cursor Positioning:
The HD44780 based LCD displays are basically designed for one or two lines with a maximum of 24-
character positions. The cursor addresses for a 16-characters * 2-lines LCD are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Line 1 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
Line2 C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
Example 1: To set cursor at11thcharacter position of the first line, the following procedure is used.
To set the Cursor at 11thposition on 1st line, the command word is computed as follows:
80H+display position address in the respective line = 80H + 0AH = 8AH
Example 2: To set cursor at11thcharacter position of the second line, the following procedure is used.
To set the Cursor at 11thposition on2nd line, the command word is computed as follows:
C0H+display position address in the respective line = C0H + 0AH = CAH
In both examples, send the command to the LCD using the CMD procedure. You should send the high
nibble first and then the low nibble of the command.
3. Writing text:
The character to be displayed on the LCD has to be in the ASCII format before it can be sent to the LCD.
The character byte is swapped and sent 4-bits at a time.
4. LCD commands:
2
CpE 364 Computer Engineering Department Laboratory #7
Problem Definition:
Initialize the given LCD, and display digit 2 on the 1st line 1st position then clear LCD and display
character Z on the 2nd line 1st position.
Steps involved in this laboratory are:
1) For the given problem statement, prepare the algorithm.
2) Write the assembly language program.
3) Assemble source code, Build the program.
Note: In Fig. 2, for proper operation of LCD, typical delay timings are provided.
Program Listing:
;This program will display digit 2 on the first line of the LCD then it will clear LCD and display
character Z on the second line of LCD
ORG 0H
ACALL INLCD ; initialize LCD
;----- display 2 on the 1st line 1st position-----
MOV A,#80H
ACALL CMD
MOV A,#32H
ACALL WCHR
MOV R7,#250
WAIT1: ACALL LDELAY ; Delay to see no. 2 before it gets cleared
DJNZ R7,WAIT1
;-----clear LCD-----
MOV A,#01H
ACALL CMD
MOV R7,#14
WAIT: ACALL LDELAY
DJNZ R7,WAIT
;-----display Z on the 2nd line 1st position---
MOV A,#0C0H
ACALL CMD
MOV A,#'Z'
ACALL WCHR
FINISH: SJMP FINISH
;- Subroutine to write character in A to the LCD-----
WCHR:
PUSH ACC
PUSH B
SETB P1.3
MOV B,A
ACALL COMMON
ACALL LDELAY
MOV A,B
SWAP A
3
CpE 364 Computer Engineering Department Laboratory #7
ACALL COMMON
ACALL LDELAY
POP B
POP ACC
RET
;--Subroutine to write COMMAND in A to the LCD----
CMD:
CLR P1.3
MOV B,A
ACALL COMMON
ACALL LDELAY
MOV A,B
SWAP A
ACALL COMMON
ACALL LDELAY
RET
;---Common operation for CHAR write and COMMAND write
COMMON:
ANL a,#11110000B
ANL P1, #00001111B
ORL P1,A
SETB P1.2
CLR P1.2
RET
; ------- procedure init_display -------
INLCD:
CLR P1.3
CLR P1.7
CLR P1.6
SETB P1.5
CLR P1.4
SETB P1.2
CLR P1.2
ACALL LDELAY
SETB P1.2
CLR P1.2
SETB P1.7
CLR P1.6
CLR P1.5
CLR P1.4
SETB P1.2
CLR P1.2
ACALL LDELAY
CLR P1.7
CLR P1.6
CLR P1.5
4
CpE 364 Computer Engineering Department Laboratory #7
CLR P1.4
SETB P1.2
CLR P1.2
SETB P1.7
SETB P1.6
SETB P1.5
SETB P1.4
SETB P1.2
CLR P1.2
ACALL LDELAY
CLR P1.7
CLR P1.6
CLR P1.5
CLR P1.4
SETB P1.2
CLR P1.2
SETB P1.6
SETB P1.5
SETB P1.2
CLR P1.2
ACALL LDELAY
RET
; ------- procedure delay -------
LDELAY:
MOV R0, #50
DJNZ R0, $
RET
5
CpE 364 Computer Engineering Department Laboratory #7
Lab Exercise-7
Name: ID:
==========================================================================
Problem Statement: Write a program to perform the following actions continuously:
Display the following on LCD:
• Your first name stored in ROM on the 1st line starting from display position 3.
• A single digit number stored in a RAM on the 2nd line from display position 4.
1. Draw the flow chart for solving the problem.
2. Comment your code.
3. Assemble, build and download the code to kit and verify the result.
4. Ask your engineer to check your results, write his/her comments and sign below:
………………………………………………………………………………………………………………………………………..……………………………….
……………………………………………………………………………………………………………………………………………………..………………….
………………………………………………………………………………………………………………………………………………………..……………….
Engineer Signature……..……………..
5. Submit the print out of the source code with proper comments.