請求51單片機c語言關(guān)于矩陣鍵盤掃描程序的詳解 謝謝了 部分程序如下 void keyscan(void)
{
char col,row;
char scanline=0x08;
int key=0;
int keystatus;
for(col=0;col<4;col++)
{
P2=~scanline;
keystatus=~P2;
keystatus&=0xf0;
for(row=0;row<4;row++)
{
if(keystatus==0x80)
{
one=0;
if(keytemp!=key)
{
keytemp=key;
zero=1;
}
else
{
zero+=1;
if(zero==5)
keydata=keytemp;
}
}
key+=1;
keystatus<<=1;
}
}
one+=1;
if(one==5)
{
zero=0;
keytemp=0xff;
keydata=0xff;
}
}
|