资源描述:
《51单片机的键盘扫描程序,算法简单有效》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Senda51single-chipkeyboardscanningprogram,thealgorithmissimpleandeffective/slzsixsixsixsixsixsix/#
2、S#
3、SxpxXTXxpxxpxxpxxpxXTXxpxxpxxpxXTXXTXXTXXTXXTXXTXXTXXTXXTX✓JX彳UDonotusekeyboardtimerwithoutdelayCharacteristic:Thekeyiseffectiveafterloosening,thesensitivityishigh,theconsumption
4、isless,andtheoperationefficiencyishighTheindependentkeyboardis:K01=P24;K02=P25;K03=P26;K04二P2"7;Matrixkeyboard:line(toptobottom)P2.3P2.2P2.1P2.0Column(lefttoright)P2.7P2.6P2.5P2.4Suppliedoperatingfunctions://independentkeyboard・Nobuttonmovesthevalueitreturnsnumkey=0,otherwisether
5、eturnbuttonnumbernumkeyExtern,unsigned,char,keyboardself();//matrixkeyboard.Nobuttonmovesthereturnvalueofnumkey=0,otherwisethereturnbuttonnumbernumkey****detectionfourExtern,unsigned,char,keyboard_matrix();Lookattheindependentkeyboard(thesameasthematrixkeyboard)#include#
6、include//independentkeyboard・Nobuttonmovesthevalueitreturnsnum_key=0,otherwisethereturnbuttonnumbernum_keyExtern,unsigned,char,keyboard_self()Unsignedcharnum_key=0;//key.Unsignedchartemp二0;//P2keyvalueforreadingonlineStaticunsignedchartemp_code=0;//savekeyvalueStaticun
7、signedcharnum_check=0;//lowleveleffectivenumberStaticunsignedcharkey_flag=0//keyeffectiveidentificationTemp二P2&0xF0;readtheP2datalineIf(temp!二OxFO)/lowleveljudgmentNumcheck++;If(num_check=10)/10consecutive(10ms)activelow,believesthatthekeyiseffectiveKey_flag=l;//enableeffectiveid
8、entificationkeysTemp_code=temp;//savekeyvalueElse//judgewhenyouletgoNum_check=0;If(key_flag==l)/keyiseffectiveKey_flag=0;Switch(temp_code)//readthekeynumberCaseOxEO:num_key=l;Break;CaseOxDO:num_key=2;Break;CaseOxBO:num_key=3:Break;case0x70:num_key二4;break;return(num_key);现在是矩阵键盘的
9、#ineludereg52.h><#includeintrins.h>/矩阵键盘•无按键动作时其返回值num_key二0,否则返回按键号num_key****检测高四位externunsignedcharkeyboard_matrix(){unsignedcharnum_key=0;//按键号unsignedchartemp二0;//读取p2口线数据thestaticunsignedchartemp_code=0;//用于保存按键值thestaticunsignedchartemp_circle二Oxfe;//保存p2线上的循环扫描值thestati
10、cunsignedcharnum_check=0;//低电平计数thestati