本人菜鸟一只,模仿了个0-999999计数器,在加一的时候,其它数码管有抖动,不知要怎么消除,请高手赐教指点下,谢谢
单片机源程序如下:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- sbit dula=P2^6;
- sbit wela=P2^7;
- void delayms(uint);
- void smg(ulong,ulong,ulong,ulong,ulong,ulong);
- uchar num1,num,sw,w,k,b,s,g;
- uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
-
- void main()
- {
- TMOD=0X01;
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- EA=1;
- TR0=1;
- ET0=1 ;
- while(1)
- {
- smg(sw,w,k,b,s,g);
- }
- }
- void smg(ulong sw,ulong w,ulong k,ulong b,ulong s,ulong g)
- {
-
- dula=1;
- P0=table[g];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xdf;
- wela=0;
- delayms(1);
-
- dula=1;
- P0=table[s];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xef;
- wela=0;
- delayms(1);
-
- dula=1;
- P0=table[b];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xf7;
- wela=0;
- delayms(1);
-
- dula=1;
- P0=table[k];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfb;
- wela=0;
- delayms(1);
-
- dula=1;
- P0=table[w];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfe;
- wela=0;
- delayms(1);
-
- dula=1;
- P0=table[sw];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfd;
- wela=0;
- delayms(1);
- }
- void delayms(uint xms)
- {
- uint i,j;
- for(i=xms;i>0;i--)
- for(j=10;j>0;j--);
- }
-
- void T0_time()interrupt 1
- {
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- num1++;
- if(num1==20)
- {
- num1=0;
- num++;
- if(num==999999)
- num=0;
- sw=num/100000;
- w=num%100000/10000;
- k=num%10000/1000;
- b=num%1000/100;
- s=num%100/10;
- g=num%10;
- }
- }
复制代码
|