下面是c语言源程序:
#包括
#define uint unsigned int
#define uchar无符号字符
uintled [] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,0x8e};
uchar a,b,c,temp;
void delay7ms(void) //误差 -0.217013888891us
{
未签名的字符a,b;
对于(b = 208; b> 0; b--)
for(a = 14; a> 0; a--);
}
ucharkey()
{
P1 = 0x0f;
如果(P1!= 0x0f)
{
delay7ms();
if(P1!= 0x0f);
P1 = 0xfe;
a = P1 ^ 0xfe;
开关(a)
{
情况0x80:c = 0; break;
case 0x40:c=1;break;
case 0x20:c=2;break;
case 0x10:c=3;break;
}
temp=P1;
while(temp!=0xfe)
{
temp=P1;
}
}
P1=0x0f;
if(P1!=0x0f)
{
delay7ms();
if(P1!=0x0f);
P1=0xfd;
a=P1^0xfd;
switch(a)
{
case 0x80:c=4;break;
case 0x40:c=5;break;
case 0x20:c=6;break;
case 0x10:c=7;break;
}
temp=P1;
while(temp!=0xfd)
{
temp = P1;
}
}
P1 = 0x0f;
如果(P1!= 0x0f)
{
delay7ms();
if(P1!= 0x0f);
P1 = 0xfb;
a = P1 ^ 0xfb;
开关(a)
{
情况0x80:c = 8; break;
情况0x40:c = 9; break;
情况0x20:c = 10; break;
情况0x10:c = 11; break;
}
temp = P1;
while(temp!= 0xfb)
{
temp = P1;
}
}
P1 = 0x0f;
if(P1!=0x0f)
{
delay7ms();
if(P1!=0x0f);
P1=0xf7;
a=P1^0xf7;
switch(a)
{
case 0x80:c=12;break;
case 0x40:c=13;break;
case 0x20:c=14;break;
case 0x10:c=15;break;
}
temp=P1;
while(temp!=0xf7)
{
temp=P1;
}
}
return c;
}
void main(void)
{
而(1)
{
P2 = led [b];
b = key();
}
}