Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 447: Lecture 12 Keypads ECE 447: Lecture 10. ECE 447: Matrix Keypad.

Similar presentations


Presentation on theme: "ECE 447: Lecture 12 Keypads ECE 447: Lecture 10. ECE 447: Matrix Keypad."— Presentation transcript:

1 ECE 447: Lecture 12 Keypads ECE 447: Lecture 10

2 ECE 447: Matrix Keypad

3 ECE 447: Matrix Keypad Microcontroller Interface

4 1 1 1 1 ECE 447: Matrix Keypad - Scanning

5 Matrix Keypad - Scanning 1 1 1 1 ECE 447: Matrix Keypad - Scanning

6 Matrix Keypad - Scanning 0 1 1 1 ECE 447: Matrix Keypad - Scanning

7 Matrix Keypad - Scanning 1 0 1 1 ECE 447: Matrix Keypad - Scanning

8 Matrix Keypad - Scanning 1 1 0 1 ECE 447: Matrix Keypad - Scanning

9 Matrix Keypad - Scanning 1 1 1 0 ECE 447: Matrix Keypad - Scanning

10 Matrix Keypad - Scanning PC0 PC1 PC2 PC3 PC4 PC5 PC6 ECE 447: Matrix Keypad - Scanning

11 11110000 F0 inputs outputs ECE 447: Matrix Key Codes

12 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

13 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

14 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

15 11110000 F0 inputs ECE 447: Matrix Key Codes

16 11110000 F0 outputs ECE 447: Matrix Key Codes

17 Matrix Keypad - Scanning 0 0 0 0 1 1 1 outputs inputs ECE 447: Matrix Keypad - Scanning

18 Matrix Keypad - Scanning 0 0 0 0 1 1 1 outputs inputs ECE 447: Matrix Keypad - Scanning

19 Matrix Keypad - Scanning 0 0 0 0 1 1 1 outputs inputs ECE 447: Matrix Keypad - Scanning

20 Matrix Keypad - Scanning 0 0 0 0 0 1 1 outputs inputs ECE 447: Matrix Keypad - Scanning

21 Matrix Keypad - Scanning 1 1 1 0 0 1 1 outputs inputs ECE 447: Matrix Keypad - Scanning

22 Matrix Keypad - Scanning 1 1 1 0 0 1 1 outputs inputs ECE 447: Matrix Keypad - Scanning

23 Matrix Keypad - Scanning 1 1 0 1 1 1 0 outputs inputs ECE 447: Matrix Keypad - Scanning

24 Matrix Keypad - Scanning 1 1 0 1 1 1 0 outputs inputs ECE 447: Matrix Keypad - Scanning

25 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

26 11110000 F0 ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN ELEVEN TWELVE NONE ECE 447: Matrix Key Codes

27 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

28 Key Bouncing key bounce, t BOUNCE typically, t BOUNCE < 10 ms key bounce, t BOUNCE ECE 447: Key Bounce

29 Keypad Bouncing key bounce, t BOUNCE typically, t BOUNCE < 10 ms key bounce, t BOUNCE NONE ECE 447: Key Bounce

30 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

31 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

32 2 out of 7 Keypad C ECE 447: 2 of 7 Keypad

33 ECE 447: 2 of 7 Keypad Microcontroller Interface

34 C 0 ECE 447: 2 of 7 Keypad Scanning

35 2 out of 7 Keypad - Scanning C 0 11101110 101101 ECE 447: 2 of 7 Keypad Scanning

36 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

37 ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN ELEVEN TWELVE NONE ECE 447: 2 of 7 Key Codes

38 ECE 447: 2 of 7 Keypad Microcontroller Interface

39 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)

40 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

41 Key Debouncing in Hardware ECE 447: 2 of 7 Keypad Hardware Debounce

42 Key Debouncing in Hardware ECE 447: 2 of 7 Keypad Hardware Debounce Capacitors associated with all pull-up resistors


Download ppt "ECE 447: Lecture 12 Keypads ECE 447: Lecture 10. ECE 447: Matrix Keypad."

Similar presentations


Ads by Google