任意定時的倒計時
單片機源程序:
- #include<reg52.h>
- #define seatport P1
- #define segport P0
- int b;
- int round;
- unsigned char seatt[6]={0x1f,
- 0x2f,
- 0x37,
- 0x3b,
- 0x3d,
- 0x3e};
- unsigned char segt[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- void delayms(int s)
- {
- int i,j;
- for(j=s;j>0;j--)
- for(i=0;i<150;i++)
- ;
- }
- void converthsmandshow(int dat)
- {
- int h,s,m;
- int h1,h0,s1,s0,m1,m0;
- h=dat%(3600*24)/3600;
- s=(dat%3600)/60;
- m=dat%60;
-
- h1=h/10;
- h0=h%10;
- s1=s/10;
- s0=s%10;
- m1=m/10;
- m0=m%10;
-
- seatport=seatt[5];
- segport=segt[m0];
- delayms(1);
-
- seatport=seatt[4];
- segport=segt[m1];
- delayms(1);
-
- seatport=seatt[3];
- segport=segt[s0]+0x80;
- delayms(1);
-
- seatport=seatt[2];
- segport=segt[s1];
- delayms(1);
-
- seatport=seatt[1];
- segport=segt[h0]+0x80;
- delayms(1);
-
- seatport=seatt[0];
- segport=segt[h1];
- delayms(1);
- }
- void timerone() interrupt 3
- {
- TH1=0X3C;
- TL1=0xB0;
- round++;
- if(round==20)
- {
- b--;
- round=0;
- }
- }
- void main(void)
- {
- b=999;
- round=0;
- TMOD=0x10;
- EA=1;
- ET1=1;
- TH1=0x3C;
- TL1=0xB0;
- TR1=1;
- while(1)
- {
- converthsmandshow(b);
- }
- }
復制代碼
全部資料下載地址:
倒計時.zip
(637 Bytes, 下載次數: 42)
2017-6-7 16:06 上傳
點擊文件名下載附件
|