- #include<reg51.h>
- unsigned char codeseg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x00,0x90 };
- inti=11,j=59,a=0,b=0,m=0,n=0,temp,s=0,r=24,k;
- sbit aa=P0^0;
- sbit bb=P0^1;
- sbit one=P0^2;
- sbit two=P0^3;
- sbit three=P0^4;
- sbit exchange=P0^5;
- sbit stop=P0^6;
- sbit led=P3^6;
- sbit tt=P3^7;
- void delay(int x)
- {
- intw,q;
- for(w=0;w<x;w++)
- for(q=0;q<120;q++);
- }
- void display(int i,int j,int a,int b)
- {
- P2= 0x01;
- P1= seg[i/10];
- delay(1);
- P2= 0x00;
- P2= 0x02;
- P1= seg[i%10];
- delay(1);
- P2= 0x00;
-
- P2= 0x04;
- P1= seg[j/10];
- delay(1);
- P2= 0x00;
-
- P2= 0x08;
- P1= seg[j%10];
- delay(1);
- P2 = 0x00;
-
- P2=0x10;
- P1= seg[a/10];
- delay(1);
- P2=0x00;
-
- P2=0x20;
- P1 = seg[a%10];
- delay(1);
- P2= 0x00;
-
- P2 = 0x40;
- P1= seg[b/10];
- delay(1);
- P2= 0x00;
-
- P2=0x80;
- P1 = seg[b%10];
- delay(1);
- P2= 0x00;
-
- }
- void time0() interrupt 1
- {
- TH0 = 0xb1;
- TL0= 0xe0;
- m++;
- if(m==50)
- {
- m=0;
- j--;
- if(j==-1)
- j= 59;
- n++;
- if(n==60)
- {
- n=0;
- i--;
- if(i==0&&j==0){
- ET0=1;
- TR0= 1;
- }
- }
- }
- display(i,j,a,b);
- }
- void main()
- {
- P0= 0x00;
- display(12,0,0,0);
- TMOD= 0x01;
- TH0= 0xb1;
- TL0= 0xe0;
- IE= 0x82;
- TR0= 1;
- while(1)
- {
- if(aa==1&&one==1)
- {a++;display(i, j, a, b);while(one==1);}
- elseif(aa==1&&two==1)
- {a=a+2;display( i, j, a, b);while(two==1);}
- elseif(aa==1&&three==1)
- {a=a+3;display(i, j, a, b);while(three==1);}
- elseif(bb==1&&one==1)
- {b++;display(i, j, a, b);while(one==1);}
- elseif(bb==1&&two==1)
- {b=b+2;display( i, j, a, b);while(two==1);}
- elseif(bb==1&&three==1)
- {b=b+3;display( i, j, a, b);while(three==1);}
- else if(exchange==1)
- {temp= a;a = b;b = temp;delay(500);}
- elseif(stop==1) {ET0=0;TR0=0;while(stop==1);while(stop==0);while(stop==1){ET0=1;TR0=1;}}
- }
- }
复制代码
|