|
c語(yǔ)言秒表單片機(jī)源程序如下:
- //**************************************************************************************
- // File name :**.c
- //
- // Descriptions :
- //
- //**************************************************************************************
- //**************************************************************************************
- //Revision History
- //------------------
- //
- //01 ****-**-** 10:07 Park
- // Create the file.
- //**************************************************************************************
- #include<reg51.h>
- sbit dula=P2^6;
- sbit wela=P2^7;
- sbit beep=P3^7;
- unsigned char j,k,a1,a0,s=60;
- unsigned int m;
- unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
- 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- void delay(unsigned char i)
- {
- for(j=i;j>0;j--)
- for(k=125;k>0;k--);
- }
- void display(unsigned char sh_c,unsigned char g_c)
- {
- dula=0;
- P0=table[sh_c];
- dula=1;
- dula=0;
-
- wela=0;
- P0=0xfe;
- wela=1;
- wela=0;
- delay(5);
-
- P0=table[g_c];
- dula=1;
- dula=0;
-
- P0=0xfd;
- wela=1;
- wela=0;
- delay(5);
- }
- void main()
- {
- TMOD=0x01;
- TR0=1;
- TH0=(65536-46080)/256;// 由于晶振為11.0592,故所記次數(shù)應(yīng)為46080,計(jì)時(shí)器每隔50000微秒發(fā)起一次中斷。
- TL0=(65536-46080)%256;//46080的來(lái)歷,為50000*11.0592/12
- ET0=1;
- EA=1;
- while(1)
- {
- if(m==20)
- { m=0;
- s--;
- }
- a0=s%10;
- a1=s/10;
- display(a1,a0);
- if(s==0)
- {
- TR0=0;//時(shí)間到,定時(shí)器關(guān)閉
- beep=0;//蜂鳴器響,報(bào)時(shí)。
- }
- }
- }
- void time0() interrupt 1
- {TH0=(65536-46080)/256;
- TL0=(65536-46080)%256;
- m++;
- }
復(fù)制代碼
所有資料51hei提供下載:
10 C語(yǔ)言秒表.zip
(203.46 KB, 下載次數(shù): 33)
2018-5-19 22:05 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|