uchar code keytab[]={0x7E,0x7D,0x7B,0x77, //0,1,2,3,
0xBE,0xBD,0xBB,0xB7, //4,5,6,7,
0xDE,0xDD,0xDB,0xD7, //8,9,a,b,
0xEE,0xED,0xEB,0xE7}; //c,d,e,f,
uchar KeyScan()
{
uint i;
uchar h="0xef",b,c;
for(i=4,P1=h;i>0;i--)
{
if((P1&0x0f)!=0x0f)
{
Delay(5000);
if((P1&0x0f)!=0x0f)
{
uchar key,p;
p=P1;
for(key=0;key<16;key++)
{
if(p==keytab[key])
{
do{
_nop_();
}while((P1&0x0f)==0x0f); //等待按键放开,很重要
//P1=0xff;
return(key);
}
}
}
}
b=h>>7;
c=h<<1;
h=c|b;
P1=h;
}
P1=0xff;
return(16);
}
tengjingshu_112148725 2009-4-11 16:01