当前位置:网站首页>迷惑的单片机矩阵按键
迷惑的单片机矩阵按键
2022-07-27 21:59:00 【*黑心萝卜三条杠*】
在我们学习单片机的过程中,矩阵按键是必不可少的模块,接下来就让小编带你走进单片机矩阵按键吧!
一、矩阵按键的扫描
矩阵按键是由十六个按键组成,我们在判断矩阵按键的位置时,我们既用到了状态机,也使用了行列扫描法。话不多说,下面先让我们看看矩阵按键的构成吧!

在状态机中,我们设置了四个状态,即未按按键状态、按键按下状态、按键弹起转态、屏蔽状态;我们使用的行列扫描法,其实就是根据行与列的位置来确定唯一的矩阵按键位置。
二、设计实现
1.定义使用的全局变量:
#define kbd_io P3
#define state_0 0 //是否按下
#define state_1 1 //是否是抖动
#define state_2 2 //判断是否弹起
#define kbd_maskrow 0x0f //屏蔽不需要的IO
unsigned int key_num=16;2.具体的实现函数:
void scankbd()
{
static char kbd_state = 0;//用来判断处于那个状态
unsigned char kbd_press;
char row;
switch(kbd_state){
case state_0: //是否按下
kbd_io=0x0f; P42=0; P44=0;
kbd_press =kbd_io;
if(kbd_press != kbd_maskrow)
kbd_state = state_1;
//break;
case state_1: //是否是抖动 kbd_io-P3
kbd_press =kbd_io;
if(kbd_press != kbd_maskrow)
{
if((kbd_io&0x08)==0) row=0; //P30列
if((kbd_io&0x04)==0) row=1; //P31列
if((kbd_io&0x02)==0) row=2; //P32列
if((kbd_io&0x01)==0) row=3; //P33列
kbd_io=0xf0; P42=1;P44=1;
if(P44==0) key_num=row; //p44行
if(P42==0) key_num=row+4; //p42行
if((kbd_io&0x20)==0) key_num=row+8; //P35行
if((kbd_io&0x10)==0) key_num=row+12; //p34行
kbd_state = state_2;
}
else
kbd_state = state_0;
break;
case state_2: //判断是否弹起
kbd_io=0x0f; P42=0; P44=0;
kbd_press =kbd_io;
if(kbd_press == 0x0f) kbd_state = state_0;
break;
default: //屏蔽不需要的IO
break;
}
}边栏推荐
- Shell(3)
- A few lines of code can easily realize the real-time reasoning of paddleocr. Come and get!
- The R language uses the hexsticker package to convert the visualized results of ggplot2 package into hexagonal diagrams (hexagonal stickers, hexagonal stickers, ggplot2 plot to hex stickers)
- Intel releases open source AI Reference Suite
- Application scenario Display of metauniverse
- Yongzhou plant cell laboratory construction layout plan
- 强强协同,共拓发展!英特尔与太一物联举办 AI 计算盒聚合服务研讨会
- 阿金的思考
- 服务器中毒了——菜是原罪
- 好漂亮的彩虹
猜你喜欢

Analysis and solution of errors in symbols uploading when baget manages packages

Intel AI practice day issue 56 | explore new trends in industry development

冲量在线出席2022数据要素安全流通论坛—政务领域专场,助力行业政务大数据建设创新发展

MATLAB | 那些你不得不知道的MATLAB小技巧(四)

强强协同,共拓发展!英特尔与太一物联举办 AI 计算盒聚合服务研讨会

҈直҈播҈预҈告҈ |҈ 炎热盛夏,与Nono一起跨越高温“烤”验吧!

公司7月来了个软件测试工程师,一副毛头小子的样儿,哪想到是新一代卷王...

Window function over

MFC提示this application has requested the runtime to terminate it in an unusual way editbox框已经删了还在使用

A few lines of code can easily realize the real-time reasoning of paddleocr. Come and get!
随机推荐
智能便利店带你解锁未来科技购物体验
30余年的元宇宙,为我们带来了什么?
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
几行代码轻松实现对于PaddleOCR的实时推理,快来get!
泵站远程监控
Oracle password expiration solution
[meetup preview] openmldb + ONEFLOW: link feature engineering to model training to accelerate machine learning model development
Window function over
Applet helps smart home ecological platform
҈ straight ҈ Broadcast ҈ Pre ҈ Report ҈ |҈ In hot summer, let's cross the high temperature and "bake" with nono!
Y79. Chapter IV Prometheus' monitoring system and practice -- Prometheus' service discovery mechanism (10)
MATLAB 文件夹前面的+和@是干啥的 命名空间与函数的重载
[must read for new products] valuation analysis of Meishi technology, distributed audio-visual products and Solutions
Analysis and solution of errors in symbols uploading when baget manages packages
服务器开放敏感端口
机械工程物联网系统远程解决方案
Strong collaboration and common development! Intel and Taiyi IOT held a seminar on AI computing box aggregation services
【Meetup预告】OpenMLDB+OneFlow:链接特征工程到模型训练,加速机器学习模型开发
A design scheme of Wal
Intensive reading of deep learning papers [gan]: multi-purpose image restoration and processing using depth generation priors