Download Print this page

Cypress Semiconductor PSoC Style AN2034 Specification Sheet

User interface - keypad scan, psoc style

Advertisement

Quick Links

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.
1
shows an example of such a keypad:
Figure 1. 4-Column by 4-Row Keypad
C
C
0
R
0
[0,0]
[1,0]
R
1
[0,1]
[1,1]
R
2
[0,2]
[1,2]
R
3
[0,3]
[1,3]
January 16, 2009
User Interface - Keypad Scan, PSoC
Associated Part Family: CY8C20x34, CY8C21x23, CY8C21x34
Figure
C
C
1
2
3
[2,0]
[3,0]
[2,1]
[3,1]
[2,2]
[3,2]
[2,3]
[3,3]
Document No. 001-40409 Rev. *A
CY8C23x33, CY8C24x23A, CY8C24x94
CY8C27x43, CY8C29x66
GET FREE SAMPLES HERE
Software Version: PSoC Designer™ 5.0
Associated Application Notes:
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.
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.
keypad without diodes.
Figure 2. The Keypad you can Afford
C
C
0
R
0
[0,0]
[1,0]
R
1
[0,1]
[1,1]
R
2
[0,2]
[1,2]
R
3
[0,3]
[1,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.
®
Style
AN2034
Author: Dave Van Ess
Associated Project: Yes
AN2354
However,
because
PSoC
Figure 2
shows the
C
C
1
2
3
[2,0]
[3,0]
[2,1]
[3,1]
[2,2]
[3,2]
[2,3]
[3,3]
1
[+] Feedback
[+] Feedback

Advertisement

loading
Need help?

Need help?

Do you have a question about the PSoC Style AN2034 and is the answer not in the manual?

Questions and answers

Summary of Contents for Cypress Semiconductor PSoC Style AN2034

  • Page 1 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.
  • Page 2 PSOC General Purpose IO To detect single-switch closures, use the following algorithm: Drive all rows simultaneously and read the columns. Drive all columns simultaneously and read the rows. Condense this data to determine switch-closure status. The structure of the general purpose of each pin simplifies this bipolar use of rows and columns.
  • Page 3: Using The Output

    Code 1: Subroutine for Reading Keypad ;----------------------------------------- Keypad.asm This routine reads a 4 column by 4 row keypad on port1. The status of key closures is returned in A. P1.4 P1.5 P1.6 P1.7 ; P1.0 R0 --+----+----+----+- ; P1.1 R1 --+----+----+----+- ;...
  • Page 4 Example Code 3 is the main function that implements the design in on page 3. Figure 5 Code 3. Keypad Project Implemented ;----------------------------------------- ; This program reads the keypad ; at port 1 and control the LEDs ; on port0. ;...
  • Page 5: Document History

    Document History Document Title: User Interface – Keypad Scan, PSoC Document Number: 001-40409 Revision Orig. of Submission Change 1532004 OGNE 10/02/07 2640952 01/20/09 In March of 2007, Cypress recataloged all of its Application Notes using a new documentation number and revision code. This new documentation number and revision code (001-xxxxx, beginning with rev.