满意答案
lfm630228
2013.05.08
采纳率:50% 等级:12
已帮助:8260人
uchar code KeyCodeTable[]=
{
0x11,0x12,0x14,0x18,0x21,0x22,0x24,0x28,0x41,0x42,0x44,0x48,0x81,0x82,0x84,0x88
};
void Delay()
{
uchar i;
for(i=0;i<200;i++);
}
uchar Keys_Scan()
{
uchar sCode,kCode,i,k;
P1 = 0xf0;
if((P1&0xf0)!=0xf0)
{
Delay();
if((P1&0xf0)!=0xf0)
{
sCode = 0xfe;
for(k=0;k<4;k++)
{
P1 = sCode;
if((P1&0xf0)!=0xf0)
{
kCode = ~P1;
for(i=0;i<16;i++)
{
if(kCode == KeyCodeTable[i])
return i;
}
}
else
sCode = _crol_(sCode,1);
}
}
}
return -1;
}
以上程序来自:《单片机C语言程序设计实训100例——基于8051+Proteus仿真》
00分享举报