|
初學(xué)者,嘗試做一個(gè)60S的倒計(jì)時(shí)。實(shí)驗(yàn)圖如下;
單片機(jī)上傳.png (23.31 KB, 下載次數(shù): 56)
下載附件
2019-7-1 09:02 上傳
這個(gè)程序是60S倒計(jì)時(shí),達(dá)到0時(shí),重新賦初值為60,繼續(xù)進(jìn)行減計(jì)時(shí),循環(huán)往復(fù)。
單片機(jī)源程序如下:
- //60S倒計(jì)時(shí)程序
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar temp,bai,shi,ge,num;
- uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- void delay(uint z);
- void main()
- {
- temp=60;
- num=0;
- P1=0x00;
- TMOD=0x01;
- TH0=(65536-55536)/256;
- TL0=(65536-55536)%256;
- EA=1; ET0=1; TR0=1;
- while(1)
- {
- shi = temp/10;
- ge = temp%10;
- P1 = 0xFD;
- P2 = table[shi];
- P1 = 0xFD;
- delay(5);
- P1 = 0xFE;
- P2 = table[ge];
- delay(5);
- }
- }
- //定時(shí)器0外部中斷方式
- void time_0() interrupt 1
- {
- TH0=(65536-55536)/256;
- TL0=(65536-55536)%256;
- num ++;
- if(num == 18)
- {
- temp --;
- num = 0;
- if(temp == -1)
- {
- temp = 60;
- }
- }
- }
- //延時(shí)程序
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
復(fù)制代碼 全部資料51hei下載地址:
60S程序+仿真.zip
(87.35 KB, 下載次數(shù): 55)
2019-7-1 09:16 上傳
點(diǎn)擊文件名下載附件
60S倒計(jì)時(shí) 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|