当我把delay(5000)改成delay(10000)后,数字管上数字滚动延时时间变很长也不规律
单片机源程序:
- #include<reg52.h>
- #include<intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- uchar temp,aa,num;
- sbit duan=P2^2;
- sbit wei=P2^3;
- uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- void delay(uint t);
- void InitTimer();
- void main()
- {
- num=0;
- InitTimer();
- temp=0xfe;
- P1=temp;
- duan=1;
- P0=table[0];
- duan=0;
- wei=1;
- P0=0x00;
- wei=0;
- while(1)
- {
- delay(5000);
- temp=_crol_(temp,1);
- P1=temp;
- if(aa==40)
- {
- aa=0;
- num++;
- if(num==16)
- num=0;
- duan=1;
- P0=table[num];
- duan=0;
-
- }
-
- }
- }
- void delay(uint t)
- {
- while(t--);
- }
- void InitTimer()
- {
- TMOD = 0x01;
- TH0 = (65536-50000)/256;
- TL0 = (65536-50000)%256;
- EA = 1;
- ET0 = 1;
- TR0 = 1;
- }
- void Timer() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- aa++;
- }
复制代码
|