当前位置:网站首页>(4) Independent key
(4) Independent key
2022-06-26 08:19:00 【I love notes】
Previously, I recalled the relevant contents of key output , Now you can continue to work on the contents of the key input , In this section, we will find out the relevant contents of an independent key to recall the relevant contents of key input , Make an... By the judgment of an independent key led The light is on and off .
1. About keys
The keyboard is divided into coding keyboard and non coding keyboard , The recognition of the coding keys on the keyboard is realized by a special hardware encoder , And generate code number or key value is called coding keyboard , Such as computer keyboard . The keyboard recognized by software programming is called non coding keyboard . Non coding keyboard is divided into independent keyboard and determinant keyboard . The keyboard on the single-chip microcomputer is generally a non coding keyboard , In this section, I mainly talk about the independent keyboard .
2. Hardware
In fact, the detection of cases is relatively simple , The detection principle of our button is very simple , We first pass gpio The port is connected with the key and the ground , As shown in the figure below :

our gpio As input, it defaults to high level , At this time, we check the status of the four buttons at the same time , If gpio Low level detected , Then this button is pressed . But in practice, when we press , He didn't immediately switch from high to low , It's a period of jitter , Is a period of high and low levels , We can complete the work by hardware and software , But the hardware circuit is usually used to eliminate the jitter , This is more complicated and costly , So we basically choose the way of software anti shake , If a key has been pressed , We delayed about 10ms about , Check again , If it is still low level , It proves that the key was pressed .
3. Software
After pressing the key, the corresponding led The main procedures for light on are as follows :
#include "key.h"
void delay(int xms){
int i,j;
for(i = 0;i < xms;i++){
for(j = 0;j < 100;j++);
}
}
int key_scan(){
if(k0==0){
delay(10);
if(k0==0){
led0 = !led0;
}
while(!k0);
}
else if(k1==0){
delay(10);
if(k1==0){
led1 = !led1;
}
while(!k1);
}
else if(k2==0){
delay(10);
if(k2==0){
led2 = !led2;
}
while(!k2);
}
if(k3==0){
delay(10);
if(k3==0){
led3 = ~led3;
}
while(!k3);
}
else {
}
return 0;
}
The principle has been made clear , By the way, put the calling function and the header file together , The header file code is as follows :
#ifndef _KEY_H_
#define _KEY_H_
#include "reg52.h"
sbit k1 = P3^1;
sbit k0 = P3^0;
sbit k2 = P3^2;
sbit k3 = P3^3;
sbit led0 = P2^0;
sbit led1 = P2^1;
sbit led2 = P2^2;
sbit led3 = P2^3;
int key_scan();
void delay();
#endifThe main function calling functions are as follows :
#include "reg52.h"
#include "key.h"
void main(){
while(1){
key_scan();
}
}Here we are , Our individual buttons are complete
边栏推荐
- Assembly led on
- Area of Blue Bridge Cup 2 circle
- h5 localStorage
- I want to open a stock account at a discount. How do I do it? Is it safe to open a mobile account?
- Idea uses regular expressions for global substitution
- 你为什么会浮躁
- ASP. Net and Net framework and C #
- Ora-12514: tns: the listener currently does not recognize the service requested in the connection descriptor
- Idea automatically sets author information and date
- 1. error using XPath to locate tag
猜你喜欢

Pychart connects to Damon database

MySQL practice: 2 Table definition and SQL classification

The 9th zero code training camp is officially open for registration! (Beijing, Shanghai, Guangzhou and Shenzhen)

Quickly upload data sets and other files to Google colab ------ solve the problem of slow uploading colab files

Ora-12514: tns: the listener currently does not recognize the service requested in the connection descriptor

Design of reverse five times voltage amplifier circuit

What if the service in Nacos cannot be deleted?

加密的JS代码,变量名能破解还原吗?

ASP. Net and Net framework and C #

Detailed explanation and code implementation of soft voting and hard voting mechanism in integrated learning
随机推荐
SOC的多核启动流程详解
Crawler case 1: JS reversely obtains HD Wallpapers of minimalist Wallpapers
Go语言浅拷贝与深拷贝
Chapter VIII (classes and objects)
RF filter
Uni app installation and project directory (hbuilder configuration)
Mapping '/var/mobile/Library/Caches/com.apple.keyboards/images/tmp.gcyBAl37' failed: 'Invalid argume
MySQL insert Chinese error
What if the service in Nacos cannot be deleted?
Software engineering - high cohesion and low coupling
h5 localStorage
Example of offset voltage of operational amplifier
Real machine debugging of uniapp custom base
Power apps application practice | easily develop employee leave attendance management applet with power apps
Recognize the interruption of 80s51
Hand drawn style chart library chart Implementation principle of xkcd
Opencv mouse event + interface interaction drawing rectangle polygon selection ROI
ASP. Net and Net framework and C #
(vs2019 MFC connects to MySQL) make a simple login interface (detailed)
Learning signal integrity from scratch (SIPI) -- 3 challenges faced by Si and Si based design methods