4×4键盘扫描子程序如下:
...
...
unsigned char Key_Get( )
{
unsigned char k=255;
row0=row1=row2=row3=col0=col1=col2=col3=1;
row0=0;
if (col0==0)k=7;
else if (col1==0)k=8;
else if (col2==0)k=9;
else if (col3==0)k=15;
row0=1;
row1=0;
if (col0==0)k=4;
else if (col1==0)k=5;
else if (col2==0)k=6;
else if (col3==0)k=14;
row1=1;
row2=0;
if (col0==0)k=1;
else if (col1==0)k=2;
else if (col2==0)k=3;
else if (col3==0)k=13;
row2=1;
row3=0;
if (col0==0)k=0;
else if (col1==0)k=10;
else if (col2==0)k=11;
else if (col3==0)k=12;
row3=1;
return k;
}
...
...