|
|
51單片機(jī)主控的數(shù)字頻率計(jì)設(shè)計(jì)資料,我的畢業(yè)設(shè)計(jì) 仿真加源碼
下面是實(shí)物圖:
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載):
單片機(jī)源程序如下:
- #include <reg52.h>
- sbit led0=P2^6;//換擋燈
- sbit led1=P2^7;
- void delay_ms(int x);
- unsigned char code table[]={ //不顯示小數(shù)點(diǎn)的數(shù)碼管段值表
- 0x3f,0x06,0x5b,0x4f,0x66,
- 0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char code tablewe[]={ //顯示小數(shù)點(diǎn)的數(shù)碼管段值表
- 0xbf,0x86,0xdb,0xcf,
- 0xe6,0xed,0xfd,0x87,
- 0xff,0xef};
- int count1=0;
- int time0=0;
- unsigned char a,b,c,d;
- unsigned long int f=0;
- void main()
- {
- TMOD=0x51; //定時(shí)器1工作方式為16位計(jì)數(shù)器,定時(shí)器0工作方式為16位定時(shí)器
- TH0=(65536-46080)/256;//定時(shí)50ms
- TL0=(65536-46080)%256;
- EA=1;//開總中斷
- ET0=1;//開定時(shí)器0中斷
- TR0=1;//啟動(dòng)定時(shí)器0
- ET1=1;//開定時(shí)器1中斷
- IT1=1;//設(shè)置計(jì)數(shù)方式為下降沿計(jì)數(shù)
- TR1=1;//啟動(dòng)計(jì)數(shù)器1
- led0=1;//開始讓兩個(gè)燈都滅
- led1=1;
- while(1)
- {
- if(time0==20) //定時(shí)1s時(shí)間到
- {
- TR1=0; //關(guān)閉定時(shí)計(jì)數(shù)器
- TR0=0;
- f=count1*65536+TH1*256+TL1; //1s時(shí)間測(cè)得的信號(hào)下降沿個(gè)數(shù),即頻率
- if(f<1000) //如果頻率小于1000Hz
- {
- led0=0;//Hz檔燈亮
- led1=1;
- while(1)
- {
- a=f/100;
- P2=0x8f; //消隱
- P0=table[a]; //數(shù)碼管的百位值
- P2=0x8d;
- delay_ms(1); //延時(shí)1ms
- b=(f%100)/10;
- P2=0x8f;
- P0=table[b]; //數(shù)碼管的十位值
- P2=0x8b;
- delay_ms(1);
- c=f%100%10;
- P2=0x8f;
- P0=table[c]; //數(shù)碼管的個(gè)位值
- P2=0x87;
- delay_ms(1);
- }
- }
- if(f>=1000&&f<10000) //從1000Hz開始,小數(shù)點(diǎn)的位置有所變化,采用四位數(shù)碼管顯示
- {
- led0=1;//KHz檔燈亮
- led1=0;
- while(1)
- {
- a=f/1000;
- P2=0x6f;
- P0=tablewe[a]; //小數(shù)點(diǎn)的位置在第一位
- P2=0x6e;
- delay_ms(1);
- b=(f%1000)/100;
- P2=0x6f;
- P0=table[b];
- P2=0x6d;
- delay_ms(1);
- c=(f%1000%100)/10;
- P2=0x6f;
- P0=table[c];
- P2=0x6b;
- delay_ms(1);
- d=f%1000%100%10;
- P2=0x6f;
- P0=table[d];
- P2=0x67;
- delay_ms(1);
- }
- }
- if(f>=10000&&f<100000)
- {
- while(1)
- {
- a=f/10000;
- P2=0x6f;
- P0=table[a];
- P2=0x6e;
- delay_ms(1);
- b=(f%10000)/1000;
- P2=0x6f;
- P0=tablewe[b]; //小數(shù)點(diǎn)的位置在第二位
- P2=0x6d;
- delay_ms(1);
- c=f%10000%1000/100;
- P2=0x6f;
- P0=table[c];
- P2=0x6b;
- delay_ms(1);
- d=f%10000%1000%100/10;
- P2=0x6f;
- P0=table[d];
- P2=0x67;
- delay_ms(1);
- }
- }
- if(f>=100000&&f<1000000)
- {
- while(1)
- {
- a=f/100000;
- P2=0x6f;
- P0=table[a];
- P2=0x6e;
- delay_ms(1);
- b=(f%100000)/10000;
- P2=0x6f;
- P0=table[b];
- P2=0x6d;
- delay_ms(1);
- c=(f%100000%10000)/1000;
- P2=0x6f;
- P0=tablewe[c]; //小數(shù)點(diǎn)的位置在第三位
- P2=0x6b;
- delay_ms(1);
- d=(f%100000%10000%1000)/100;
- P2=0x6f;
- P0=table[d];
- P2=0x67;
- delay_ms(1);
- }
- }
- if(f>=1000000) //超出范圍的顯示
- {
- while(1)
- {
- P2=0xcf;
- P0=0x7f;
- P2=0xce;
- delay_ms(1);
- P2=0xcf;
- P0=0x7f;
- P2=0xcd;
- delay_ms(1);
- P2=0xcf;
- P0=0x7f;
- P2=0xcb;
- delay_ms(1);
- P2=0xcf;
- P0=0x7f;
- P2=0xc7;
- delay_ms(1);
- }
- }
- }
- }
-
- }
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
51單片機(jī)數(shù)字頻率計(jì).rar
(3.25 MB, 下載次數(shù): 230)
2017-7-24 13:28 上傳
點(diǎn)擊文件名下載附件
|
|