怎么把时间加到一起?
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit dula=P2^6;
- sbit wela=P2^7;
- sbit r1=P1^0;
- sbit g1=P1^2;
- sbit y1=P1^1;
- sbit r2=P1^4;
- sbit g2=P1^6;
- sbit y2=P1^5;
- uchar time,num,deng,deng1;
- uchar code wei[]={0xfe,0xfd,0xbf,0x7f};
- uchar code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar dis[4]={0,0,0,0};
- void convert();
- void display();
- void close();
- void delay(unsigned int x)
- {
- uchar m,k;
- for(m=x;m>0;m--)
- for(k=125;k>0;k--);
- }
- void close()
- {
- uchar i;
- for(i=0;i<4;i++)
- {
- P0=wei[i];
- wela=1;wela=0;
- P0=0xff;
- P0=duan[dis[i]];
- dula=1;dula=0;
- delay(20);
-
- }
- }
- void main()
- {
- TMOD=0x01;
- TR0=1;
- TH0=(65536-46080)/256;
- TL0=(65536-46080)%256;
- EA=1;
- ET0=1;
- while(1)
- {
- close();
- convert();
- display();
- }
- }
- void convert()
- {
- dis[0]=time/10;
- dis[1]=time%10;
- dis[2]=time/10;
- dis[3]=time%10;¡¤¡¤
- }
- void time0() interrupt 1
- {
- TH0=(65536-46080)/256;
- TL0=(65536-46080)%256;
- num++;
- if(num==20)
- {
- num=0;
- time--;
-
- }
- }
- void display()
- {
- if(time==0xff)
- {
-
- deng++;
- if(deng==4)
- deng=0;
- switch(deng)
- {
- case 0: time=10;
- r2=0;g2=1;y2=1;
- r1=1;g1=0;y1=1;
- break;
- case 1: time=3;
- r2=0;g2=1;y2=1;
- r1=1;g1=1;y1=0;
- break;
- case 2: time=10;
- r2=1;g2=0;y2=1;
- r1=0;g1=1;y1=1;
- break;
- case 3: time=3;
- r2=1;g2=1;y2=0;
- r1=0;g1=1;y1=1;
- break;
- }
- }
- }
复制代码
仿真的时候看的好难受、
|