The document discusses the interfacing of a keypad with a microcomputer system, detailing how rows and columns of the keypad are connected to input and output ports. It outlines an algorithm for identifying pressed keys using pull-up resistors and lookup tables to manage non-linear key values. Additionally, it provides a program structure and flowchart for monitoring key presses and displaying the corresponding hexadecimal value on a data display unit.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views31 pages
Micro computer
The document discusses the interfacing of a keypad with a microcomputer system, detailing how rows and columns of the keypad are connected to input and output ports. It outlines an algorithm for identifying pressed keys using pull-up resistors and lookup tables to manage non-linear key values. Additionally, it provides a program structure and flowchart for monitoring key presses and displaying the corresponding hexadecimal value on a data display unit.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31
Keypad Interfacing
Another key area where parallel I/O Ports
are applied is the Interfacing of a keypad to a microcomputer Systems.
A keypad consists of labelled switches
arranged in rows and columns. They come in various sizes i.e. 4x4 , 4x6 etc. Keypad Interfacing.. The Columns are normally connected to an Output port while the rows are connected to an input port.
Pressing a key basically makes a connection
between a row and column as illustrated in the following diagrams that show how the MPT 809 keypad is interfaced to the microcomputer system.. Keypad Interfacing.. Keypad Interfacing.. Identifying a Pressed Key The pull-up resistors play a key role in this process. With the Input (rows) port presenting a very high impedance when there is no key pressed they ensure logic 1 is maintained on each row i.e. each bit of the rows input port is at logic 1 when there is no key pressed. The algorithm for identifying a pressed key is as follows: Identifying a Pressed Key.. 1. Ground all keypad columns by sending logic 0 to each output bit of the keypad columns port. 2. Monitor (Read) the keypad rows input port bits status. When no key is pressed all the rows will be at logic 1 hence keep monitoring the keypad rows input port. However when a key is pressed one of the rows will be at logic 0. As such go to the following step. Identifying a Pressed Key.. 3. Ground only one column at a time. 4. Read the keypad rows input port bits status. If the pressed key is NOT in the only current grounded column all the rows input port bits will be at logic 1 hence repeat from step 3 with the next column for grounding. In case the pressed key is in the grounded column the pressed key row will be at logic 0 and the pressed key is therefore identified. Repeat from step 1 for the next pressed key monitoring. Identifying a Pressed Key.. In other words a pressed key is identified by identifying the column and row where it is located. From the above algorithm the only current grounded column is known and the row that returns logic 0 can also be determined. Identifying a Pressed Key.. Example: Develop a program that monitors the MPT 809 keypad for a pressed hexadecimal key (0 to F) and displays the pressed key onto the data display unit. Information to the Data display unit is sent by sending the content of the accumulator to the permanently defined Output Port at I/O port address 00H i.e. OUT 00H. Identifying a Pressed Key.. Keypad Hex Bit pattern to Expected Scan Code Key ground only the Rows Input (Hex) Column where port bit the key is located Status (Hex) when the key is pressed 0 0E 07 E7 1 0D 07 D7 2 0B 07 B7 3 07 07 77 4 0E 0B EB 5 0D 0B DB 6 0B 0B BB 7 07 0B 7B 8 0E 0D ED 9 0D 0D DD A 0B 0D BD B 07 0D 7D C 0E 0E EE D 0D 0E DE E 0B 0E BE F 07 0E 7E Identifying a Pressed Key.. As can be seen from the columns values there is no linearity on change of values for keys 0 to 3. It starts from value 0EH to 0DH, a decrease by 1 from key 0 to 1, then decrease by 2 from key 1 to 2, and decreases by 4 from key 2 to 3. As such a simple loop can not be used to determine the next value. The same applies to expected rows bit Status. Identifying a Pressed Key.. To resolve this non-linearity problem Lookup tables are employed.
A lookup table is basically a single
Column matrix (or a one-dimension array) located in a computer memory block containing desired values. Identifying a Pressed Key.. In this example we can use two Lookup tables i.e. One for column values and one for expected rows status values. It is also possible to use a Single Lookup table that contains keypad Scan Codes – Do this as Homework Keypad Ground Column Data Lookup Table Label Mnemonic Comment CLMDAT: ;Ground Column bit pattern for Key 0 DB 0EH ;Ground Column bit pattern for Key 1 DB 0DH ;Ground Column bit pattern for Key 2 DB 0BH ;Ground Column bit pattern for Key 3 DB 07H ;Ground Column bit pattern for Key 4 DB 0EH ;Ground Column bit pattern for Key 5 DB 0DH ;Ground Column bit pattern for Key 6 DB 0BH ;Ground Column bit pattern for Key 7 DB 07H ;Ground Column bit pattern for Key 8 DB 0EH ;Ground Column bit pattern for Key 9 DB 0DH ;Ground Column bit pattern for Key A DB 0BH ;Ground Column bit pattern for Key B DB 07H ;Ground Column bit pattern for Key C DB 0EH ;Ground Column bit pattern for Key D DB 0DH ;Ground Column bit pattern for Key E DB 0BH ;Ground Column bit pattern for Key F DB 07H Keypad Expected Rows Status Data Lookup Table Label Mnemonic Comment
ROWDAT: DB 07H,07H,07H,07H ;Expected Rows Status for keys 0,1,2,3
DB 0BH,0BH,0BH,0BH ;Expected Rows Status for keys 4,5,6,7
DB 0DH,0DH,0DH,0DH ;Expected Rows Status for keys 8,9,A,B
DB 0EH,0EH,0EH,0EH ;Expected Rows Status for keys C,D,E,F
Identifying a Pressed Key.. With the two Lookup tables a loop can be used to identify a pressed key. Basically key 0 is checked first followed by key 1, 2 etc. For each key being checked the key Ground Column bit pastern is retrieved from the Columns Data Lookup table and sent to the keypad columns port. The rows status is then read and compared to the expected rows status data in the Rows Data lookup table. If the read status matches the expected Rows status the pressed key has been identified. Flow Chart Flow Chart Blocks Text 1. Define Port A as Output and Port C as Input 2. Any Key Pressed? 3. Initialize Current Key to be checked 4. Point to Top of Columns and Rows Data Lookup Tables 5. Fetch Ground Column Data for Current Check Key. Flow Chart Blocks Text 6. Ground only the Column for current check Key. 7. Read the Rows Status. 8. Is the Current Check key Pressed? 9. Are all keys checked? 10. Update Current Check key. Point to next Location for both Lookup Tables 11. Display the pressed Key. Identifying a Pressed Key.. The Program Header Label Mnemonic Comment NAME KEYPAD ;Program Name
CLMPRT EQU 40H ;8255 PPI Port A (Columns Port) Address
;on the MPT 809
ROWPRT EQU 42H ;8255 PPI Port C (Rows Port) Address
CTREG EQU 43H ;8255 PPI Control Register Address
DISPLY EQU 00H ;Data Display Unit Output Port Address
ORG 0C100H ;Program Starting Address
Identifying a Pressed Key.. Stack and Port Direction Definition LXI SP,0C200H ;Initialise Stack Pointer
MVI A,89H ;The bit Pattern to
OUT CTREG ;Define Port A as Output and Port C
;as Input Identifying a Pressed Key.. Monitoring Keypad Section MONITA: MVI A,00H ;The Bit Pattern to
OUT CLMPRT ;Ground all keypad columns
IN ROWPRT ;Read the Keypad Rows Status
ANI 0FH ;Mask Off Upper nibble i.e. Rows
;connected ;to the 4 Least significant ;bits of Port C
CPI 0FH ;Is any key pressed?
JZ MONITA ;No – Keep Monitoring the keypad
Identifying a Pressed Key.. Initialisation Section MVI C,10H ;Total Number (16) of keys to check
MVI B,00H ;Initialise current key to be checked
LXI D,CLMDAT ;Point to Top of ground Columns bit
;pattern Lookup Table
LXI H,ROWDAT ;Point to Top of expected Rows Status
;bit ;pattern Lookup Table Identifying a Pressed Key.. Determining whether Current Key is Pressed GRNDAT: LDAX D ;Get current check key Ground Column ;bit pattern OUT CLMPRT ;Ground only the current check key ;column IN ROWPRT ;Read the keypad rows status
ANI 0FH ;Mask Off Upper nibble i.e. Rows
;connected to 4 Least significant bits ;of Port C
CMP M ;Is the Current Check key the one
;pressed? JZ SHOW ;Yes – display the current check key Identifying a Pressed Key.. Check Key Loop Control Section DCR C ;Have all the hexadecimal keys Checked?
JZ MONITA ;Yes – Start all over again
INX D ;Point to Ground Column pattern for the
;next key INX H ;Point to expected Rows pattern for the ;next ;check key
INR B ;Update current check key to next key
JMP GRNDAT ;Process the new current check key
Identifying a Pressed Key.. Display Identified Key Section SHOW: MOV A,B ;Get the current check key identified ;as pressed
OUT DISPLY ;Display the identified pressed key
;on The Data Display Unit
JMP MONITA ;Continue Monitoring the keypad
Identifying a Pressed Key.. Ground Column Bit pattern Lookup Table Section CLMDAT: DB 0EH,0DH,0BH,07H ;Ground Column bit pattern for ;keys 0,1,2,3
DB 0EH,0DH,0BH,07H ;Ground Column bit pattern
;for keys 4,5,6,7
DB 0EH,0DH,0BH,07H ;Ground Column bit pattern for
;keys 8,9,A,B
DB 0EH,0DH,0BH,07H ;Ground Column bit pattern for
;keys C,D,E,F Identifying a Pressed Key.. Expected Rows Status Bit Pattern Lookup Table Section
ROWDAT: DB 07H,07H,07H,07H ;Expected Rows Status for
;keys 0,1,2,3
DB 0BH,0BH,0BH,0BH ;Expected Rows Status for
;keys 4,5,6,7
DB 0DH,0DH,0DH,0DH ;Expected Rows Status for
;keys 8,9,A,B
DB 0EH,0EH,0EH,0EH ;Expected Rows Status for
;keys C,D,E,F Key Pressed Verification The Is Key pressed decision Block can be expanded in order to avoid multiple identification of the same key press, debouncing or just a transient. When a human being presses a key the CPU, when running the example program, can identify that key press thousands of times before the key is released.
The following Flow chart shows how this is done.
Key Pressed Verification.. Exercise 1. Modify the Example program such that the Key press Verification is implemented. 2. Modify the example program with key pressed verification such that on displaying the pressed the previous pressed key display moves left to make room for the new pressed key. In other words the Data display unit always displays the last two pressed hex digits. 3. Modify the Example program such that it uses a Single Lookup Table that contains key Scan Codes