#include
#define ui unsigned int
#define uc unsigned char
sbit key=P3^2;
void delay(ui time)
{
ui i;
for(i=0;i<=time;i++);
}
uc led[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0x00,0xFF};
void main(void)
{
uc key_num=0;
P0=0xFF;
while(1)
{
if(key==0)
{
delay(20);
if(key==0)
{
key_num++;
}
while(!key);
delay(5);
while(!key);
}
if(key_num==11)
key_num=0;
switch(key_num)
{
case 1: P0=led[0];break;
case 2: P0=led[1];break;
case 3: P0=led[2];break;
case 4: P0=led[3];break;
case 5: P0=led[4];break;
case 6: P0=led[5];break;
case 7: P0=led[6];break;
case 8: P0=led[7];break;
case 9: P0=led[8];break;
case 10: P0=led[9];break;
}
}
}
/*if(key==0)
{
delay(10);
if(key==0)
{
key_num++;
if(key_num==11)
key_num=0;
{
}
}
} */
还是的程序 我只不过改动了一下 你自己对照看看 在下载进去试验一下 先前就是的按键判断的不好