ECE 447: Lecture 12 Keypads ECE 447: Lecture 10
ECE 447: Matrix Keypad
ECE 447: Matrix Keypad Microcontroller Interface
ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning PC0 PC1 PC2 PC3 PC4 PC5 PC6 ECE 447: Matrix Keypad - Scanning
F0 inputs outputs ECE 447: Matrix Key Codes
while (1) { do ( PORTC = "XXXX0000" while ( PORTC = "X111XXXX"); c=decode_key();..... do something dependent on the key being pressed... PORTC = "XXXX0000" while (PORTC != "X111XXXX") /* do nothing */ } Wait until any key pressed Wait until all keys released Decode the key being pressed ECE 447: Key Scanning Function
int decode_key() { PORTC = "XXXX1110" if ( PORTC != "X111XXXX”) return decode_output (PORTC, 1) else { PORTC = "XXXX1101" if ( PORTC != "X111XXXX") return decode_output(PORTC, 2) } else { PORTC = "XXXX1011" if ( PORTC != "X111XXXX") return decode_output (PORTC, 3) } else { PORTC = "XXXX0111" if ( PORTC != "X111XXXX") return decode_output (PORTC, 4) else return NONE_KEY_PRESSED; } check Row 1 check Row 2 check Row 3 check Row 4 ECE 447: Key Scanning Function
Possible Key Decoding Procedure (3) Decoding a column XCCCXXXX Three bits of interest Three combinations valid (“110”, “101”, “011”) Decoding column possible ECE 447: Key Scanning Function
F0 inputs ECE 447: Matrix Key Codes
F0 outputs ECE 447: Matrix Key Codes
Matrix Keypad - Scanning outputs inputs ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning outputs inputs ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning outputs inputs ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning outputs inputs ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning outputs inputs ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning outputs inputs ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning outputs inputs ECE 447: Matrix Keypad - Scanning
Matrix Keypad - Scanning outputs inputs ECE 447: Matrix Keypad - Scanning
decode_key() { unsigned char keys = [NONE, ONE, TWO, …, TWELVE]; for (i=0, i<=12, i++) { PORTC = keys[i] if (PORTC == keys[i] return i; } return UNKNOWN; } Simplified Key Decoding Procedure (4) ECE 447: Key Scanning Function – Alternative
F0 ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN ELEVEN TWELVE NONE ECE 447: Matrix Key Codes
while (1) { do ( PORTC = "XXXX0000" while ( PORTC = "X111XXXX"); c=decode_key();..... do something dependent on the key being pressed... PORTC = "XXXX0000" while (PORTC != "X111XXXX") /* do nothing */ } Wait until any key pressed Wait until all keys released Decode the key being pressed ECE 447: Key Scanning Function – No Debounce
Key Bouncing key bounce, t BOUNCE typically, t BOUNCE < 10 ms key bounce, t BOUNCE ECE 447: Key Bounce
Keypad Bouncing key bounce, t BOUNCE typically, t BOUNCE < 10 ms key bounce, t BOUNCE NONE ECE 447: Key Bounce
Keypad Debouncing in Software key bounce, t BOUNCE typically, t BOUNCE < 10 ms wait debouncing period key bounce, t BOUNCE decode_key; action dependent on the key wait until any key pressed wait debouncing period wait until all keys released wait until any key pressed NONE ECE 447: Key Bounce
Key Decoding Procedure (7) while (1) { while (key_decode() == NONE) /* do nothing */ ; wait debouncing period(); c=decode_key();..... do something dependent on the key being pressed... while(key_decode()!=NONE) /* do nothing */ ; wait debouncing period(); } Wait until any key pressed Wait until all keys released Decode the key being pressed ECE 447: Key Scanning Function – with Debounce
2 out of 7 Keypad C ECE 447: 2 of 7 Keypad
ECE 447: 2 of 7 Keypad Microcontroller Interface
C 0 ECE 447: 2 of 7 Keypad Scanning
2 out of 7 Keypad - Scanning C ECE 447: 2 of 7 Keypad Scanning
decode_key() { unsigned char keys = [NONE, ONE, TWO, …, TWELVE]; for (i=0, i<=12, i++) { PORTC = keys[i] if (PORTC == keys[i] return i; } return UNKNOWN; } ECE 447: 2 of 7 Keypad Scanning Function
ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN ELEVEN TWELVE NONE ECE 447: 2 of 7 Key Codes
ECE 447: 2 of 7 Keypad Microcontroller Interface
decode_key() { unsigned char keys = [NONE, ONE, TWO, …, TWELVE]; code = PORTC for (i=0, i<=12, i++) { if (code == keys[i] return i; } return UNKNOWN; } ECE 447: 2 of 7 Keypad Scanning Function (Simplified)
while (1) { while (decode_key() == NONE) /* do nothing */ ; wait debouncing period(); c=decode_key();..... do something dependent on the key being pressed... while(decode_key()!=NONE) /* do nothing */ ; wait debouncing period(); } Wait until any key pressed Wait until all keys released Decode the key being pressed ECE 447: 2 of 7 Keypad Scanning Function
Key Debouncing in Hardware ECE 447: 2 of 7 Keypad Hardware Debounce
Key Debouncing in Hardware ECE 447: 2 of 7 Keypad Hardware Debounce Capacitors associated with all pull-up resistors