您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 电子设计/PCB > 矩阵键盘扫描代码(C语言)
#includereg52.h#defineuncharunsignedchar#defineunintunsignedintunsignedcharcodedula[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};unsignedcharcodewela[]={0,1,2,3,4,5,6,7};unsignedcharnum,key;unsignedcharkeyscan();uncharKeyscan();voiddelay(intz){intx,y;for(x=z;x=0;x--)for(y=0;y=148;y++);}voidmain(){P2=1;while(1){P1=0xf0;if(P1!=0xf0)//判断有无按键按下{delay(20);//按键消抖if(P1!=0xf0)//第二次判断有无按键按下{delay(20);//按键消抖if(P1!=0xf0)//第三次判断有无按键按下{key=Keyscan();}}}P0=dula[key];}}//uncharkeyscan()//{//}uncharKeyscan(void){unchari,j,temp,Buffer[4]={0xfe,0xfd,0xfb,0xf7};//让矩阵键盘的每行分别为低电?for(j=0;j4;j++){P1=Buffer[j];temp=0x10;for(i=0;i4;i++){if(!(P1&temp))//判断P1口高4位某一行为低电平{return(i+j*4);//返回键码}temp=1;}}}
本文标题:矩阵键盘扫描代码(C语言)
链接地址:https://www.777doc.com/doc-5000094 .html