欢迎来到天天文库
浏览记录
ID:39463356
大小:26.50 KB
页数:3页
时间:2019-07-03
《4x4按键识别点灯》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#defineuintunsignedint#defineucharunsignedcharucharcodekeycodeTable[]={0x11,0x12,0x14,0x18,0x21,0x22,0x24,0x28,0x41,0x42,0x44,0x48,0x81,0x82,0x84,0x88};//延时函数voiddelay(uintt){uchark=0;while(t--)for(k=0;k<120;k++);}//最重要的——————键盘扫
2、描,键识别charkeys_scan(){ucharscode,kcode,i,k;P1=0xf0;if((P1&0xf0)!=0xf0){delay(10);if((P1&0xf0)!=0xf0){scode=0xfe;for(k=0;k<4;k++){P1=scode;if((P1&0xf0)!=0xf0){kcode=~P1;for(i=0;i<16;i++)if(kcode==keycodeTable[i])return(i+1);}elsescode=_crol_(scode,1);}}}return-1;}//主
3、函数voidmain(){charkeyno=-1;while(1){keyno=keys_scan();if(keyno==-1){P0=0xff;}delay(10);if(keyno!=-1){switch(keyno){case1:P0=~0X01;break;case2:P0=~0X02;break;case3:P0=~0X04;break;case4:P0=~0X08;break;case5:P0=~0X10;break;case6:P0=~0X20;break;case7:P0=~0X40;break;case
4、8:P0=~0X80;break;case9:P0=~0X11;break;case10:P0=~0X22;break;case11:P0=~0X44;break;case12:P0=~0X12;break;case13:P0=~0X14;break;case14:P0=~0X18;break;case15:P0=~0X21;break;case16:P0=~0Xff;break;}}}}
此文档下载收益归作者所有