给你改了一下试试。
- #include <reg51.h>
- sbit key1=P3^0;
- sbit key2=P3^1;
- sbit key3=P3^2;
- unsigned char dula[]=(0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
- 0xf8,0x80,0x90);
- unsigned char wela[]=(0xfe,0xfd,0xfb,0xf7);
- unsigned char tab[4];
- unsigned char sec,count;
- void delay (unsigned int i)
- {
- while(i--);
- }
- void keytest()
- {
- if(key1==0)
- {
- delay(200);
- if (key1==0)
- {
- TR0=1;
- while(key1==0);
- }
- }
- else if(key2==0)
- {
- delay(200);
- if(key2==0)
- {
- TR0=0;
- while(key2==0);
- }
- }
- else if(key3==0)
- {
- delay(200);
- if(key3==0)
- {
- TR0=0;
- sec=0;
- count=0;
- while(key3==0);
-
- }//break;
- }
- }
- void main()
- {
- TMOD=0x01;
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- EA=1;
- ET0=1;
- while(1)
- {
- unsigned char a=0;
- keytest();
- display();
- }
- }
- void T0()interrupt 1
- {
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- count++;
- if(count==100)
- {
- count=0;
- sec++;
- if(sec==60) sec=0;
- }
- }
- void display()
- {
- tab[0]=sec/10;
- tab[1]=sec%10;
- tab[2]=count/10;
- tab[3]=count%10;
- for(a=0;a<4;a++)
- {
- switch(a)
- {
- case 0: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
- case 1: P1=wela[a];P2=dula[tab[a]]&0x7f;delay(500);P1=0xff;break;
- case 2: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
- case 3: P1=wela[a];P2=dula[tab[a]];delay(500);P1=0xff;break;
- }
- }
- }
复制代码 |