Several key input implementation methods on single chip microcomputer

Publisher:SereneSpiritLatest update time:2012-07-10 Source: mcu99Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

As a simple and practical input device, buttons have been used in various microcontroller application systems and are ubiquitous. However, the buttons used in different practical occasions are also different. Here are some commonly used buttons and their usage methods.

1. Traditional buttons:

Traditional buttons are the most widely used buttons in various electronic devices. They may have different shapes
, but their control methods are similar. They use the IO level state change of whether the button is pressed to identify it.
This type of button is shown in the figure below:

Click to browse the next page



1) Direct key

The simplest keyboard is to connect the level signal directly to the IO. Read the IO level status in the program. If
the corresponding level is read, it means that the key connected to this IO is pressed. The principle and control method of this method are very
simple, but it causes a waste of IO resources. The schematic diagram of this key method is as follows:

Click to browse the next page


2) Scan key matrix This key input method makes clever use of IO resources, so that 8 IOs can realize a 16-key keyboard. Its schematic diagram is as follows:


Click to browse the next page

This key input method is more complicated than the direct key method above in terms of principle and control
. It obtains key values ​​by scanning IO. In fact, the scanning process is very simple. The process is as follows:
KEY1~KEY4 corresponds to IO0~IO3, and KEY5~KEY8 corresponds to IO4~IO7.
1. Set IO0~IO3 high, IO4 low, IO5, IO6, and IO7 high, and read IO0~IO3. After a
button in the first column is pressed, the corresponding two contacts are connected, and the IO on the corresponding row can read a low level.
2. Set IO0~IO3 high, IO5 low, IO4, IO6, and IO7 high, and read IO0~IO3. After a
button in the first column is pressed, the corresponding two contacts are connected, and the IO on the corresponding row can read a low level.
3. Set IO0~IO3 high, IO6 low, IO4, IO5, and IO7 high, and read IO0~IO3. After a button in the first column
is pressed, the corresponding two contacts are connected, and the IO on the corresponding row can read a low level.
4. Set IO0~IO3 high, IO7 low, IO4, IO5, and IO6 high, and read IO0~IO3.
After a button in the first column is pressed, the corresponding two contacts are connected, and the IO on the corresponding row can read a low level.
This process can be repeated to read the key value.
In actual applications, this scanning process is usually completed in the interrupt service program of the timer, and
the key value is returned to other functions through global variables. Of course, as a learning process, the scanning can also be
completed directly in the main function.
In the key input method introduced above, readers can see that IO uses a low level as the detection level.
Why is this? This is because when the microcontroller IO reads the level state, reading a low level is more stable than a high level. It is also because
of this reason that the external interrupt uses a low level or a falling edge as its interrupt trigger condition to ensure the reliability of the interrupt. [page]

2. Multi-directional integrated buttons

As handheld devices become more and more popular, people are increasingly exposed to multi-directional integrated buttons, such as
the five-way navigation button on a mobile phone and the toggle switch on an MP3 player. They all have a common feature,
that is, an integrated button can output signals in several directions for the controller to identify. The multi-directional integrated button is as follows
:

Click to browse the next page
Click to browse the next page



1)
Five-way button We use five-way buttons almost every day. You can see them as long as you take out your MP3 or mobile phone.
Some people may feel its magic. Here we will reveal its secrets for you.
The five-way button is actually an integration of five traditional buttons, which are arranged in
five directions: up, down, left, right, and center, thus forming a five-way button. When a button in a certain direction is turned on, the IO can
sense the corresponding level to identify its direction. The schematic diagram of the five-way application is as follows:

Click to browse the next page



From the above picture, we can see that the usage of the five-way key is actually the same as the direct key in the traditional key.

2) Dial button

The wheel button is often used in products for volume adjustment, item selection, etc. Its principle is similar to that of the five-way key, but
the difference is that the wheel button integrates the left, right, and middle direction buttons, and the button is changed to a toggle mode, which is
more suitable for the user's usage habits. The application diagram is as follows:

Click to browse the next page

The usage of the five-way button and the dial button on the SiriuS development board is as follows:

Click to browse the next page


3. Analog keystrokes

The keystroke input methods introduced above all use digital signals to identify keys. Their disadvantage is that they require
more IO and the number of keys is limited.
The method of using analog signals to identify keys introduced here can save IO and the expansion of keys is also very convenient. Of course, its implementation requires the support of corresponding hardware (digital-to-analog
converter).

The principle is actually very simple. A key is connected between series-connected resistors of equal value, and the other end of the key is connected to the ground. In this
way, when two resistors are connected to the ground due to key connection, different voltage values ​​will be obtained at the input end of the analog-to-digital converter.
These voltage values ​​are 1/2 VCC, 2/3 VCC, etc., respectively. According to these voltage values, the pressed keys can be identified.
The maximum number of keys depends on the accuracy of the analog-to-digital converter.

Keywords:MCU Reference address:Several key input implementation methods on single chip microcomputer

Previous article:Program implementation of state machine idea in single chip microcomputer
Next article:Wireless UART Experiment Design Based on CC1100 and MSP430

Recommended ReadingLatest update time:2024-11-16 22:02

51 MCU ultrasonic module digital tube program sharing
The ultrasonic principle is simple, the distance measurement is accurate, and it is widely used. Below is a digital tube program I wrote. The display part needs to be modified. It is written that I am using the Huijing development board and common cathode digital tube. //Ultrasonic module program //Trig = P2^0 //Ec
[Microcontroller]
51 MCU ultrasonic module digital tube program sharing
MCU programming STM8S optionbytes
Today I used STM8S to modify optionbyte in the program. I encountered a problem that it kept reading as 0 and could not enter the setting process. I modified the previous program again today. Using the new film, the original procedure is as follows:   AFR_TEMP = (uint16_t)((uint16_t)0x01 8);   AFR_TEMP = AFR_TEMP
[Microcontroller]
Freescale 16-bit MCU (Thirteen) - SPI module test
1. SPI module introduction          The Serial Peripheral Interface (SPI) module provides full-duplex, synchronous, serial communication between the microcontroller and peripheral devices. These peripheral devices can include other microcontrollers, analog-to-digital shifters, shift registers, sensors, and memories.
[Microcontroller]
Freescale 16-bit MCU (Thirteen) - SPI module test
51 MCU common IO port simulation serial port source program
You can use it with confidence, but you should take a good look at your program as it is prone to interrupt conflicts. We are also working on solving this problem. The program for receiving and sending strings will be sent to you by email if you need it. It is a good thing. We encountered an interrupt problem, which
[Microcontroller]
[MCU Notes] Single button to achieve single click, double click, long press
I will paste the source code and test routines directly, and they are accompanied by Chinese comments without further explanation. Bottom-layer driver: #define key_state_0 0 #define key_state_1 1 #define key_state_2 2 #define key_state_3 3   #define key_no 0 #define key_click 1 #define key_double 2 #define key_lon
[Microcontroller]
Radio data communication based on DTMF coding of single chip microcomputer
  With the popularization of single-chip microcomputer applications, the communication problem between single-chip microcomputers has attracted widespread attention. At present, wired communication is widely used, and how to use the existing wireless analog channel for single-chip microcomputer data transmission is a
[Microcontroller]
Radio data communication based on DTMF coding of single chip microcomputer
MCU memory configuration
MCU memory configuration: On-chip RAM 128 bytes (00H-7FH); The first 32 units of the on-chip RAM are the working register area (00H-1FH) The on-chip RAM has 128 bit-addressable bits, occupying 16 cells. The bit address number is: 00H-7FH, distributed in 20H-2FH units (P.27) Among the 21 special function re
[Microcontroller]
MCU memory configuration
Design of a Single-Chip Microcomputer Multi-Machine Communication System
1 Introduction With the continuous development of single-chip microcomputer and computer technology, the application of single-chip microcomputer has also developed from independent single machine to network. The multi-machine network system composed of computer and single-chip microcomputer has become a direct
[Microcontroller]
Design of a Single-Chip Microcomputer Multi-Machine Communication System
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号