我的题目是:基于PID 算法的温度控制系统 89C51 单片机,通过键盘输入预设值,与DS18B20 测得的实际值做比较,然后驱动制冷或加热电路。用 keil C 语言来实现 PID 的控制。 最佳答案 //PID 算法温控C 语言 2008-08-17 18:58 #include #include #include #include struct PI{ unsigned int SetPoint; // 设定目标 Desired Value unsigned int Proportion; // 比例常数 Proportional Const unsigned int Integral; // 积分常数 Integral Const unsigned int LastError; // Error[-1] unsigned int PrevError; // Error[-2] unsigned int SumError; // Sums of Errors }; struct PI spid; // PI Control Structure unsigned int rout; // PIResponse (Output) unsigned int rin; // PI Feedback (Input) sbit data1=P1^0; sbit clk=P1^1; sbit plus=P2^0; sbit subs=P2^1; sbit stop=P2^2; sbit output=P3^4; sbit DQ=P3^3; unsigned char flag,flag_1=0; unsigned char high_time,low_time,count=0;//占空比调节参数 unsigned char set_temper=35; unsigned char temper; unsigned char i; unsigned char j=0; unsigned int s; /*********************************************************** 延时子程序,延时时间以 12M 晶振为准,延时时间为 30us× time ***********************************************************/ void delay(unsigned char time) { unsigned char m,n; for(n=0;n