Beruflich Dokumente
Kultur Dokumente
INTERFACING
Chung-Ping Young
楊中平
P2.2
and Data to
LCDs w/ Busy E
(cont’)
RS
tAH = Hold time after E has
come down for both RS and
R/W = 10 ns (minimum)
Data
Sending Codes tH = Data hold time
and Data to tH = 10 ns (minimum)
LCDs w/ Busy E tDSW
(cont’)
RS
tAH = Hold time after E has
come down for both RS and
R/W = 10 ns (minimum)
MOVC JZ SEND_DAT
Instruction
SJMP C1
SEND_DAT:
MOV DPTR,#MYDATA
D1: CLR A
MOVC A,@A+DPTR
ACALL DATAWRT ;call command subroutine
ACALL DELAY ;give LCD some time
INC DPTR
JZ AGAIN
SJMP D1
AGAIN: SJMP AGAIN ;stay here
.....
Sending Solution:
rw = 1;
Sending while(busy==1){ //wait here for busy flag
en = 0; //strobe the enable pin
Information to MSDelay(1);
LCD Using en = 1;
}
MOVC
Instruction void lcddata(unsigned int itime){
unsigned int i, j;
(cont’) for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
3 2 1 0
D0
7 6 5 4
D1 If no key has
B A 9 8 been pressed,
If all the rows are D2 reading the
grounded and a key F E D C input port will
is pressed, one of D3 yield 1s for all
the columns will columns since
have 0 since the key Port 1 they are all
pressed provides the connected to
(Out) D3 D2 D1 D0 Port 2
path to ground high (Vcc)
(In)
Department of Computer Science and Information Engineering
HANEL National Cheng Kung University, TAIWAN 18
It is the function of the microcontroller
KEYBOARD to scan the keyboard continuously to
INTERFACING detect and identify the key pressed
To detect a pressed key, the
Grounding microcontroller grounds all rows by
Rows and providing 0 to the output latch, then it
Reading reads the columns
Columns ¾ If the data read from columns is D3 – D0 =
1111, no key has been pressed and the
process continues till key press is detected
¾ If one of the column bits has a zero, this
means that a key press has occurred
For example, if D3 – D0 = 1101, this means that
a key in the D1 column has been pressed
After detecting a key press, microcontroller will
go through the process of identifying the key
3 2 1 0
D0
7 6 5 4
D1
B A 9 8
D2
F E D C
D3
Vcc
Port 1
(Out) D3 D2 D1 D0 Port 2
(In)
yes
no no All keys
1 down?
yes
Grounding
Rows and no All keys
down?
Reading
yes
Columns
(cont’) Find which key
is pressed
Return
Columns
INC DPTR ;point to next col. addr
SJMP FIND ;keep searching
(cont’) 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