實訓期間根據課程相關要求完成的數字頻率計的設計。
利用定時/計數器完成簡易頻率計的設計、仿真、調試。
測量結果通過六位數碼管動態顯示出來。
上傳文件包括仿真原理圖、源程序代碼、以及所有壓縮文件。
望可以提供參考性意見。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載):
360截圖20180213135949594.jpg (87.57 KB, 下載次數: 37)
下載附件
2018-2-13 14:20 上傳
單片機源程序:
- #include<AT89X51.H>
- #define uchar unsigned char
- uchar code dispcode[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar count,num,dat1,dat2,dat3,dat4,dat5,dat6;
- void delayms(uchar ms)
- { uchar i,j;
- for(j=ms;j>0;j--)
- for(i=60;i>0;i--);
- }
- void display()
- { P2=0xff;
- P0=dispcode[dat1];
- P2=0xdf;
- delayms(10);
- P2=0xff;
- P0=dispcode[dat2];
- P2=0xef;
- delayms(10);
- P2=0xff;
- P0=dispcode[dat3];
- P2=0xf7;
- delayms(10);
- P2=0xff;
- P0=dispcode[dat4];
- P2=0xfb;
- delayms(10);
- P2=0xff;
- P0=dispcode[dat5];
- P2=0xfd;
- delayms(10);
- P2=0xff;
- P0=dispcode[dat6];
- P2=0xfe;
- delayms(10);
- }
- void calc()
- { long frequency;
- frequency=num*65536+TH0*256+TL0;
- dat6=frequency%10;
- frequency=frequency/10;
- dat5=frequency%10;
- frequency=frequency/10;
- dat4=frequency%10;
- frequency=frequency/10;
- dat3=frequency%10;
- frequency=frequency/10;
- dat2=frequency%10;
- frequency=frequency/10;
- dat1=frequency;
- }
- main()
- { TMOD=0x15;
- TH1=(65536-50000)/256;
- TL1=(65536-50000)%256;
- TH0=0x00;
- TL0=0x00;
- IE=0x8a;
- TCON=0x50;
- while(1)
- { display();
- }
- }
- void time0() interrupt 1
- {
- num++;
- }
- void time1() interrupt 3
- { count++;
- TH1=(65536-50000)/256;
- TL1=(65536-50000)%256;
- if(count==20)
- {TR0=0;
- calc();
- TH0=0x00;
- TL0=0x00;
- count=0x00;
- num=0x00;
- TR0=1;
- }
- }
-
復制代碼
0.png (50.89 KB, 下載次數: 48)
下載附件
2018-2-13 22:42 上傳
全部資料51hei下載地址:
頻率計.zip
(60.4 KB, 下載次數: 58)
2018-2-13 14:22 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|