行列式键盘输入实验
#include<REG51.H>
#define uchar unsigned char
#define uint unsigned int
uchar code DIS_SEG7[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
uchar code DIS_BIT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar code SKEY[16]={10,11,12,13,
3,6,9,14,
2,5,8,0,
1,4,7,15};
uchar code ACT[4]={0xfe,0xfd,0xfb,0xf7};
//-------------------------------------------------
void delay(uint k)
{
uint data i,j;
for(i=0;i<k;i++)
{
for(j=0;j<121;j++)
{;}
}
}
//-------------------------------------
char scan_key(void)
{
uchar i,j,in,ini,inj;
bit find=0;
for(i=0;i<4;i++)
{
P1=ACT;
delay(10);
in=P1;
in=in>>4;
in=in|0xf0;
for(j=0;j<4;j++)
{
if(ACT[j]==in)
{
find=1;
inj=j;ini=i;
}
}
}
if(find==0)return -1;
return(ini*4+inj);
}
//==============================
void main()
{
char c;
uchar key_value;
while(1)
{
c=scan_key();
if(c!=-1)key_value=SKEY[c];
P0=DIS_SEG7[key_value];
P2=DIS_BIT[0];
delay(2);
}
} |