FA21 - Lec15 - 2021-11-03 - Keypad Interfacing
FA21 - Lec15 - 2021-11-03 - Keypad Interfacing
Interfacing
LECTURE# 15
MICROPROCESSOR SYSTEMS AND INTERFACING
F E D C
F E D C
Drive High
1
B A 9 8
1
F E D C
0 0 0 0
Drive Low
Observe
B A 9 8
H
F E D C
0 0 0 0
Drive Low
H means that the line will maintain its logic high value when undriven
0 means that the line is driven low due to a key pressed
Drive Low
0
B A 9 8
0
F E D C
1 1 1 1
Drive High
Drive Low
0
B A 9 8
0
F E D C
H 0 H H
Observe
H means that the line will maintain its logic high value when undriven
0 means that the line is driven low due to a key pressed
Drive Low
0
H H H H
Always observe
Drive Low
0
H 0 H H
Always observe
Drive Low
Wait for a few milliseconds 0
Always observe
Drive Low
◦ No key is pressed on this row
◦ Check next row 1
H H H H
Always observe
Drive Low
◦ No key is pressed on this row
◦ Check next row 1
Always observe
Drive Low
1
H 0 H H
Always observe
2. Validate key press Wait for already Read all columns Ground next row
key press release
3. Identify key press No Read all columns
Identify the
All keys open? pressed key
4. Decode key press Yes No Any key press (Find the column
in this row?
and row of
Yes pressed key)
Detect Key press
Find which key is
Read all columns pressed
(continue only if a
key is pressed) Get the key ascii
No Any key Decode
down? or number
Yes
Return
Validate Key Wait for debounce
press
Read all columns
(continue only if
legitimate key is
No Any key Yes
pressed, and not
down?
a glitch)
3 OUT KEY_DDR,R20
GROUND_ALL_ROWS:
4 LDI R20,0x0F
5 OUT KEY_PORT,R20
Rows WAIT_FOR_RELEASE:
6 NOP
7 IN R21,KEY_PIN ;read key pins
ANDI R21,0x0F ;mask unused bits
CPI R21,0x0F ;(equal if no key)
BRNE WAIT_FOR_RELEASE ;do again until keys released
Detect
ANDI R21,0x0F ;mask unused bits
CPI R21,0x0F ;(equal if no key)
BREQ WAIT_FOR_KEY ;do again until a key pressed
Validate
IN R21,KEY_PIN ;read key pins
ANDI R21,0x0F ;mask unused bits
CPI R21,0x0F ;(equal if no key)
BREQ WAIT_FOR_KEY ;do again until a key pressed