初学者 弄了一个60分钟倒计时,为什么 数码管一直在闪烁、
- #include <REGX51.H>
- #include <intrins.h>
- void Delay1000ms();
- void Delay5ms();
- char temp[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
- void main (void)
- {
- char i = 10;
- char shi = 5;
- char bai = 9;
- char qian = 5;
- while(1)
- {
- P2 = temp[i--];
- Delay1000ms();
- if(i<0)i=9,shi--;
- if(shi<0)shi=5,bai--;
- if(bai<0)bai=9,qian--;
- if(qian<0)i=0,shi=0,bai=0,qian=0;
-
- {
- P3_2 = 1;
- P3_3 = 1;
- P3_4 = 1;
- P2 = temp[qian];
- P3_1 = 0;
- Delay5ms();
- P3_1 = 1;
- P3_3 = 1;
- P3_4 = 1;
- P2 = temp[bai];
- P3_2 = 0;
- Delay5ms();
- P3_1 = 1;
- P3_2 = 1;
- P3_4 = 1;
- P2 = temp[shi];
- P3_3 = 0;
- Delay5ms();
- P3_1 = 1;
- P3_2 = 1;
- P3_3 = 1;
- P2 = temp[i];
- P3_4 = 0;
- Delay5ms();
- }
- }
- }
- void Delay1000ms() //@11.0592MHz
- {
- unsigned char i, j, k;
- _nop_();
- i = 3;
- j = 26;
- k = 223;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- }
- void Delay5ms() //@11.0592MHz
- {
- unsigned char i, j;
- i = 9;
- j = 24;
- do
- {
- while (--j);
- } while (--i);
- }
复制代码
|