0% found this document useful (0 votes)
15 views19 pages

Interfacing

This document covers the fundamentals of 8051 assembly programming, focusing on LCD and keyboard interfacing. It includes detailed instructions for programming the LCD, including command and data writing, as well as keyboard interfacing techniques to read key presses. The document also provides example code snippets for practical implementation of these concepts.

Uploaded by

aditya14201
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views19 pages

Interfacing

This document covers the fundamentals of 8051 assembly programming, focusing on LCD and keyboard interfacing. It includes detailed instructions for programming the LCD, including command and data writing, as well as keyboard interfacing techniques to read key presses. The document also provides example code snippets for practical implementation of these concepts.

Uploaded by

aditya14201
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

UNIT V

•Introduction to 8051 assembly programming,

•Assembling and running an 8051 program, Data types and Assembler directives,

•Arithmetic, logic instructions and programs,

•Jump, loop and call instructions, IO port programming.

•Programming 8051 Timers.

•Serial Port Programming, Interrupts Programming,

•Interfacing: LCD & Keyboard Interfacing, ADC, DAC & Sensor Interfacing,

•External Memory Interface, Stepper Motor and Waveform generation.

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
LCD AND KEYBOARD INTERFACING
• LCD is finding widespread use replacing LEDs
• The declining prices of LCD
• The ability to display numbers, characters and graphics
• Incorporation of a refreshing controller into the LCD, thereby relieving the
CPU of the task of refreshing the LCD
• Ease of programming for characters and graphics

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
PIN DESCRIPTION OF LCD

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
LCD CONNECTIONS

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
• To send any of the commands to the LCD, make pin RS=0.
• For data, make RS=1.
• Then send a high-to-low pulse to the E pin to enable the internal latch of the
LCD. This is shown in the code below.
• ;calls a time delay before sending next data/command

• ;P1.0-P1.7 are connected to LCD data pins D0-D7


• ;P2.0 is connected to RS pin of LCD
• ;P2.1 is connected to R/W pin of LCD
• ;P2.2 is connected to E pin of LCD

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
• ORG 0H
• MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#0EH ;display on, cursor on
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#01 ;clear LCD
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#06H ;shift cursor right
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#84H ;cursor at line 1, pos. 4
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
• MOV A,#’N’ ;display letter N
• ACALL DATAWRT ;call display subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#’O’ ;display letter O
• ACALL DATAWRT ;call display subroutine
• AGAIN: SJMP AGAIN ;stay here
COMNWRT: ;send command to LCD
• MOV P1,A ;copy reg A to port 1
• CLR P2.0 ;RS=0 for command
• CLR P2.1 ;R/W=0 for write
• SETB P2.2 ;E=1 for high pulse
• ACALL DELAY ;give LCD some time
• CLR P2.2 ;E=0 for H-to-L pulse
• RET
Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
DATAWRT: ;write data to LCD
• MOV P1,A ;copy reg A to port 1
• SETB P2.0 ;RS=1 for data
• CLR P2.1 ;R/W=0 for write
• SETB P2.2 ;E=1 for high pulse
• ACALL DELAY ;give LCD some time
• CLR P2.2 ;E=0 for H-to-L pulse
• RET

DELAY:
• MOV R3,#50 ;50 or higher for fast CPUs
• HERE2: MOV R4,#255 ;R4 = 255
• HERE: DJNZ R4,HERE ;stay until R4 becomes 0
• DJNZ R3,HERE2
• RET
• END
Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
KEYBOARD INTERFACING

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
KEYBOARD PROGRAM
This program sends the ASCII code for pressed key to P0.1
;P1.0-P1.3 connected to rows,
P2.0-P2.3 to column
MOV P2,#0FFH ;make P2 an input port K1:
MOV P1,#0 ;ground all rows at once
MOV A,P2 ;read all col ;(ensure keys open)
ANL A,00001111B ;masked unused bits
CJNE A,#00001111B,K1 ;till all keys release
K2: ACALL DELAY ;call 20 msec delay
MOV A,P2 ;see if any key is pressed
ANL A,00001111B ;mask unused bits
CJNE A,#00001111B,OVER;key pressed, find row
SJMP K2 ;check till key pressed

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
KEYBOARD PROGRAM
OVER: ACALL DELAY ;wait 20 msec debounce time
MOV A,P2 ;check key closure
ANL A,00001111B ;mask unused bits
CJNE A,#00001111B,OVER1;key pressed, find
row
SJMP K2 ;if none, keep polling

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET
KEYBOARD PROGRAM
OVER1: MOV P1, #11111110B ;ground row 0
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_0 ;key row 0, find
col.
MOV P1,#11111101B ;ground row 1
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_1 ;key row 1, find
col.
MOV P1,#11111011B ;ground row 2
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_2 ;key row 2, find
col.
MOV P1,#11110111B ;ground row 3
MOV A,P2 ;read all columns Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal,
ECE Department, GCET
KEYBOARD PROGRAM

ROW_0: MOV DPTR,#KCODE0 ;set DPTR=start of row 0


SJMP FIND ;find col. Key belongs to

ROW_1: MOV DPTR,#KCODE1 ;set DPTR=start of row


SJMP FIND ;find col. Key belongs to

ROW_2: MOV DPTR,#KCODE2 ;set DPTR=start of row 2


SJMP FIND ;find col. Key belongs to

ROW_3: MOV DPTR,#KCODE3 ;set DPTR=start of row 3

FIND: RRC A ;see if any CY bit low


JNC MATCH ;if zero, get ASCII code
INC DPTR ;point to next col. Addr
SJMP FIND ;keep searching
Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal,
ECE Department, GCET
KEYBOARD PROGRAM

MATCH: CLR A ;set A=0 (match is found)


MOVC A,@A+DPTR ;get ASCII from table
MOV P0,A ;display pressed key
LJMP K1 ;ASCII LOOK-UP TABLE FOR EACH ROW

ORG 300H
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

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal,


ECE Department, GCET
THE END

Unit-5(LCD & KeyBoard Interfacing) , Asst. Prof. Sakshi Mittal, ECE Department, GCET

You might also like