原文链接
https://www.amobbs.com/thread-4308630-1-1.html
#define Number 20
unsigned char Jitter = Number; //连续检测20次,每次间隔1ms
unsigned int Value; //读取的端口,每次和次数据做或操作,原始值为0
unsigned int SaveData;//保存读取的去抖动后的端口数据
unsigned int Trg;
unsigned int Cont;
void KeyRead(unsigned char Time)
{
if(Time != 0) //不为0时,1ms时间间隔已到
{
if(Jitter == 0)
{
SaveData = Value; //去抖动次数到,保存读取的数据
Value = 0; //和端口做or操作
Jitter =Number;
}
else
{
--Jitter;
Value |= GPIO_ReadInputData(GPIOC);//每次去抖动时都是0为有按下,有一次为1,
//表示已松开,置读取数据以后都为1,到去抖动次数到,再读取是否为0
}
}//以上为添加部分
unsigned int ReadData = SaveData^0xffff; // 1
Trg = ReadData & (ReadData ^ Cont); // 2
Cont = ReadData; // 3
}
一周热门 更多>