并伴有蜂鸣器报警功能,测试范围为0~200mv,希望和大家交流学习!
仿真原理图如下:
单片机源程序如下:
- #include <reg51.h>
- #include "LCD1602.h"
- #include "TLC2543.h"
- #include "delay.h"
- #include <intrins.h>
- #include <stdio.h>
- unsigned int zyx;
- unsigned int ADresult[1];
- unsigned int Freq=0;
- void Timer_Init();// 定时器声明
- unsigned char cnt_t1=0;
- sbit fengming=P2^0;
- main(void)
- {
- unsigned char Vrms[4],Vmax[4],Freq_temp[5];
-
- LCD1602_Init();
- Timer_Init();
- LCD1602_SendString(1,0,"V=");
- LCD1602_SendString(1,8,"Vm=");
- LCD1602_SendString(2,0,"Freq=");
- LCD1602_SendString(1,5,"mV");
- LCD1602_SendString(1,14,"mV");
- LCD1602_SendString(2,9,"Hz");
-
- TR1=1;//开启定时器T1
- TR0=1;//开启计数器
- fengming=0;
- while(1)
- {
-
- zyx=ADresult[0]*1.221*1.414;
- ADresult[0]=getdata(0);
- if( zyx<=100 || zyx>=200)
- {
- fengming=1; }
-
- else
- {
- fengming=0;
- }
- sprintf(Vrms,"%f",ADresult[0]*1.221);
- Vrms[3]='\0';
- LCD1602_SendString(1,2,Vrms);
-
- sprintf(Vmax,"%f",ADresult[0]*1.221*1.414);
- Vmax[3]='\0';
- LCD1602_SendString(1,11,Vmax);
- sprintf(Freq_temp,"%d",Freq);
- Freq_temp[4]='\0';
- LCD1602_SendString(2,5,Freq_temp);
- TR1=1;//开启定时器T1
- TR0=1;//开启计数器T0
- }
- }
- /*------定时器的初始化--------*/
- void Timer_Init()
- {
- TMOD|=0x15;//T0为计数器方式1,T1为定时器方式1
- TH1=(65536-50000)/256; //重装
- TL1=(65536-50000)%256;
- TH0=0;
- TL0=0;
- ET0=1;//开T0,T1中断
- ET1=1;
- EA=1; //全局中断
- }
- /*------定时器1中断服务程序-------*/
- void Time1_ser() interrupt 3
- {
- unsigned int dat1,dat2;
- TH1=(65536-50000)/256; //重装 50ms
- TL1=(65536-50000)%256;
- cnt_t1++;
- if(cnt_t1>=20)
- {
- TR1=0; //关定时
- TR0=0; //关计数
- cnt_t1=0;
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
采用TLC2543设计的弱交流信号测试仪.zip
(97.83 KB, 下载次数: 34)
|