Introduction to MCU buttons

Publisher:Yuexiang666Latest update time:2016-12-23 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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
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
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
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
Figure 8-9 Schematic diagram of matrix buttons becoming independent buttons


Reference address:Introduction to MCU buttons

Previous article:C language function call
Next article:Scanning of independent buttons of single chip microcomputer

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号