Independent buttons
There are two forms of commonly used button circuits, independent buttons and matrix buttons. Independent buttons are relatively simple, and each of them is connected to an independent input line, as shown in Figure 8-6.
Figure 8-6 Schematic diagram of independent button
The 4 input lines are connected to the IO port of the microcontroller. When the button K1 is pressed, +5V passes through the resistor R1 and then through the button K1 to finally enter GND to form a path. Then all the voltage of this line is added to the resistor R1, and the KeyIn1 pin is a low level. When the button is released, the line is disconnected and no current will pass through. Then KeyIn1 and +5V should be at the same potential, which is a high level. We can judge whether a button is pressed by the high and low levels of the IO port KeyIn1.
We understand the principle of the button in this circuit, but in fact, there is also a pull-up resistor inside our microcontroller IO port. Our button is connected to the P2 port. The P2 port is a quasi-bidirectional IO port by default when it is powered on. Let's take a brief look at the circuit of this quasi-bidirectional IO port, as shown in Figure 8-7.
Figure 8-7 Quasi-bidirectional IO port structure diagram
First of all, I want to explain that most of our MCU IO ports now use MOS tubes instead of triodes, but the principle of MOS tubes used here is the same as that of triodes, so I use triodes to replace them to explain the principle, and bring the knowledge of triodes mentioned earlier over, everything is applicable and helpful for understanding.
The circuits in the box in Figure 8-7 refer to the internal part of the MCU, and the ones outside the box are our external pull-up resistors and buttons. You should pay attention to this place, that is, when we want to read the external key signal, the MCU must first write "1" to the pin, that is, high level, so that we can correctly read the external key signal. Let's analyze the reason.
When the internal output is high level, it becomes low level after an inverter, and the NPN triode will not be turned on. Then, from the internal point of view of the MCU IO port, due to the existence of the pull-up resistor R, it is a high level. When no external button is pressed to pull the level down, VCC is also +5V. Although there are two resistors between them, there is no voltage difference, so there will be no current. All positions on the line are high level, and we can read the state of the button normally.
When the internal output is a low level, it becomes a high level after an inverter, and the NPN transistor is turned on, then the internal IO port of the microcontroller is a low level. At this time, although there is also a pull-up resistor outside, the two resistors are in parallel. Regardless of whether the button is pressed or not, the state input from the IO port of the microcontroller to the internal state of the microcontroller is a low level, and we cannot read the state of the button normally.
This is actually very similar to water flow. As long as one side is low potential, the current will flow downstream. Since there is only a pull-up resistor and no resistor voltage divider below, it goes directly to GND, so regardless of whether the other side is high or low, the level must be low.
From the above analysis, we can draw a conclusion that if this kind of quasi-bidirectional IO port with pull-up wants to read the status of the external signal normally, we must first ensure that the internal output is 1. If the internal output is 0, no matter whether the external signal is 1 or 0, the pin will read 0.
Matrix Buttons
In a system design, if many buttons are needed, making them independent will occupy a large number of IO ports, so we introduced the design of matrix buttons. As shown in Figure 8-8, it is the schematic diagram of the matrix button circuit on our KST-51 development board, which uses 8 IO ports to realize 16 buttons.
Figure 8-8 Schematic diagram of matrix buttons
If you understand the independent keys, the matrix keys are not difficult to understand, so let's analyze it together. In Figure 8-8, there are 4 groups of keys in total. We only look at one group, as shown in Figure 8-9. Take a closer look. If KeyOut1 outputs a low level, KeyOut1 is equivalent to GND. Is it equivalent to 4 independent keys? Of course, at this time, KeyOut2, KeyOut3, and KeyOut4 must all output high levels. They all output high levels to ensure that the three keys connected to them will not interfere with this one. You can analyze it by comparing the two schematic diagrams.
Figure 8-9 Schematic diagram of matrix buttons becoming independent buttons
Previous article:C language function call
Next article:Scanning of independent buttons of single chip microcomputer
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Evaluation Weekly Report 20211206: Anxinke UWB indoor positioning module is here, Qinheng CH582 is coming, RCSN plays AT32F437
- I encountered some difficulties in the process of making a magnetically controlled lamp for a model, and I would like to ask for help from an expert.
- Evaluation of domestic FPGA Gaoyun GW1N-4 series development board - Software Part 3
- Hi3518 Rebirth (Part 3) http+mjpeg bug fix in minihttp
- Advantages of the STOP function in low-noise data acquisition applications
- UC3842 power supply problem
- I would like to ask how to set up Xnet in allegro
- Two Application Examples of EPROM in Single Chip Microcomputer Development
- [Erha Image Recognition Artificial Intelligence Vision Sensor] Evaluation 1: Winner Chip Level Evaluation
- Circuit PCB Design