Cypress PSoC Style AN2034 User Manual

An2034, User interface - keypad scan, psoc, Style

Advertising
background image



User Interface - Keypad Scan, PSoC

®

Style

January 16, 2009

Document No. 001-40409 Rev. *A

1

AN2034

Author: Dave Van Ess

Associated Project: Yes

Associated Part Family: CY8C20x34, CY8C21x23, CY8C21x34

CY8C23x33, CY8C24x23A, CY8C24x94

CY8C27x43, CY8C29x66

GET FREE SAMPLES HERE

Software Version: PSoC Designer™ 5.0
Associated Application Notes:

AN2354

Application Note Abstract

X–Y matrix keypads are an inexpensive interface enabling interaction with microcontroller-based products. This application
note shows how the PSoC® microcontroller’s unique I/O structure can build a keypad scan routine that is fast, uses minimal
RAM resources, and operates in a polled or interrupt mode. A function callable by either ‘C’ or assembly language is also
presented.

Introduction

An X-Y keypad enables use of N column lines and M row
lines to detect switch closures for N * M switches. For this
application note, a keypad is defined as an X-Y matrix
where only one key is pressed at a time, as opposed to a
keyboard where simultaneous key closures are the norm
([Ctrl] [Shift] [Delete]). This keypad definition is valid for
telephones, calculators, security entry kiosks, or other
products where only one key is pressed at a time.

This application relies on PSoC General Purpose Input
Output (GPIO).

Rows and Columns

This application note uses C columns and R rows.

Figure

1

shows an example of such a keypad:

Figure 1. 4-Column by 4-Row Keypad

C

0

C

1

C

2

C

3

R

0

R

1

R

2

R

3

[0,0]

[0,1]

[0,2]

[0,3]

[1,1]

[1,0]

[1,2]

[1,3]

[2,0]

[2,1]

[2,2]

[2,3]

[3,0]

[3,1]

[3,2]

[3,3]

Closure of switch [i, j] (column i, row j) enables current
flow from row j to column i. This keypad requires only eight
connections to the MCU. The 16 diodes can detect
multiple key closures. However, because PSoC
microcontroller reduces the cost of external components
such as op-amps, filters, and DACs, using 16 diodes is not
a good idea.

Well known techniques have been developed to detect
multiple key presses without diodes.

Figure 2

shows the

keypad without diodes.

Figure 2. The Keypad you can Afford

[0,0]

[0,1]

[0,2]

[0,3]

[1,1]

[1,0]

[1,2]

[1,3]

[2,0]

[2,1]

[2,2]

[2,3]

[3,0]

[3,1]

[3,2]

[3,3]

C

0

C

1

C

2

C

3

R

0

R

1

R

2

R

3

The standard algorithm for reading a keypad is to
individually drive each row and sample the status of all
columns. Correctly combining all this information enables
detection of at least two simultaneous switch closures.
The hardware cost is less but there is software overhead
required to scan all four rows, read column status, and
condense this information into an answer.

To develop a keypad scan that is low in both hardware
and software resources, limit its operation to single-key
presses.

[+] Feedback

[+] Feedback

Advertising