#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED1=P1^0;
sbit KEY1=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
uchar disnum;
uchar code table_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
delay(uchar);
void main()
{
	wela=1;
	P0=0XFE;
	wela=0;
	KEY1=1;
	while(1)
	{
		if(KEY1==0)  //如果有按键按下
		{
			delay(10);     //先延时10ms
			if(KEY1==0)  //再次判断是否真的有按键按下(即消除前沿抖动)
			{
			LED1=0;        //真的有按键按下，第一个LED小灯亮
			disnum++;       //真的有按键按下，disnum的值自身加1
			if(disnum==10)  
			disnum=0;
			while(!KEY1);  //按键松手检测
			delay(10);      //延时10ms
			while(!KEY1);  //再次判断按键是否真的松手了(即消除后沿抖动)
			}
		}
		else          //如果有没按键按下
			LED1=1;   //第一个LED小灯不亮
			P0=table_du[disnum];   //数码管还是显示原来的数字
			dula=1;
			dula=0;
	}
}

delay(uchar x)  
{
	uchar a,b;
	for(a=x;a>0;a--)
		for(b=200;b>0;b--);
}