You are on page 1of 4

[11.] WAP IN ASSEMBLY LANGUAGE TO DISPLAY A CHARACTER OR A STRING OF CHARACTERS ON A L.C.D.

SCREEN IN
8051

ORG 00H
MOV P2, #0FFH

/Make Port 2 as Input-Port

K1: MOV P1, #00H

/Ground all Rows at once

MOV A, P2

/Read all Columns

;-----------------------------------------------Ensure Keys are Open----------------------------------------------------------------------------------------------ANL A, #0FH

/Mask unused bits

CJNE A, #0FH, K1

/Till all keys release

K2: ACALL DELAY_KEY

/Call 20 msec Delay

;--------------------------------------------Check if any Key is Pressed-------------------------------------------------------------------------------------------MOV A, P2

/See if any key is pressed

ANL A, #0FH

/Mask unused bits

CJNE A, #0FH, OVER

/Key pressed, Find row

SJMP K2

/Check till key pressed

OVER: ACALL DELAY_KEY

/Wait 20 msec [Debounce-Time]

;--------------------------------------------Check if any Key is Closed-------------------------------------------------------------------------------------------MOV A, P2

/Check if key is closed

ANL A, #0FH

/Mask unused bits

CJNE A, #0FH, OVER1

/Key pressed, Find row

SJMP K2

/If none, Keep polling

OVER1:
MOV P1, #0FEH

/Ground Row 0

MOV A, P2

/Read all columns

ANL A, #0FH

/Mask unused bits

CJNE A, #0FH, ROW_0

/Key Row 0, Find Column

MOV P1, #0FDH

/Ground Row 1

MOV A, P2

/Read all Columns

ANL A, #0FH

/Mask unused bits

CJNE A, #0FH, ROW_1

/Key Row 1, Find Column

MOV P1, #0FBH

/Ground Row 2

MOV A, P2

/Read all Columns

ANL A, #0FH

/Mask unused bits

CJNE A, #0FH, ROW_2

/Key Row 2, Find Column

MOV P1, #0F7H

/Ground Row 3

MOV A, P2

/Read all Columns

ANL A, #0FH

/Mask unused bits

CJNE A, #0FH, ROW_3

/Key Row 3, Find Column

LJMP K2

/If none, False-Input, Repeat

;--------------------------------------Check which Column the Key belongs to---------------------------------------------------------------------------------ROW_0: MOV DPTR, #KCODE0

/Set DPTR=Start of Row 0

SJMP FIND

/Find which Column the Key belongs to

ROW_1: MOV DPTR, #KCODE1

/Set DPTR=Start of Row 1

SJMP FIND

/Find which Column the Key belongs to

ROW_2: MOV DPTR, #KCODE2

/Set DPTR=Start of Row 2

SJMP FIND

/Find which Column the Key belongs to

ROW_3: MOV DPTR, #KCODE3

/Set DPTR=Start of Row 3

FIND: RRC A

/See if Carry (CY) bit is Low

JNC MATCH

/If Zero, Get ASCII-Code

INC DPTR

/Point to next Column Address

SJMP FIND

/Keep Searching

MATCH: CLR A

/Clear Accumulator when Match is found

MOVC A,@A+DPTR

/Get ASCII value from table

MOV R7, A

/Display the pressed key

ACALL DISPLAY
LJMP K1

DELAY_KEY:
MOV R0, #0FFH
HERE3: MOV R1, #0FFH
HERE4: DJNZ R1, HERE4

DJNZ R0, HERE3


RET
;-----------------------------------------------------L.C.D. Program for Display----------------------------------------------------------------------------------DISPLAY:
RS BIT P3.5

/Assigning Control-Pins of Port 2 to LCD

RW BIT P3.6
EN BIT P3.7
;--------------------------------------------------------L.C.D Initialization-----------------------------------------------------------------------------------------HERE: MOV P1, #38H

/Command for 2 Lines and 5x7 Matrix

ACALL Send_Command
MOV P1, #0EH

/Display On, Cursor blinking

ACALL Send_Command
MOV P1, #01H

/Clear Display-Screen

ACALL Send_Command
;--------------------------------------------------Printing a Character or String-----------------------------------------------------------------------------------MOV A, R7
MOV P0, A
ACALL Send_Data
;-------------------------------------------------------DELAY-Subroutine-----------------------------------------------------------------------------------------DELAY_LCD:

/Delay for 2.55 msec

MOV R0, #10H


HERE2: MOV R1, #0FFH
HERE1: DJNZ R1, HERE1
DJNZ R0, HERE2
RET

/Return from DELAY-Loop

;--------------------------------------Subroutine for sending Command to LCD for Control------------------------------------------------------------------Send_Command:


CLR RW

/Clear RW to Write to LCD

CLR RS

/Clear RS to send a Command to LCD

SETB EN

/Set EN (Enable) to Latch the data to LCD

ACALL DELAY
CLR EN
RET

/Clear EN (Enable) to stop Latching

;----------------------------------------Subroutine for sending Data to LCD for Display----------------------------------------------------------------------Send_Data:


CLR RW

/Clear RW to Write to LCD

SETB RS

/Set RS to send a Data to LCD

SETB EN

/Set EN (Enable) to Latch the data to LCD

ACALL DELAY
CLR EN

/Clear EN (Enable) to stop Latching

RET
;-----------------------------------------------ASCII Look-Up Table for each Row-----------------------------------------------------------------------------ORG 800H
KCODE0: DB '0', '1', '2', '3'

/ROW 0

KCODE1: DB '4', '5', '6', '7'

/ROW 1

KCODE2: DB '8', '9', 'A', 'B'

/ROW 2

KCODE3: DB 'C', 'D', 'E', 'F'

/ROW 3

END

You might also like