|
0.png (16.2 KB, 下載次數(shù): 108)
下載附件
2016-5-29 15:44 上傳
0.png (70.5 KB, 下載次數(shù): 101)
下載附件
2016-5-29 15:44 上傳
仿真文件下載:http://www.torrancerestoration.com/bbs/dpj-50777-1.html
- #include <reg51.h>
- char disNumber[10] = {0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x2, 0x78, 0x0, 0x10};
- char ONE = 0;
- char TWO = 0;
- char THERE = 0;
- char FOUR = 0;
- int count = 0;
- void delay5ms(void) //誤差 0us
- {
- unsigned char a,b;
- for(b=19;b>0;b--)
- for(a=130;a>0;a--);
- }
- void delay950ms(void) //誤差 0us
- {
- unsigned char a,b,c;
- for(c=227;c>0;c--)
- for(b=246;b>0;b--)
- for(a=7;a>0;a--);
- }
- void time1() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- count++;
- if (count % 2 == 0)
- FOUR++;
- if (FOUR >= 10)
- {
- FOUR = 0;
- THERE++;
- }
- if (THERE >= 10)
- {
- THERE = 0;
- TWO++;
- }
- if (TWO >= 10)
- {
- TWO = 0;
- ONE++;
- }
- }
- int main(void)
- {
- int i = 0;
-
-
- TMOD=0x01;//設(shè)置定時器0為工作方式1
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1;//打開中斷總開關(guān)
- ET0=1;//開定時器0中斷
- TR0=1;//啟動定時器0
-
- while (1)
- {
- P3 = 0;
- P2 = 0X1;
- P0 = disNumber[ONE];
- delay5ms();
-
- P2 = 0X2;
- P0 = disNumber[TWO];
- delay5ms();
- i++;
- P2 = 0X4;
- P0 = disNumber[THERE];
- delay5ms();
- i++;
- P2 = 0X8;
- P0 = disNumber[FOUR];
- delay5ms();
- i++;
- }
-
- return 0;
- }
復(fù)制代碼
|
評分
-
查看全部評分
|