数码管时钟,错误太多,望各位指导.........
时间:10-02
整理:3721RD
点击:
- #include<reg52.h>
- #define uc unsigned char;
- #define ui unsigned int;
- sbit d=P2^6;
- sbit w=P2^7;
- sbit led1=P1^0;
- uc code table1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uc code table2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- void delayms(ui);
- uc n1,n2,n3,n4,x,shi1,ge1,shi2,ge2,shi3,ge3,shi4,ge4,m;
- void display(uc,uc,uc,uc,uc,uc,uc,uc);
- void main()
- {
- TMOD=0x11;
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- TH1=(65536-45872)/256;
- TL1=(65536-45872)%256;
- EA=1;
- ET0=1;
- ET1=1;
- TR0=1;
- TR1=1;
- while(1)
- {
- display(shi1,ge1,shi2,ge2,shi3,ge3,shi4,ge4);
- }
- }
- void display(uc shi1,uc ge1,uc shi2,uc ge2,uc shi3,uc ge3,uc shi4,uc ge4)
- {
- for(x=1;x<5;x++)
- {
- d=1;
- P0=table1[gex];
- d=0;
- P0=0xff;
- w=1;
- P0=table1[2*x-1];
- w=0;
- delayms(1);
- d=1;
- P0=table1[shix];
- d=0;
- P0=0xff;
- w=1;
- P0=table1[2*x];
- w=0;
- delayms(1);
- }
- }
- void delayms(ui xms)
- {
- ui i,j;
- for(i=xms;i>0;i--)
- for(j=110;j>0;j--)
- }
- void T1_time()interrupt3
- {
- TH1=(65536-45872)/256;
- TL1=(65536-45872)%256;
- m++;
- if(m==20)
- {
- m=0;
- n1++;
- if(n1==60)
- {
- n1=0;
- n2++;
- if(n2==60)
- {
- n2=1;
- n3++;
- if(n3==24)
- {
- n3=0;
- n4++;
- shi4=n4/10;
- ge4=n4%10;
- }
- shi3=n3/10;
- ge3=n3%10;
- }
- shi2=n2/10;
- ge2=n2%10;
- }
- shi1=n1/10;
- ge1=n1%10;
- }
- }
顶顶。11
自顶一个!
太乱了