jack821119的笔记 https://bbs.21ic.com/?390105 [收藏] [复制] [RSS]

日志

独立按键扫描防抖动与真值表

已有 1288 次阅读2013-7-21 15:53 |系统分类:嵌入式系统

独立按键扫描防抖动与真值表

这次介绍的是按键防抖动对应的真值表。


 


volatile unsigned char Trg;   //表示按键按下触发    


volatile unsigned char Release; //表示按键释放触发


volatile unsigned char LastKey;//表示上次按键键值


volatile unsigned char CurrentKey;//表示本次按键键值


volatile unsigned char LastStatus;//表示上次按键状态


volatile unsigned char CurrentStatus;//表示本次按键状态

















































































CurrentKey


LastKey


LastStatus


CurrentStatus


Trg


Release


0


0


0


0


0


0


1


0


0


0


0


0


0


1


0


0


0


0


1


0


0


0


0


0


1


1


0


1


1


0


1


1


1


1


0


0


0


1


1


1


0


0


0


0


1


0


0


1


0


0


0


0


0


0


 


 


 


 


 


 


 


由此真值表可以得出:


CurrentStatus = CurrentKey& LastKey&~ LastStatus+ CurrentKey& LastKey& LastStatus+ (~CurrentKey& LastKey&LastStatus)
                          = CurrentKey& LastKey&
~ LastStatus+ LastKey& LastStatus;


Trg = CurrentKey& LastKey&(~ LastStatus)& CurrentStatus


= CurrentKey& LastKey&~ LastStatus;           // 2  得到按下触发值 


Release =( ~CurrentKey)& (~LastKey)&LastStatus& (~CurrentStatus);


            =( ~CurrentKey)& (~LastKey)&LastStatus;


void KeyRead( void )    


{    


unsigned char CurrentKey = (~PINB)&0xff;      // 1  读键值    


Trg = CurrentKey& LastKey&~ LastStatus;           // 2  得到按下触发值 

 
Release =( ~CurrentKey)& (~LastKey)&LastStatus& (~CurrentStatus)=( ~CurrentKey)& (~LastKey)&LastStatus;       // 3  得到释放触发值    


LastKeyCurrentKey;                    // 4  得到所有未释放的键值    


LastStatus = CurrentStatus//5  得到上次按键状态



路过

鸡蛋

鲜花

握手

雷人

全部作者的其他最新日志

评论 (0 个评论)