矩阵键盘扫描代码(C语言)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
for(j=0; j<4; j++)
{
P1 = Buffer[j];
temp = 0x10;
for(i=0; i<4; i++)
{
if(!(P1 & temp))//判断P1口高4位某一行为低电平
{
return (i+j*4);//返回键码
}
temp<<= 1;
}
}
}
unsigned char code wela[]={0,1,2,3,4,5,6,7};
unsigned char num,key;
unsigned char keyscan();
unchar Keyscan();
void delaHale Waihona Puke Baidu(int z)
{
int x,y;
for(x=z;x>=0;x--)
#include<reg52.h>
#define unchar unsigned char
#define unint unsigned int
unsigned char code dula[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
for(y=0;y<=148;y++);
}
void main()
{
P2=1;
while(1)
{
P1 = 0xf0;
if(P1 != 0xf0)//判断有无按键按下
{
delay(20);//按键消抖
if(P1 != 0xf0)//第二次判断有无按键按下
{
delay(20); //按键消抖
if(P1 != 0xf0)//第三次判断有无按键按下
{
key = Keyscan();
}
}
}
P0=dula[key];
}
}
//unchar keyscan()
//{
//}
unchar Keyscan(void)
{
unchar i,j,temp, Buffer[4] = {0xfe, 0xfd, 0xfb, 0xf7}; //让矩阵键盘的每行分别为低电?
{
P1 = Buffer[j];
temp = 0x10;
for(i=0; i<4; i++)
{
if(!(P1 & temp))//判断P1口高4位某一行为低电平
{
return (i+j*4);//返回键码
}
temp<<= 1;
}
}
}
unsigned char code wela[]={0,1,2,3,4,5,6,7};
unsigned char num,key;
unsigned char keyscan();
unchar Keyscan();
void delaHale Waihona Puke Baidu(int z)
{
int x,y;
for(x=z;x>=0;x--)
#include<reg52.h>
#define unchar unsigned char
#define unint unsigned int
unsigned char code dula[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
for(y=0;y<=148;y++);
}
void main()
{
P2=1;
while(1)
{
P1 = 0xf0;
if(P1 != 0xf0)//判断有无按键按下
{
delay(20);//按键消抖
if(P1 != 0xf0)//第二次判断有无按键按下
{
delay(20); //按键消抖
if(P1 != 0xf0)//第三次判断有无按键按下
{
key = Keyscan();
}
}
}
P0=dula[key];
}
}
//unchar keyscan()
//{
//}
unchar Keyscan(void)
{
unchar i,j,temp, Buffer[4] = {0xfe, 0xfd, 0xfb, 0xf7}; //让矩阵键盘的每行分别为低电?