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:
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:
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:
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
:
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:
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:
The usage of the five-way button and the dial button on the SiriuS development board is as follows:
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.
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Did you guess the board that was unboxed yesterday? It was the Southchip SC8905 EVM. Let’s take a look at the detailed introduction~
- 【TI recommended course】# Master the design of flyback power transformer and circuit#
- Technical books and materials related to lighting LED power supply design
- HyperLynx High-Speed Circuit Design and Simulation (V) Transmission Line Crosstalk after Termination
- Suspicious signal from outer space
- 51 MCU header file added
- Download gift: USB Type C related development and test materials, read it when you have nothing to do, and you will become a master by accident
- Show your face, be careful not to scare people.
- Qorvo explains WIFI and 5G clearly
- NUCLEO-G431RB Review Using the Library to Do FFT