一个改进型的4*4矩阵键盘扫描
时间:11-30
来源:互联网
点击:
#include
#define uchar unsigned char
#define uint unsigned int
uchar temp,num,bai,shi,ge;
uchar key[]={0x3f,0x5f,0x6f};
uchar code table[]=
{
0x3f , 0x06 , 0x5b ,
0x4f , 0x66 , 0x6d ,
0x7d , 0x07 , 0x7f ,
0x6f };
void keyscan();
void delay(uchar z);
void dsp(uchar bai,uchar shi,uchar ge);
void main()
{
while(1)
{
keyscan();
dsp(bai,shi,ge);
}
}
void delay(uchar z)
{
uchar x,y;
for(x=100;x--;x>0)
for(y=z;y--;y>0);
}
void dsp(uchar bai,uchar shi,uchar ge)
{
bai=num/100;
shi=num%100/10;
ge=num%10;
P0=0xfb;
P2=table[bai];
delay(1);
P0=0xfd;
P2=table[shi];
delay(1);
P0=0xfe;
P2=table[ge];
delay(1);
}
void keyscan()
{ uchar i;
for(i=0;i<3;i++)
{
P1=key[i];
temp=P1;
temp&=0x0f;
if(temp!=0x0f) //如果有键按下
{
delay(5);
temp=P1;
temp&=0x0f;
if(temp!=0x0f)//确实有键按下
{
switch(temp)
{
case 0x07:adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=f1c2511670cd2325&k=switch&k0=switch&kdi0=0&luki=1&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=2523cd701651c2f1&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2002%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">switch(i)
{
case 0:num=1;break;
case 1:num=5;break;
case 2:num=9;break;
};
break;
case 0x0b:switch(i)
{
case 0:num=2;break;
case 1:num=6;break;
case 2:num=10;break;
};
break;
case 0x0d:switch(i)
{
case 0:num=3;break;
case 1:num=7;break;
case 2:num=11;break;
};
break;
case 0x0e:switch(i)
{
case 0:num=4;break;
case 1:num=8;break;
case 2:num=12;break;
};;
break;
while(temp!=0xf0) //松开手后就跳出循环,否则等待松手
{
temp=P1;
temp=temp&0xf0;
dsp(bai,shi,ge);
}
}
}
}
}
}
#define uchar unsigned char
#define uint unsigned int
uchar temp,num,bai,shi,ge;
uchar key[]={0x3f,0x5f,0x6f};
uchar code table[]=
{
0x3f , 0x06 , 0x5b ,
0x4f , 0x66 , 0x6d ,
0x7d , 0x07 , 0x7f ,
0x6f };
void keyscan();
void delay(uchar z);
void dsp(uchar bai,uchar shi,uchar ge);
void main()
{
while(1)
{
keyscan();
dsp(bai,shi,ge);
}
}
void delay(uchar z)
{
uchar x,y;
for(x=100;x--;x>0)
for(y=z;y--;y>0);
}
void dsp(uchar bai,uchar shi,uchar ge)
{
bai=num/100;
shi=num%100/10;
ge=num%10;
P0=0xfb;
P2=table[bai];
delay(1);
P0=0xfd;
P2=table[shi];
delay(1);
P0=0xfe;
P2=table[ge];
delay(1);
}
void keyscan()
{ uchar i;
for(i=0;i<3;i++)
{
P1=key[i];
temp=P1;
temp&=0x0f;
if(temp!=0x0f) //如果有键按下
{
delay(5);
temp=P1;
temp&=0x0f;
if(temp!=0x0f)//确实有键按下
{
switch(temp)
{
case 0x07:adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=f1c2511670cd2325&k=switch&k0=switch&kdi0=0&luki=1&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=2523cd701651c2f1&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2002%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">switch(i)
{
case 0:num=1;break;
case 1:num=5;break;
case 2:num=9;break;
};
break;
case 0x0b:switch(i)
{
case 0:num=2;break;
case 1:num=6;break;
case 2:num=10;break;
};
break;
case 0x0d:switch(i)
{
case 0:num=3;break;
case 1:num=7;break;
case 2:num=11;break;
};
break;
case 0x0e:switch(i)
{
case 0:num=4;break;
case 1:num=8;break;
case 2:num=12;break;
};;
break;
while(temp!=0xf0) //松开手后就跳出循环,否则等待松手
{
temp=P1;
temp=temp&0xf0;
dsp(bai,shi,ge);
}
}
}
}
}
}
改进型4*4矩阵键盘扫 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)