Sei sulla pagina 1di 10

Assignment No 10

Title: Display a message on LCD.


Aim: To interface and write 8051 ALP to display the message on LCD.
Objective:
To be familiar with the 8051 assembly language program along with IO device
communication with microcontroller.

Problem Statement: write 8051 ALP to display the message on LCD.


Outcomes:
Software and Hardware Requirements: Windows 7 professional, 8051 kit, Keil uVision3 (or
5), Flash magic, Power supply for 8051 kit, RS232 (serial) cable for programming the IC and 16X2
LCD Display.
Theory:
LCD is an electronics display module which uses liquid crystal to produce a visible image. The
principle behind the LCD is that when an electrical current is applied to the liquid crystal molecule,
the molecule tends to untwist. This causes the angle of light which is passing though the molecule
of the polarized glass and also cause a change in the angel of the top polarizing filter. As a result,
a little light is allowed to pass the polarized glass through a particular area of the LCD. Thus that
particular area will become dark as compared to other.
There are several advantages of LCD over LED type displays. LCD consumes less power as
compared to CRT and LED. The LCDs are thinner and lighter and low cost.
Modules with 8, 16, 20, 24, 32, and 40 characters are available. The 16x2 LCD display is a very
basic module commonly used in DIYs and circuits. The fig 1 shows, 16x2 LCD module has 16
columns and 2 rows.

Fig 1: 16x2 LCD Display Fig 2: 16x2 LCD Pin Diagram

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.

Table 1: Pin Configuration of LCD Module

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

Algorithm / Steps for LCD Initialization:


The steps that has to be done for initializing the LCD is given below.
i) Introduce approx. 20ms delay to initialize the internal registers of LCD.
ii) Send command through CMDWRT function to initialize LCD in 2 lines, 5x7 matrix and 4 bit
mode.
iii) Send command through CMDWRT function so that Display becomes ON and Cursor blinks.
iv) Send command through CMDWRT function to clear the LCD data.
After sending each command, some delay has to be introduced. It’s because the LCD takes some
time to process on that command (and data as well). Normally, LCD takes 50µs to 80µs for
processing.

Algorithm / Steps for displaying data on LCD:


i) Send a data/character in ASCII format through DATAWRT function to LCD
ii) Introduce a delay to process the LCD on the given data

Algorithm / Steps for writing a command to LCD:


i) Clear RS for ‘command’ operation.
ii) Clear RW for ‘write’ operation.
iii) Separate Upper and lower nibble of the command value by using SEPARATOR function.
iv) Send higher nibble on higher nibble pins of port P1 and toggle the En pin.
v) Send lower nibble on higher nibble pins of port P1 and toggle the En pin.

Algorithm / Steps for writing/displaying a data to LCD:


i) Set RS for ‘data’ operation.
ii) Clear RW for ‘write’ operation.
iii) Separate Upper and lower nibble of the data value by using SEPARATOR function.
iv) Send higher nibble on higher nibble pins of port P1 and toggle the En pin.
v) Send lower nibble on higher nibble pins of port P1 and toggle the En pin.

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.

MOV A, #28H ; initialize. LCD 2 lines, 5x7 Matrix, 4 bit mode


ACALL CMDWRT ; Call command Subroutine
ACALL DELAY ; Give LCD some time.
MOV A, #0FH ; Display on, cursor blinking.
ACALL CMDWRT ; Call command Subroutine.
ACALL DELAY ; Give LCD some time.

MOV A, #01H ; Clear LCD.


ACALL CMDWRT ; Call command subroutine
ACALL DELAY ; Give LCD sometime

;-------------------------------------------------------------------------
; DISPLAYING DATA ON THE LCD

MOV A, #'S' ; Display letter S


ACALL DATAWRT ; Call Data command subroutine
ACALL DELAY ; Give LCD sometime

MOV A, #'E' ; Display letter E


ACALL DATAWRT ; Call Data command subroutine
ACALL DELAY ; Give LCD sometime

MOV A, #' ' ; Display space


ACALL DATAWRT ; Call Data command subroutine
ACALL DELAY ; Give LCD sometime

MOV A, #'I' ; Display letter I


ACALL DATAWRT ; Call Data command subroutine
ACALL DELAY ; Give LCD sometime

MOV A, #'T' ; Display letter T


ACALL DATAWRT ; Call Data command subroutine
ACALL DELAY ; Give LCD sometime
SJMP $

;--------------------------------------------------------------------------
; 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

MOV A, U ; send higher nibble first


MOV P1, A

SETB EN ; E=1 FOR HIGH PUSLSE


ACALL DELAY
CLR EN ; E=0 FOR H-TO-L PULSE
ACALL DELAY

MOV A, L ; send lower nibble


MOV P1, A
SETB EN ; E=1 FOR HIGH PUSLSE
ACALL DELAY
CLR EN ; E=0 FOR H-TO-L PULSE
ACALL DELAY

RET

;---------------------------------------------------------------------------
; WRITING DATA TO LCD

DATAWRT:
SETB RS ; RS=1 FOR DATA
; CLR RW ; R/W=0 F0R WRITE, DONE INITIALLY

ACALL SEPARATOR

MOV A, U ; send higher nibble first on P1


MOV P1, A

SETB EN ; E=1 FOR HIGH PUSLSE


ACALL DELAY
CLR EN ; E=0 FOR H-TO-L PULSE
ACALL DELAY

MOV A, L ; send lower nibble on P1


MOV P1, A

SETB EN ; E=1 FOR HIGH PUSLSE


ACALL DELAY
CLR EN ; E=0 FOR H-TO-L PULSE
ACALL DELAY

RET

;--------------------------------------------------------------------------
; DELAY SUBROUTINE
DELAY:
MOV R1, #10H

DBK: MOV R0, #0FH


DJNZ R0, $
DJNZ R1, DBK
RET

;---------------------------------------------------------------------------
END
;---------------------------------------------------------------------------

Potrebbero piacerti anche