


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第第页51单片机-温度PID算法(C程序)#include"reg51.h"#include"intrins.h"#include"math.h"#include"string.h"structPID{unsignedintSetPoint;//设定目标DesiredValueunsignedintProportion;//比例常数ProportionalConstunsignedintIntegral;//积分常数IntegralConstunsignedintDerivative;//微分常数DerivativeConstunsignedintLastError;//Error[-1]unsignedintPrevError;//Error[-2]unsignedintSumError;//SumsofErrors};structPIDspid;//PIDControlStructureunsignedintrout;//PIDResponse(Output)unsignedintrin;//PIDFeedback(Input)sbitdata1=P1^0;sbitclk=P1^1;sbitplus=P2^0;sbitsubs=P2^1;sbitstop=P2^2;sbitoutput=P3^4;sbitDQ=P3^3;unsignedcharflag,flag_1=0;unsignedcharhigh_time,low_time,count=0;//占空比调节参数unsignedcharset_temper=25;unsignedchartemper;unsignedchari;unsignedcharj=0;unsignedints;voiddelay(unsignedchartime){unsignedcharm,n;for(n=0;nfor(m=0;m>i;temp=tempwrite_bit(temp);}delay(7);//TR0=1;EA=1;}unsignedcharread_bit(){unsignedchari,value_bit;EA=0;DQ=0;_nop_();_nop_();DQ=1;for(i=0;i>4;temper=i|j;}voidPIDInit(structPID*pp){memset(pp,0,sizeof(structPID));//全部初始化为0}unsignedintPIDCalc(structPID*pp,unsignedintNextPoint){unsignedintdError,Error;Error=pp->SetPoint-NextPoint;//偏差pp->SumError+=Error;//积分dError=pp->LastError-pp->PrevError;//当前微分pp->PrevError=pp->LastError;pp->LastError=Error;return(pp->Proportion*Error//比例项+pp->Integral*pp->SumError//积分项+pp->Derivative*dError);//微分项}voidcompare_temper(){unsignedchari;if(set_temper>temper)//是否设置的温度大于实际温度{if(set_temper-temper>1)//设置的温度比实际的温度是否是大于1度{high_time=100;//如果是,则全速加热low_time=0;}else//如果是在1度范围内,则运行PID计算{for(i=0;i0){high_time=0;low_time=100;}else{for(i=0;i>1;if(m==1)data1=1;elsedata1=0;_nop_();clk=1;_nop_();}}}voiddisplay(){unsignedcharcodenumber[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6};unsignedchardisp_num[6];unsignedintk,k1;k=high_time;k=k00;k1=k/100;if(k1==0)disp_num[0]=0;elsedisp_num[0]=0x60;k=k0;disp_num[1]=number[k/10];disp_num[2]=number[k];k=temper;k=k0;disp_num[3]=number[k/10];disp_num[4]=number[k]+1;disp_num[5]=number[s/10];disp_1(disp_num);}voidmain(){unsignedcharz;unsignedchara,b,flag_2=1,count1=0;unsignedcharphil[]={2,0xce,0x6e,0x60,0x1c,2};TMOD=0x21;TH0=0x2f;TL0=0x40;SCON=0x50;PCON=0x00;TH1=0xfd;TL1=0xfd;PS=1;EA=1;EX1=0;ET0=1;ES=1;TR0=1;TR1=1;high_time=50;low_time=50;PIDInit(//InitializeStructurespid.Proportion=10;//SetPIDCoefficients比例常数ProportionalConstspid.Integral=8;//积分常数IntegralConstspid.Derivative=6;//微分常数DerivativeConstspid.SetPoint=100;//SetPIDSetpoint设定目标DesiredValuewhile(1){if(plus==0){EA=0;for(a=0;a5)temper=a;elsetemper=b;a=temper;flag_2=0;if(++count1>30){display();count1=0;}compare_temper();}TR0=
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 球队更换合同协议书模板
- 重庆中兴花园项目销售策划和销售代理投标书58p
- 红色简约风感动中国十大人物介绍
- 黑龙江省哈尔滨市道外区2024-2025学年高一下学期期中考试数学试卷(解析)
- 2025年大数据展现平台项目合作计划书
- 2025年微波暗室设备项目建议书
- 心衰患者中医护理
- 抖音短视频内容创作者激励方案合同
- 电商平台仓储动线智能化物流方案设计与实施合同
- 微信视频号美妆教程制作与推广服务合同
- 术前月经来潮的应急预案
- 特种设备使用和运营的安全管理制度(2篇)
- 《中国的民主政治》课件
- 部队安全保密教育课件
- 2024年10月自考00152组织行为学试题及答案
- 承包荒地治沙合同范例
- 心血管内科降低患者桡动脉止血器压迫不适发生率品管圈PDCA成果汇报书
- 第11课 近代职业教育的兴起和发展
- 软著设计说明书
- 第二单元《践行职业道德》测试卷-高二思想政治课《职业道德与法治》附答案
- 三年合同到期不续签劳动仲裁申请书
评论
0/150
提交评论