单片机数字频率计
通过单片机实现对于正弦波频率、幅值的测量。
#include <REGX52.H>
#include "LCD1602.h"
#include "Delay.h"
#include "MCP3208.h"
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
bit flag;
unsigned long x;
unsigned int P_date = 0; P_max = 0;
void HzCal(void)
{
unsigned char i;
x=T0count*65536+TH0*256+TL0;
LCD_ShowNum(1,5,x,4);
P_date = GET_MCP3208();
if(P_date > P_max)
{
P_max = P_date;
}
LCD_ShowNum(2,5,P_max/3,4);
timecount=0;
T0count=0;
}
int main()
{
LCD_Init();
LCD_ShowString(1,1,"FRE:");
LCD_ShowString(2,1,"AMP:");
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
while(1)
{
if(flag==1)
{
flag=0;
HzCal();
TH0=0;
TL0=0;
TR0=1;
}
}
}
void t0(void) interrupt 1 using 0
{
T0count++;
}
void t1(void) interrupt 3 using 0
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
timecount++;
if(timecount==200)
{
TR0=0;
timecount=0;
flag=1;
P_max = 0;
}
}