电子设计大赛倒立摆PID控制算法源程序.pdfVIP

  • 0
  • 0
  • 约1.87万字
  • 约 20页
  • 2026-02-12 发布于北京
  • 举报

电子设计大赛倒立摆PID控制算法源程序.pdf

#includereg51.h#includeintrins.h#includemath.h#

includestring.hstructPID{unsignedintSetPoint;//设定

目标DesiredValueunsignedintProportion;//比例常数

ProportionalConstunsignedintIntegral;//积分常数

IntegralConstunsignedintDerivative;//微分常数

DerivativeConstunsignedintLastError;//Error[‑1]

unsignedintPrevError;//Error[‑2]unsignedint

SumError;//错误总和};structPIDspid;//PID控制结构

unsignedintrout;//PID响应(输出)unsignedintrin;//

PID反馈(输入)sbitdata1P1^0;sbitclkP1^1;sbitplus

P2^0;sbitsubsP2^1;sbitstopP2^2;sbitoutputP3^4;sbit

DQP3^3;unsignedcharflag,flag_1=0;unsignedchar

high_time,low_time,count=0;//占空比调节参数unsigned

charset_temper=35;unsignedchartemper;unsigned

chari;unsignedcharj=0;unsignedints;/

*********************************************************

**

延时子程序,延时时间以12M晶振为准,延时时间为30us×time

**********************************************************

*/

voiddelay(unsignedchartime){unsignedcharm,n;

for(n=0;ntime;n++)for(m=0;m2;m++){}}/

*

*

*

*********************************************************/

***编写一个数据子程序

***********************************************************/

voidwrite_bit(unsignedcharbitval){

#includereg51.h

#includeintrins.h

#includemath.h

#includestring.h

structPID{

unsignedintSetPoint;//设定目标DesiredValue

unsignedintProportion;//比例常数ProportionalConst

unsignedintIntegral;//积分常数IntegralConst

unsignedintDerivative;//微分常数DerivativeConst

unsignedintLastError;//Error[-1]

unsignedintPrevError;//Error[-2]

unsignedintSumError;//SumsofErrors

};

structPIDspid;//PIDControlStructure

unsignedintrout;//PIDResponse(Output)

unsignedintrin;//PIDFeedback(Input)

sbitdata1=P1^0;

sbitclk=P1^1;

sbitplus=P2^0;

sbitsubs=P2^1;

文档评论(0)

1亿VIP精品文档

相关文档