|
例3 00-59秒計(jì)時(shí)器的proteus仿真電路及C語言程序設(shè)計(jì)
0.png (19.45 KB, 下載次數(shù): 57)
下載附件
2017-1-7 21:15 上傳
- #include <REG51.H>
- #define uint unsigned int
- #define uchar unsigned char
- uint sec;
-
-
- uint tcnt;
- unsigned char table[]=
- {0xc0,0xf9,0xa4,0xb0,0x99,
- 0x92,0x82,0xf8,0x80,0x90,
- 0xbf};
- //共陰數(shù)碼管 0-9 '-'
-
- //顯示延時(shí) 函數(shù)
- void delay(unsigned int z)
- {
- unsigned int x;
- unsigned char y;
- for(x=z;x>0;x--)
- for(y=200;y>0;y--);
- }
- void display()
- {
-
- P3=0xfd;P2=0x00;
- P2=table[sec%10];
- delay(3);
-
- P3=0xfe;P2=0x00;
- P2=table[sec/10];
- delay(3);
-
- }
- main()
- {
-
- TMOD=0x02; //設(shè)置模式為定時(shí)器T0的模式2 (8位自動(dòng)重裝計(jì)數(shù)初值的計(jì)數(shù)值)
- TH0=0x06; //設(shè)置計(jì)數(shù)器初值,靠TH0存儲(chǔ)重裝的計(jì)數(shù)值X0=256-250=6
- TL0=0x06;
- TR0=1; //啟動(dòng)T0
- ET0=1; //開啟定時(shí)器T0中斷允許
- EA=1;
-
- while(1)
- {
-
- display();
-
- }
- }
- void t0(void)interrupt 1 using 0 //t0的中斷程序
- {
- tcnt++;
- if(tcnt==4000)//定時(shí)器的定時(shí)計(jì)數(shù),4000次250us為1秒
- {
- tcnt=0;
-
- sec++;
- if(sec==60)
- {
- sec=0;
-
- }
- }
- }
復(fù)制代碼
0.png (77.04 KB, 下載次數(shù): 77)
下載附件
2017-1-7 21:15 上傳
所有資料下載:
例3 00-59秒計(jì)時(shí)器的proteus仿真電路及C語言程序設(shè)計(jì).zip
(47.7 KB, 下載次數(shù): 43)
2016-12-8 20:46 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|