微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 交流信号测量仪

交流信号测量仪

时间:11-29 来源:互联网 点击:
本作品为匆忙制作,考试逼近,为了应付竞赛,用了几天时间,整出这个一个东西交差,程序算法有待提高

如有朋友做AD方面的东西,相互交流


完整的源码下载:http://www.51hei.com/f/jiaoliu.rar
以下是部分代码:

#include            #include    #include      #define nop() _nop_()#define N0 65336#define uint unsigned int#define uchar unsigned char  #define ulong unsigned longuchar code xian[]={"Welcome"};uchar code xian1[]={"Designed by WJJ"};uchar tab[7];uchar tab2[7];uchar tab3[5];uchar tab4[8]={"        "};sbit EOC=P2^6;sbit OE=P2^5;sbit START=P2^7;sbit lcdrs=P3^5;sbit lcdrw=P3^6;sbit lcden=P3^7;uint vmax=0; //  电压测量运算变量uint count1;  //电压测量控制变量uint count;   //频率测量控制变量ulong mt=0;    //  频率测量运算变量ulong vs=0;ulong t;bit flag=0;    //是否显示标志位  对频率void  DelayNS(uint dly)  { uint i;for(; dly>0; dly--)for(i=0; i<100; i++);}bit lcd_busy(){bit result;lcdrw = 1;lcdrs = 0;lcden = 1;nop();nop();nop();nop();result = (bit)(P1&0x80);lcden = 0;return(result);}void write_com(uchar com){while(lcd_busy());      //LCD忙等待lcdrs = 0;lcdrw = 0;P1 = com;DelayNS(5);lcden = 1;DelayNS(5);lcden = 0;}void write_data(uchar date){while(lcd_busy());      //LCD忙等待lcdrs = 1;lcdrw = 0;P1 = date;DelayNS(5);lcden = 1;DelayNS(5);lcden = 0;}void lcd_init(){lcden = 0;write_com(0x38);DelayNS(5);write_com(0x0c);DelayNS(5);write_com(0x04);DelayNS(5);write_com(0x01);}void timer_init()  {EA = 1;EX0=1;IT0=1;TMOD = 0x11;TH0=0;TL0=0;}				   void main(){uint i;ulong v=0;ulong av;uint hz;bit flag=0;ulong t1=0,t2=0;lcd_init();write_com(0x84);for(i=0;i<7;i++){write_data(xian[i]);DelayNS(2);  }write_com(0x80+0x40);for(i=0;i<15;i++){write_data(xian1[i]);DelayNS(2);  }DelayNS(1000); DelayNS(1000);  timer_init();write_com(0x01);while(1){if(count==40){count=0;EX0=0;ET0=0;TR0=0;t1=100000000/mt;tab[0]=t1/1000+0x30;tab[1]=t1%1000/100+0x30;tab[2]=0x2e;tab[3]=t1%1000%100/10+0x30;tab[4]=t1%1000%100%10+0x30;        //周期显示十位tab[5]=0x48;tab[6]=0x7a;hz=t1/100;t=1000000/(50*hz)+100;TH1=65536-t/256;TL1=65535-t%256;t2=mt/10;tab2[0]=t2/1000+0x30;tab2[1]=t2%1000/100+0x30;tab2[2]=0x2e;tab2[3]=t2%1000%100/10+0x30;tab2[4]=t2%1000%100%10+0x30;tab2[5]=0x6d;tab2[6]=0x73;    ET1=1;TR1=1;}if(count1==80)     {ET1 = 0;TR1 = 0;count1=0;v=(vmax+1)*196/100;tab3[4]=0x56;tab3[3]=(v%100)%10+0x30;tab3[2]=(v%100)/10+0x30; tab3[1]=0x2e;tab3[0]=v/100+0x30;vs=vs*0.0195*0.0195;av=(sqrt(vs/50))*100;tab4[4]=0x56;tab4[3]=(av%100)%10+0x30;tab4[2]=(av%100)/10+0x30; tab4[1]=0x2e;tab4[0]=av/100+0x30;if((v/sqrt(2)-av)>25){tab4[7]=0x32;}else{tab4[7]=0x31;}av=0;flag=1;}if(flag==1){flag=0;write_com(0x80);for(i=0;i<7;i++){write_data(tab[i]);DelayNS(2); }write_com(0x80+0x09);for(i=0;i<7;i++){write_data(tab2[i]);DelayNS(2); }write_com(0x80+0x40);for(i=0;i<5;i++){write_data(tab3[i]);DelayNS(20);}write_com(0x80+0x47);for(i=0;i<8;i++){write_data(tab4[i]);DelayNS(20);}//write_com(0x80+0x54);//write_data(tab4[7]);//DelayNS(20);vmax=0;EX0=1;}}}void ex0() interrupt 0{ count++;if(count%2==0){ET0=1;TR0=1;TH0=0;TL0=0;}else{ET0=0;TR0=0;mt=TH0*256+TL0; }}void timer0() interrupt 1 //测频率时计时{  TH0=0;TL0=0;}void  timer1() interrupt 3 //控制AD转换{uint data1;count1++;OE = 0;START = 0;_nop_();START = 1;_nop_(); START = 0; while(EOC==0); OE = 1; _nop_();data1 = P0;_nop_();OE = 0;if(data1>vmax){vmax=data1;}if(count1<=52){vs=vs+data1*data1;}TH1=65536-t/256;TL1=65535-t%256;}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top