#51 MCU#button

Publisher:BlissfulHeartLatest update time:2021-10-27 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

button

There are two commonly used key circuits, one is an independent key and the other is a matrix key.


Independent buttons

The independent buttons are each connected to an independent input line.


Take the circuit in the following figure as an example for analysis.


Independent button schematic diagram:

insert image description here

The basis for judging whether a key is pressed is: the level of the KeyIn (n) IO port.

When K1 is pressed, the high and low level ends of the circuit are connected. At this time, the Keyln1 pin is at a low level.


When K1 is released, the line is disconnected, Keyln1 and +5V are at the same potential, and the Keyln1 pin is at a high level.


Usually, there is a pull-up resistor inside the IO port of the microcontroller.


Take the quasi-bidirectional IO port structure diagram as an example:

insert image description here

The circuit inside the box is the internal part of the microcontroller, and outside the box are the external pull-up resistors and buttons.


Note: When reading external key signals, the microcontroller must first set the pin to 1! ! !

analyse as below:


When the internal output = 1, it is inverted to 0 after the NOT gate, the NPN transistor has no potential difference, and the circuit is not connected. There is no potential difference between VCC (also +5V) and +5V, and the IO port of the microcontroller is at a high level. The key status can be read normally.


When the internal output = 0, it is inverted to 1, the NPN transistor generates a potential difference, and the circuit is connected. The IO port of the microcontroller is affected and becomes a low level, and the key status cannot be read normally.


Matrix Buttons

Based on independent buttons, in order to improve the utilization rate of IO ports, matrix buttons came into being.


As shown in the figure, 8 IO ports realize 16 buttons.

insert image description here

If KeyOut1 outputs a low level, KeyOut1 is equivalent to GND, and the other four keys are equivalent to independent keys. It should be noted that KeyOut2, KeyOut3 and KeyOut4 should all output a high level at this time to avoid affecting the KeyOut1 line.


The circuit diagram is now simplified to this:

insert image description here

Reference address:#51 MCU#button

Previous article:#51 MCU#Key debounce
Next article:#51 MCU#Interrupt and digital tube application

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号