一、原理分析

二、思维导图
三、示例框架
#include "reg52.h"
sbit S7 = P3^0;
sbit S6 = P3^1;
sbit S5 = P3^2;
sbit S4 = P3^3;
void ScanKeys()
{
if(S7 == 0)
{
Delay(500);
if(S7 == 0)
{
while(S7 == 0);
}
}
if(S6 == 0)
{
Delay(500);
if(S6 == 0)
{
while(S6 == 0);
}
}
if(S5 == 0)
{
Delay(500);
if(S5 == 0)
{
while(S5 == 0);
}
}
if(S4 == 0)
{
Delay(500);
if(S4 == 0)
{
while(S4 == 0);
}
}
}
-
定义了四个位控制变量
sbit,分别对应P3口的不同引脚,用于检测四个按键的状态。 -
ScanKeys()函数用于扫描四个按键的状态,具体实现如下:- 首先检测按键S7是否被按下,如果被按下,则进行延时500个单位,并再次检测按键状态,确保按键稳定按下。
- 类似地,对按键S6、S5、S4依次进行相同的检测流程,包括延时和稳定按下检测。
-
在每个按键被检测到按下后,进入一个
while循环,等待按键释放,即等待按键不再处于按下状态。











![[VulnHub靶机渗透] BNE0x03 Simple](https://img-blog.csdnimg.cn/direct/8c62878a23eb49798c29677da6b81981.png)







![[游戏开发][UE5.3]GAS学习心得](https://img-blog.csdnimg.cn/direct/28b8a8018bc940eb807831998a6e15dc.png)