设num初值=2020即可。
- #include <reg51.h>
- #define seg_bit P2
- #define seg_dat P3
- #define uint unsigned int
- #define uchar unsigned char
- uchar code numtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar code bittab[]={0xfe,0xfd,0xfb,0xf7};
- uchar data disbuf[4];
- uchar t,i;
- uint num=2020;
- void delayms(uint xms)//延时程序
- {
- uint i,j;
- for(i=xms;i>0;i--)
- for(j=110;j>0;j--);
- }
- void main()
- {
- TMOD=0X01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1;
- ET0=1;
- TR0=1;
- while(1)
- {
- disbuf[0]=numtab[num%10];
- disbuf[1]=numtab[num/10%10]|0x80;
- disbuf[2]=numtab[num/100%10];
- disbuf[3]=numtab[num/1000%10];
- seg_dat=0x00;
- seg_bit=bittab[i];
- seg_dat=disbuf[i];
- i++;
- i%=4;
- delayms(1);
- }
- }
- void jishu() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- t++;
- if(t==2)
- {
- t=0;
- num++;
- if(num>9999)
- num=2020;
- }
- }
复制代码 |