Subscribe to EDN
RSS
Reprints/License
Print
Email

Key-reading circuit saves I/O pins

Edited by Bill Travis

Gustavo Santaolalla, Digital Precision Systems, Buenos Aires, Argentina -- EDN, March 6, 2003

Some microcontroller applications usually use too many I/O pins to read keys or onboard switches; in many cases, few pins remain available for other uses. Some alternative ways to read keys yield more free pins. First, consider some ways to effect key reading. Table 1 presents a comparison of four methods with references to circuit configurations (Figure 1, Figure 2, Figure 3 and Figure 4). As you can see, the best choice for reading many keys is to use the A/D converter that is inherent in many microcontrollers. This option needs many lines of code and is not amenable to resistive buttons, such as flexible key pads (Reference 1). Another option is to read one key with one I/O port, but it needs as many pins as the keys to read.

Figure 4 shows another possibility, the subject of this Design Idea. In this configuration, the microcontroller reads six keys with only three lines of I/O pins. This method entails the use of a few external components. The idea is to turn one of the three lines into output, set it at logic 1, and use the other two lines as inputs. Then, the microcontroller scans each input for a logic 1, and, if it finds it, a key press has occurred. If not, it turns the next line into an output, sets it, and turns the other two into inputs, and so on. In this way, you can confirm each time a key press takes place. R4, R5, and R6 are current-limiting resistors, and R1, R2, and R3 are simple pulldown resistors. The circuit uses three LEDs for debugging.

Listing 1 shows the complete program. An MC68HC908JK3 tested the software, but the routine is probably applicable to other microcontrollers. The program has no debounce function; you can add it for a real application. The program shows the variable KeyVal on three LEDs. You can probably write more efficient code that that of Listing 1; the code shown is just for testing. Table 1 shows how many pins you need to read 16 keys. As you can see, with the circuit in Figure 4, you need only five pins, but you can add four more keys.

Is this the best Design Idea in this issue? Select at www.edn.com.


Reference
  1. Motorola application note AN1775, www.motorola.com.

RSS
Reprints/License
Print
Email
Talkback
Canon Resource Center

Featured Company


Most Recent Resources

Advertisement
Related Content

No related content found.

  • 0 rated items found.
Advertisement

KNOWLEDGE CENTER

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
Engineering Careers
Jobs sponsored by
Advertisement
About EDN   |   Site Map   |   Contact Us   |   Subscription   |   RSS
© 2012 UBM Electronics. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other UBM Canon sites

UBM Canon | Design News | Test & Measurement World | Packaging Digest | EDN | Qmed | Pharmalive | Appliance Magazine | Plastics Today | Powder Bulk Solids | Canon Trade Shows