单片机测频程序(下到20hz上到29k)

来源:本站
导读:目前正在解读《单片机测频程序(下到20hz上到29k)》的相关信息,《单片机测频程序(下到20hz上到29k)》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《单片机测频程序(下到20hz上到29k)》的详细说明。
简介:本文主要介绍了单片机测频程序(下到20hz上到29k)。

/* 单片机测频 程序 下到 20hz 上到 29k */

/*如果想要测更高频率可用模拟开关加分频器*/

/*说明: 头文件中调用的“lcd1602.h”只需要把我发的lcd1602的子程序做一个h文件即可*/

#i nclude "AT89X52.h"

#i nclude "stdio.h"

#i nclude " absacc.h "

#i nclude <intrins.h>

#i nclude <math.h>

#i nclude "lcd1602.h"

sbit F_in=P1^0;

bit int_flag;

unsigned int frequency;

void Display(void);

void Mcu_init(void);

void Measure_F(void);

void Measure_T(void);

void Frequency_Measure(void);

void main()

{

Mcu_init();

while(1)

{

Frequency_Measure();

Display();

}

}

void time0(void) interrupt 1

{

int_flag=1;

}

void Frequency_Measure(void)

{

if(frequency<2000)

Measure_T();

else if(frequency>=2000)

Measure_F();

}

void Measure_F(void)

{

bit state_old=0,state_new=0;

unsigned int f_count=0;

int_flag=0;

TH0=-50000/256;

TL0=-50000%256;

TR0=1;

while(1)

{

state_new=F_in;

if(state_old!=state_new)

f_count++;

state_old=state_new;

if(int_flag)

{

TR0=0;

frequency=f_count*10;

return;

}

}

}

void Measure_T(void)

{

bit state_old=0,state_new=0;

unsigned char temp_flag=0;

unsigned int t_count;

TH0=0;

TL0=0;

while(1)

{

state_new=F_in;

if(state_old&&!state_new)

{

temp_flag++;

TR0=1;

}

if(temp_flag==2)

{

TR0=0;

t_count=TH0*256+TL0;

frequency=1000000/t_count;

return;

}

state_old=state_new;

}

}

void Display(void)

{

unsigned char a,b,c,d,e;

a=frequency/10000;

b=frequency%10000/1000;

c=frequency%1000/100;

d=frequency%100/10;

e=frequency%10;

LCD_string(LINE1,0,"F-measure:");

LCD_char(LINE1,0x0b,a|0x30);

LCD_char(LINE1,0x0c,b|0x30);

LCD_char(LINE1,0x0d,c|0x30);

LCD_char(LINE1,0x0e,d|0x30);

LCD_char(LINE1,0x0f,e|0x30);

if(frequency<2000)

LCD_string(LINE2,0,"Now is measure T");

else

LCD_string(LINE2,0,"Now is measure F");

}

void Mcu_init(void)

{

EA=1;

ET0=1;

TR0=1;

TMOD=0x01;

TH0=-(50000/256);

TL0=-(50000%256);

LCD_init();

LCD_string(LINE1,0x00," ");

LCD_string(LINE1,0x00," ");

}

提醒:《单片机测频程序(下到20hz上到29k)》最后刷新时间 2024-03-14 01:02:55,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《单片机测频程序(下到20hz上到29k)》该内容的真实性请自行鉴别。