用89C2051做的数字频率计

[复制链接]
查看1657 | 回复0 | 2011-9-7 23:02:06 | 显示全部楼层 |阅读模式
<





用89C2051做的数字频率计

点击查看高清晰电路
measure.c51 ====================================

/************************************************************************/
/* */
/* Frequency Meter 5Hz ... 125MHz Test Program */
/* */
/* Author: Peter Dannegger */
/* danni@specs.de */
/* */
/************************************************************************/
#include \"main.h\"
#include \"measure.h\"
#include \"display.h\"
#include
#define BAUD 9600

void main( void )
{
uchar idata s[DISPLAYMEM];
PCON |= SMOD_; // initialization UART
SCON = TI_ REN_ SM1_;
TMOD = T1_M1_ T0_M0_ T0_M1_; // T0: splitt timer
// T1: baud rate
TH1 = (uchar) -(0.5 XTAL / 12.0 / 16 / BAUD);
TL1 = -1;
for(;;){
measure_start();
while( measure_poll() == 0 );
display( measure_read(), s );
puts( s );
}
}

============= measure.h ==================================================

void measure_start( void );
bit measure_poll( void );
float measure_read( void );

========== display.c51 =====================================================
/************************************************************************/
/* */
/* Display 5 digit floating point number */
/* */
/* Author: Peter Dannegger */
/* danni@specs.de */
/* */
/************************************************************************/
#include \"main.h\"

void display ( float val, uchar idata *ptr )
{
uchar hz, num, i, dp;
for( dp = 1; val >= 10; dp ) // normalize (x.xxxx)
val *= 0.1; // 3 times faster as \"val /= 10;\"
hz = 0;
if( dp > 6 ){ // MHz ?
dp -= 6;
hz =
热帖推荐
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则