pid温度控制c语⾔程序及仿真,温度控制PID算法的C语⾔程序
实例代码
//PID算法温控C语⾔
#include
#include
#include
#include
struct PID {
unsigned int SetPoint; // 设定⽬标 Desired Value
unsigned int Proportion; // ⽐例常数 Proportional Const
unsigned int Integral; // 积分常数 Integral Const
unsigned int Derivative; // 微分常数 Derivative Const
unsigned int LastError; // Error[-1]
unsigned int PrevError; // Error[-2]
unsigned int SumError; // Sums of Errors
};
struct PID spid; // PID Control Structure
unsigned int rout; // PID Respon (Output)
unsigned int rin; // PID Feedback (Input)
sbit data1=P1^0;
sbit clk=P1^1;
sbit plus=P2^0;
sbit subs=P2^1;
sbit stop=P2^2;
wipilot是什么sbit output=P3^4;
sbit DQ=P3^3;
unsigned char flag,flag_1=0;
unsigned char high_time,low_time,count=0;//占空⽐调节参数
unsigned char t_temper=35;
unsigned char temper;
unsigned char i;
unsigned char j=0;
unsigned int s;
gym是什么意思
/benighted
******************
延时⼦程序,延时时间以12M晶振为准,延时时间为30us×time ******************/
void delay(unsigned char time)
{
unsigned char m,n;
for(n=0;n
for(m=0;m<2;m++){}
}
/******************
写⼀位数据⼦程序
******************/
void write_bit(unsigned char bitval)
{
EA=0;
DQ=0; /*拉低DQ以开始⼀个写时序*/
if(bitval==1)
{
_nop_();
DQ=1; /*如要写1,则将总线置⾼*/
}
delay(5); /*延时90us供DA18B20采样*/
DQ=1; /*释放DQ总线*/
_nop_();
_nop_();
EA=1;
}
/******************
写⼀字节数据⼦程序
******************/
void write_byte(unsigned char val)
{
unsigned char i;
free prone video
unsigned char temp;
EA=0; /*关中断*/
TR0=0;
for(i=0;i<8;i++) /*写⼀字节数据,⼀次写⼀位*/
{
temp=val>>i; /*移位操作,将本次要写的位移到最低位*/ temp=temp&1;strlen
write_bit(temp); /*向总线写该位*/
}
delay(7); /*延时120us后*/
// TR0=1;
EA=1; /*开中断*/
}
/
******************
读⼀位数据⼦程序
******************/
unsigned char read_bit()
{
unsigned char i,value_bit;
EA=0;
DQ=0; /*拉低DQ,开始读时序*/
_nop_();
_nop_();
DQ=1; /*释放总线*/
for(i=0;i<2;i++){}
value_bit=DQ;
EA=1;
return(value_bit);
}
/******************
读⼀字节数据⼦程序
******************/
unsigned char read_byte()
{
unsigned char i,value=0;
出埃及记下载
EA=0;
for(i=0;i<8;i++)
{
if(read_bit()) /*读⼀字节数据,⼀个时序中读⼀次,并作移位处理*/ value|=0x01<
would like的用法
delay(4); /*延时80us以完成此次都时序,之后再读下⼀数据*/
}
EA=1;
return(value);
}
/******************
复位⼦程序
上海出国留学中介
******************/
unsigned char ret()
{
unsigned char prence;
EA=0;
DQ=0; /*拉低DQ总线开始复位*/
delay(30); /*保持低电平480us*/
DQ=1; /*释放总线*/
短裤的英文
delay(3);
prence=DQ; /*获取应答信号*/
delay(28); /*延时以完成整个时序*/
EA=1;
return(prence); /*返回应答信号,有芯⽚应答返回0,⽆芯⽚则返回1*/ }
/******************
获取温度⼦程序
******************/
void get_temper()
{
unsigned char i,j;
do
{
i=ret(); /*复位*/
}while(i!=0); /*1为⽆反馈信号*/
i=0xcc; /*发送设备定位命令*/
write_byte(i);
i=0x44; /*发送开始转换命令*/
write_byte(i);
delay(180); /*延时*/
do
{
i=ret(); /*复位*/
}while(i!=0);
i=0xcc; /*设备定位*/
write_byte(i);
i=0xbe; /*读出缓冲区内容*/
write_byte(i);
j=read_byte();
i=read_byte();
i=(i<<4)&0x7f;
s=(unsigned int)(j&0x0f);
s=(s*100)/16;
j=j>>4;
temper=i|j; /*获取的温度放在temper中*/
}
/
*========
Initialize PID Structure
=========*/
void PIDInit (struct PID *pp)
{
tup
memt ( pp,0,sizeof(struct PID));
}
/*========
PID计算部分
=========*/
unsigned int PIDCalc( struct PID *pp, unsigned int NextPoint )