uchar key(void)
{
uchar key,key1,key2,k;
P1=0XF0;
k=0xff;
if((P1&0XF0)!=0XF0)
{
delay();
if((P1&0XF0)!=0XF0)
key1=P1&0XF0;
P1=0X0F;
if((P1&0X0F)!=0X0F)
{
delay();
if((P1&0X0F)!=0X0F)
{
key2=P1&0X0F;
key=key1|key2;
if(key!=0xff)
{
switch(key)
{
case 0xee: k=0;break;
case 0xed: k=1;break;
case 0xeb: k=2;break;
case 0xe7: k=3; break;
case 0xde: k=4;break;
case 0xdd: k=5;break;
case 0xdb: k=6;break;
case 0xd7: k=7; break;
case 0xbe: k=8;break;
case 0xbd: k=9;break;
case 0xbb: k=10;break;
case 0xb7: k=11; break;
case 0x7e: k=12;break;
case 0x7d: k=13;break;
case 0x7b: k=14;break;
case 0x77: k=15; break;
}
}
}
}
}
return(k);
}
只做了键盘扫描程序,说明问题,
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
-----------------------------------------------------------------------
扫描法 代码更多
unsigned int keyboar() //键盘检测函数,返回键值
{
P2=0xfe;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay1ms(10);
temp=P2;
switch(temp)
{
case 0xee:
key=0;
break;
case 0xde:
key=1;
break;
case 0xbe:
key=2;
break;
case 0x7e:
key=3;
break;
}
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
}
P2=0xfd;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay1ms(10);
temp=P2;
switch(temp)
{
case 0xed:
key=4;
break;
case 0xdd:
key=5;
break;
case 0xbd:
key=6;
break;
case 0x7d:
key=7;
break;
}
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
}
P2=0xfb;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay1ms(10);
temp=P2;
switch(temp)
{
case 0xeb:
key=8;
break;
case 0xdb:
key=9;
break;
case 0xbb:
key=10;
break;
case 0x7b:
key=11;
break;
}
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
}
P2=0xf7;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay1ms(10);
temp=P2;
switch(temp)
{
case 0xe7:
key=12;
break;
case 0xd7:
key=13;
break;
case 0xb7:
key=14;
break;
case 0x77:
key=15;
break;
}
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
}
return key;
}
一周热门 更多>