版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、附:系统程序主函数文件#include lpc23xx.h/* lpc23xx/24xx peripheral registers*/#include type.h#include irq.h#include target.h#include timer.h#include rtc.h#include define.h#include coefficient.h#include keyled_define.h#include lcd_menu_resource.h#include math.h #include string.h#include stdio.h#define samplecyc
2、lenum 5#define pi 3.14159265#define sqrt_2 1.41421357#define pointsnumber 64extern _armabi float roundf(float /*x*/);double caculate_frequency(int piont,double frequency_0);void delay_for_ad(void);void adgpio_initial(void);enum system_state systemstate; /系统状态,分为测频阶段和参量计算两个状态int ad0_value512,ad1_valu
3、e512; /采样值word totalpointsnumber;dword adc_timerinterval;byte timescount_for_frequency; / 测频状态时记录采集周期数byte newvaluecreated_flag; /新菜了一个周期波形的标志byte frequnecystateenter_flag; /进入频率测试状态的标志byte elsestateenter_flag; /点入电参量计算的标志dword file_data_buf_byte_count=0;byte usbconnect_flag=0; /u盘连接标志,当u盘连接时,标志置1in
4、t upointsnumber*3+1; int ipointsnumber*3+1;float a_for_u11;float b_for_u11;/傅氏分解的实部、虚部float a_for_i11;float b_for_i11;/傅氏分解的实部、虚部struct voltage_coe u_coe_temp10,u_coe_value, i_coe_temp10,i_coe_value;/各谐波的有效值,记录十次取平均值float u_value=0,i_value=0,pf_value=0,power_value=0,q_value=0,s_value=0; /分别为电压、电流、有功
5、、无功和视在功率float umax_value=0,imax_value=0,powermax_value=0,qmax_value=0,smax_value=0; /分别为电压、电流、有功、无功和视在功率最大值float umin_value=0,imin_value=0,powermin_value=0,qmin_value=0,smin_value=0; /分别为电压、电流、有功、无功和视在功率最小值double frequency_value; /频率float u_temp10,i_temp10,power_temp10,q_temp10,s_temp10; /分别为电压、电流、有
6、功、无功和视在功率byte valuetempcount=0;int main(void) word i=0;byte j;byte keynumber; word temp; scs|=1; initkeyledrelay_pin(); lcd_init();/初始化clearscreen(); /清屏menu_pageid=pageid_mainpage;key_databuf=0x3f;enter_flag=1;esc_flag=0;keylcd_deal(nokey);backpara(pageid_vrefadj);/* rtc时钟初始化 */ systemtime.rtc_sec=
7、0; systemtime.rtc_min=0; systemtime.rtc_hour=0; systemtime.rtc_mday=1; systemtime.rtc_mon=6; systemtime.rtc_year=2008;backpara(pageid_timeset); rtcinit(); /* initialize timer0,for sample pf */ init_timer ( 0, fpclk); /起动定时器0,作为测功率因数用 enable_timer(0); adgpio_initial(); usb_init(); frequency_value=50;
8、 timescount_for_frequency=0; systemstate=undetect_state; /初始设置为非检测状态 / frequnecystateenter_flag=1; elsestateenter_flag=1; while(1) if(elsestateenter_flag=1) elsestateenter_flag=0; timer1_counter_for_points=0; adc_timerinterval= ( fpclk/(totalpointsnumber_for_else*frequency_value)-1); init_timer ( 1,
9、 adc_timerinterval ); /将在tmer.c文件的timer0handler (void) _irq 函数中处理adc 的采样 enable_timer(1); totalpointsnumber=totalpointsnumber_for_else; keynumber=keyscan(); /扫描按键 if(keynumber!=nokey) keylcd_deal(keynumber); if(newvaluecreated_flag=1) newvaluecreated_flag=0; timescount_for_frequency+; if(timescount_
10、for_frequency=3) timescount_for_frequency=0; timer1_counter_for_points=0; caculate_value(); keylcd_deal(nokey); /存储记录数据file_data_buffile_data_buf_byte_count+=systemtime.rtc_mon;file_data_buffile_data_buf_byte_count+=systemtime.rtc_mday;file_data_buffile_data_buf_byte_count+=systemtime.rtc_hour;file_
11、data_buffile_data_buf_byte_count+=systemtime.rtc_min;file_data_buffile_data_buf_byte_count+=(int)(u_value*10)8;file_data_buffile_data_buf_byte_count+=(int)(u_value*10)&0xff);file_data_buffile_data_buf_byte_count+=(int)(u_value*10)8;file_data_buffile_data_buf_byte_count+=(int)(i_value*100)&0xff);file
12、_data_buffile_data_buf_byte_count+=(int)(i_value*100)8;file_data_buffile_data_buf_byte_count+=(int)(power_value)&0xff);file_data_buffile_data_buf_byte_count+=(int)(power_value)8;file_data_buffile_data_buf_byte_count+=(int)(q_value)&0xff);file_data_buffile_data_buf_byte_count+=(int)(q_value)8;file_da
13、ta_buffile_data_buf_byte_count+=(int)(s_value)&0xff);file_data_buffile_data_buf_byte_count+=(int)(s_value)8; if(file_data_buf_byte_count=file_data_buf_len)file_data_buf_byte_count=0; if(usbconnect_flag =1 ) /检测到u盘插入,对u盘进行处理 usbconnect_flag=0; if(parachanged_flag=1) /如果正在修改参数,先将其参数撤销,在更改到usb通讯界面 keyl
14、cd_deal(key_esc); clearscreen(); disp_string(0,2,16,menu_usbconnect); usb_deal(); keylcd_deal(nokey); adc_timerinterval= ( fpclk/(totalpointsnumber_for_else*frequency_value)-1); init_timer ( 1, adc_timerinterval ); /将在tmer.c文件的timer0handler (void) _irq 函数中处理adc 的采样 enable_timer(1); / elsestateenter_
15、flag=1; else reset_timer(1); enable_timer(1); void caculate_value(void)word i,j;float temp;double ratio; u_tempvaluetempcount=0;i_tempvaluetempcount=0; for(j=0;j10;j+) a_for_uj=0; b_for_uj=0; a_for_ij=0; b_for_ij=0; power_tempvaluetempcount=0;q_tempvaluetempcount=0;s_tempvaluetempcount=0; for(i=0;i(
16、pointsnumber*3+1);i+) u_tempvaluetempcount=u_tempvaluetempcount+ad0_valuei*ad0_valuei*coefficienti;i_tempvaluetempcount=i_tempvaluetempcount+ad1_valuei*ad1_valuei*coefficienti; for(j=0;j10;j+) a_for_uj=a_for_uj+sqrt_2*ad0_valuei*cos(j*i*2*pi/pointsnumber)*coefficienti;b_for_uj=b_for_uj+sqrt_2*ad0_va
17、luei*sin(j*i*2*pi/pointsnumber)*coefficienti; a_for_ij=a_for_ij+sqrt_2*ad1_valuei*cos(j*i*2*pi/pointsnumber)*coefficienti;b_for_ij=b_for_ij+sqrt_2*ad1_valuei*sin(j*i*2*pi/pointsnumber)*coefficienti; power_tempvaluetempcount=power_tempvaluetempcount+ad0_valuei*ad1_valuei*coefficienti; if(i(samplecycl
18、enum-2) /采集完十次,进行求平均值 valuetempcount=0; u_value=0;i_value=0; /各数据在求平均值之前清0 power_value=0;q_value=0; s_value=0; u_coe_value.degree1=0;u_coe_value.degree2=0;u_coe_value.degree3=0;u_coe_value.degree4=0;u_coe_value.degree5=0;u_coe_value.degree6=0;u_coe_value.degree7=0;u_coe_value.degree8=0;u_coe_value.d
19、egree9=0;u_coe_value.degree10=0; i_coe_value.degree1=0;i_coe_value.degree2=0;i_coe_value.degree3=0;i_coe_value.degree4=0;i_coe_value.degree5=0;i_coe_value.degree6=0;i_coe_value.degree7=0;i_coe_value.degree8=0;i_coe_value.degree9=0;i_coe_value.degree10=0; for(i=0;isamplecyclenum;i+) u_value=u_value+u
20、_tempi; i_value=i_value+i_tempi; power_value=power_value+power_tempi; q_value=q_value+q_tempi; s_value=s_value+s_tempi; u_coe_value.degree1=u_coe_value.degree1+u_coe_tempi.degree1; u_coe_value.degree2=u_coe_value.degree2+u_coe_tempi.degree2; u_coe_value.degree3=u_coe_value.degree3+u_coe_tempi.degree
21、3; u_coe_value.degree4=u_coe_value.degree4+u_coe_tempi.degree4; u_coe_value.degree5=u_coe_value.degree5+u_coe_tempi.degree5; u_coe_value.degree6=u_coe_value.degree6+u_coe_tempi.degree6; u_coe_value.degree7=u_coe_value.degree7+u_coe_tempi.degree7; u_coe_value.degree8=u_coe_value.degree8+u_coe_tempi.d
22、egree8; u_coe_value.degree9=u_coe_value.degree9+u_coe_tempi.degree9; u_coe_value.degree10=u_coe_value.degree10+u_coe_tempi.degree10; i_coe_value.degree1=i_coe_value.degree1+i_coe_tempi.degree1; i_coe_value.degree2=i_coe_value.degree2+i_coe_tempi.degree2; i_coe_value.degree3=i_coe_value.degree3+i_coe
23、_tempi.degree3; i_coe_value.degree4=i_coe_value.degree4+i_coe_tempi.degree4; i_coe_value.degree5=i_coe_value.degree5+i_coe_tempi.degree5; i_coe_value.degree6=i_coe_value.degree6+i_coe_tempi.degree6; i_coe_value.degree7=i_coe_value.degree7+i_coe_tempi.degree7; i_coe_value.degree8=i_coe_value.degree8+
24、i_coe_tempi.degree8; i_coe_value.degree9=i_coe_value.degree9+i_coe_tempi.degree9; i_coe_value.degree10=i_coe_value.degree10+i_coe_tempi.degree10; u_value=(u_value/samplecyclenum)*100; /得到平局值并乘以pt ct变比 i_value=(i_value/samplecyclenum)*10; power_value=(power_value/samplecyclenum)*100*10; q_value=(q_va
25、lue/samplecyclenum)*100*10; s_value=u_value*i_value; pf_value=power_value/s_value; u_coe_value.degree1=(u_coe_value.degree1/samplecyclenum)*100; u_coe_value.degree2=(u_coe_value.degree2/samplecyclenum)*100; u_coe_value.degree3=(u_coe_value.degree3/samplecyclenum)*100; u_coe_value.degree4=(u_coe_valu
26、e.degree4/samplecyclenum)*100; u_coe_value.degree5=(u_coe_value.degree5/samplecyclenum)*100; u_coe_value.degree6=(u_coe_value.degree6/samplecyclenum)*100; u_coe_value.degree7=(u_coe_value.degree7/samplecyclenum)*100; u_coe_value.degree8=(u_coe_value.degree8/samplecyclenum)*100; u_coe_value.degree9=(
27、u_coe_value.degree9/samplecyclenum)*100; u_coe_value.degree10=(u_coe_value.degree10/samplecyclenum)*100; i_coe_value.degree1=(i_coe_value.degree1/samplecyclenum)*10; i_coe_value.degree2=(i_coe_value.degree2/samplecyclenum)*10; i_coe_value.degree3=(i_coe_value.degree3/samplecyclenum)*10; i_coe_value.
28、degree4=(i_coe_value.degree4/samplecyclenum)*10; i_coe_value.degree5=(i_coe_value.degree5/samplecyclenum)*10; i_coe_value.degree6=(i_coe_value.degree6/samplecyclenum)*10; i_coe_value.degree7=(i_coe_value.degree7/samplecyclenum)*10; i_coe_value.degree8=(i_coe_value.degree8/samplecyclenum)*10; i_coe_v
29、alue.degree9=(i_coe_value.degree9/samplecyclenum)*10; i_coe_value.degree10=(i_coe_value.degree10/samplecyclenum)*10; if(systemstate=detect_state) /检测状态下记录更新最大最小值 if(umax_value u_value) umin_value=u_value; if(imax_value i_value) imin_value=i_value; if(powermax_value power_value) powermin_value=power_
30、value; if(qmax_value q_value) qmin_value=q_value; if(smax_value s_value) smin_value=s_value; else valuetempcount+;double caculate_frequency(int piont,double frequency_0)word i; double angle1,angle2,angle2_difference,frequency,frequency_difference;double r;/r为修正系数double a1,b1,a2,b2; for(i=0;itotalpoi
31、ntsnumber_for_caculate;i+) a1=a1+2*pionti*cos(i*2*pi/totalpointsnumber_for_caculate); b1=b1+2*pionti*sin(i*2*pi/totalpointsnumber_for_caculate); a2=a2+2*pionti+totalpointsnumber_for_caculate*cos(i*2*pi/totalpointsnumber_for_caculate); b2=b2+2*pionti+totalpointsnumber_for_caculate*sin(i*2*pi/totalpointsnumber_for_caculate); a1=a1/totalpointsnumber_for_caculate; b
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 小学生消防演练课
- 超星食品安全组日常饮食
- 部编版八年级地理上册第三章第一节《自然资源的基本特征》课件
- 放射性皮炎的护理重点
- 1.1 物质结构研究的内容课件高二上学期化学苏教版(2019)选择性必修第二册
- 彩虹教案反思
- 虎和兔说课稿
- 函数的说课稿
- 产科科室护理一级质控
- 被针刺伤应急演练
- 电子政务概论-形考任务5(在线测试权重20%)-国开-参考资料
- 装配式建筑施工技术PPT课件
- (完整版)小学第三人称单数练习题及答案
- 急性胃肠炎病历模板4页
- 农民合作社成员帐户计算表
- 机械制图CAD_(教案)全部
- 串并联电路说课稿
- 上海市重点建设项目社会稳定风险评估咨询收费办法
- 画法几何习题集第六章答案大连理工大学版
- 毕业设计论文 外文文献翻译 中英文对照 21世纪的硅微电子学
- 中控考勤管理系统数据库结构
评论
0/150
提交评论