6位數(shù)字顯示頻率計(jì)數(shù)器電路及51單片機(jī)源程序
1.頻率計(jì)算器功能
利用AT89S51單片機(jī)的T0、T1的定時(shí)計(jì)數(shù)器功能,來(lái)完成對(duì)輸入的信號(hào)進(jìn)行頻率計(jì)數(shù),計(jì)數(shù)的頻率結(jié)果通過(guò)8位動(dòng)態(tài)數(shù)碼管顯示出來(lái)。要求能夠?qū)?-250KHZ的信號(hào)頻率進(jìn)行準(zhǔn)確計(jì)數(shù),計(jì)數(shù)誤差不超過(guò)±1HZ。
2.電路原理圖
3.程序設(shè)計(jì)內(nèi)容
(1).定時(shí)/計(jì)數(shù)器T0和T1的工作方式設(shè)置,由圖可知,T0是工作在計(jì)數(shù)狀態(tài)下,對(duì)輸入的頻率信號(hào)進(jìn)行計(jì)數(shù),但對(duì)工作在計(jì)數(shù)狀態(tài)下的T0,最大計(jì)數(shù)值為fOSC/24,由于fOSC=12MHz,因此:T0的最大計(jì)數(shù)頻率為250KHz。對(duì)于頻率的概念就是在一秒只數(shù)脈沖的個(gè)數(shù),即為頻率值。所以T1工作在定時(shí)狀態(tài)下,每定時(shí)1秒中到,就停止T0的計(jì)數(shù),而從T0的計(jì)數(shù)單元中讀取計(jì)數(shù)的數(shù)值,然后進(jìn)行數(shù)據(jù)處理。送到數(shù)碼管顯示出來(lái)。
(2).T1工作在定時(shí)狀態(tài)下,最大定時(shí)時(shí)間為65ms,達(dá)不到1秒的定時(shí),所以采用定時(shí)50ms,共定時(shí)20次,即可完成1秒的定時(shí)功能。
5.C語(yǔ)言源程序
C程序
#include AT89X51.h>
unsigned CHAR code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned CHAR code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x00,0x40};
unsigned CHAR dispbuf[8]={0,0,0,0,0,0,10,10};
unsigned CHAR temp[8];
unsigned CHAR dispcount;
unsigned CHAR T0count;
unsigned CHAR timecount;
bit flag;
unsigned long x;
void main(void)
{
unsigned CHAR i;
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(6553*000)/256;
TL1=(6553*000)%6;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
51單片機(jī)相關(guān)文章:51單片機(jī)教程
塵埃粒子計(jì)數(shù)器相關(guān)文章:塵埃粒子計(jì)數(shù)器原理
評(píng)論