Experiment 4 EEE 226 PDF

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

EEE 226 Microprocessor I

LAB 4: INTERFACING LCD TO 8051

Objectives:

- To learn assembly language for running the LCD


- To construct a minimal 8051 application using LCD

Equipment

- LCD

Introduction

A liquid crystal display (LCD) is a thin, flat display device made up of any number color or
monochrome pixels arrayed in front of a light source or reflector. It is often utilized in battery-
powered electronic devices because it uses very small amounts of electric power.
The LCD is finding widespread uses replacing LEDs. This is due to declining prices of LCDs,
the ability to display numbers, characters and graphics (in contrast to LEDs, which are limited
to numbers and a few characters) and ease of programming for characters and graphics.
Below are commands to send data to LCD with a time delay using port 1 and port 2 of 8051
(refer to “The 8051 Microcontroller and Embedded Systems – using assembly and C” Mazidi.
Table 4.1 and Table 4.2 show the function of each pin and command codes for LCD
instruction.

EEE 226 Laboratory 4 Page 1


Table 4.1: Pin Descriptions of LCD

Pin Symbol I/O Description

1 Gnd -- Ground

2 VCC -- +5V power supply

3 VEE -- Power supply to control contras

4 RS I RS=0 select command register

RS=1 select data register

5 R/W I R/W=0 for write

R/W=1 for read

6 E I/O Enable

7 DB0 I/O Bit 1 of data bus (LSB)

8 DB1 I/O Bit 2 of data bus

9 DB2 I/O Bit 3 of data bus

10 DB3 I/O Bit 4 of data bus

11 DB4 I/O Bit 5 of data bus

12 DB5 I/O Bit 6 of data bus

13 DB6 I/O Bit 7 of data bus

14 DB7 I/O Bit 8 of data bus (MSB)

EEE 226 Laboratory 4 Page 2


Table 4.2: LCD command Codes

Code (Hex) Command to LCD Instruction Register

1 Clear display screen

2 Return home

4 Decrement cursor (shift cursor to left)

6 Increment cursors (shift cursor to right)

5 Shift display right

7 Shift display left

8 Display off, cursor off

A Display off, cursor on

C Display on, cursor off

E Display on, cursor on

F Display on, cursor blinking

10 Shift cursor position to left

14 Shift cursor position to right

18 Shift the entire display to left

1C Shift the entire display to right

80 Force cursor to beginning to 1st line

C0 Force cursor to beginning to 2nd line

38 2 lines and 5x7 matrix

EEE 226 Laboratory 4 Page 3


Example code for LCD.

Copy the LCD example from EdSim51 (https://www.edsim51.com/examples.html#prog4_b)


or rewrite the given code below, and once finish, run the program.

Please set “The Update Frequency” to 100 before run the program.

; put data in RAM


MOV 30H, #'A'
MOV 31H, #'B'
MOV 32H, #'C'
MOV 33H, #0 ; end of data marker

; initialise the display


; see instruction set for details

CLR P1.3 ; clear RS - indicates that instructions are


;being sent to the module

; function set
CLR P1.7 ; |
CLR P1.6 ; |
SETB P1.5 ; |
CLR P1.4 ; | high nibble set

SETB P1.2 ; |
CLR P1.2 ; | negative edge on E

CALL delay ; wait for BF to clear


; function set sent for first time –
;tells module to go into 4-bit mode
; Why is function set high nibble sent twice? See 4-bit operation on pages
;39 and 42 of HD44780.pdf.

SETB P1.2 ; |
CLR P1.2 ; | negative edge on E
; same function set high nibble sent
;a second time

SETB P1.7 ; low nibble set (only P1.7 needed to be


;changed)

SETB P1.2 ; |
CLR P1.2 ; | negative edge on E
; function set low nibble sent
CALL delay ; wait for BF to clear

; entry mode set


; set to increment with no shift
CLR P1.7 ; |
CLR P1.6 ; |
CLR P1.5 ; |
CLR P1.4 ; | high nibble set

EEE 226 Laboratory 4 Page 4


SETB P1.2 ; |
CLR P1.2 ; | negative edge on E

SETB P1.6 ; |
SETB P1.5 ; |low nibble set

SETB P1.2 ; |
CLR P1.2 ; | negative edge on E

CALL delay ; wait for BF to clear

; display on/off control


; the display is turned on, the cursor is turned on and blinking is turned
;on
CLR P1.7 ; |
CLR P1.6 ; |
CLR P1.5 ; |
CLR P1.4 ; | high nibble set

SETB P1.2 ; |
CLR P1.2 ; | negative edge on E

SETB P1.7 ; |
SETB P1.6 ; |
SETB P1.5 ; |
SETB P1.4 ; | low nibble set

SETB P1.2 ; |
CLR P1.2 ; | negative edge on E

CALL delay ; wait for BF to clear

; send data
SETB P1.3 ; clear RS - indicates that data is being
;sent to module
MOV R1, #30H ; data to be sent to LCD is stored in 8051 RAM,
;starting at location 30H
loop:
MOV A, @R1 ; move data pointed to by R1 to A
JZ finish ; if A is 0, then end of data has been
;reached - jump out of loop
CALL sendCharacter ; send data in A to LCD module
INC R1 ; point to next piece of data
JMP loop ; repeat

finish:
JMP $

sendCharacter:
MOV C, ACC.7 ; |
MOV P1.7, C ; |
MOV C, ACC.6 ; |
MOV P1.6, C ; |
MOV C, ACC.5 ; |

EEE 226 Laboratory 4 Page 5


MOV P1.5, C ; |
MOV C, ACC.4 ; |
MOV P1.4, C ; | high nibble set

SETB P1.2 ; |
CLR P1.2 ; | negative edge on E

MOV C, ACC.3 ; |
MOV P1.7, C ; |
MOV C, ACC.2 ; |
MOV P1.6, C ; |
MOV C, ACC.1 ; |
MOV P1.5, C ; |
MOV C, ACC.0 ; |
MOV P1.4, C ; | low nibble set

SETB P1.2 ; |
CLR P1.2 ; | negative edge on E

CALL delay ; wait for BF to clear

delay:
MOV R0, #50
DJNZ R0, $
RET

TASK

Based on the output that you can see, understand each of the instructions, and then report the
observation in terms of why you need those particular instructions in the code. You also need
to report the function each of the subroutines, such as “delay”, “finish” and so on.

Please do the screenshot of the output on LCD and attach it in the lab report.

EEE 226 Laboratory 4 Page 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy