一、设计简介:
本设计是基于51单片机PID算法温度控制系统设计,主要实现以下功能:
1. 单片机型号:STC89C52/51、AT89C52/51、AT89S52/51 都可通用
2.产品自带单片机上电复位电路、手动复位电路(复位按键)、晶振电路(给单片机提供时钟周期)。
3.采用LCD 1602液晶显示当前温度值(带单位),温度上限和温度下限;
4.采用DS18B20温度传感器测温,防水型传感器的
5.按键可以设置报警值,当温度超过设定的上限或低于下限时,相应的指示灯亮,同时相应的继电器吸合,继电器可以驱动负载(风扇、制冷片、加热管等);
6.三个按键:设置按键、加键和减键。可设置上下限温度控制范围;
7.温度测量范围0到99.9摄氏度,精度为0.1摄氏度
主要硬件组成:
51单片机+最小系统+LCD1602液晶+按键+DS18B20温度传感器+加热棒+LED灯+继电器
二、原理图
三、PCB图
四、Proteus仿真
五、程序源码
部分代码:
pp->PrevError = pp->LastError;
pp->LastError = Error;
return (pp->Proportion * Error//比例
+ pp->Integral * pp->SumError //积分项
+ pp->Derivative * dError); // 微分项
}
/***********************************************************
温度比较处理子程序
***********************************************************/
void compare_temper(void)
{
unsigned char i;
if(set_temper>temper) //设置温度大于当前温度
{
ledred=0;
ledgreen=1;
if(set_temper-temper>1) //温度相差1度以上
{
high_time=100;
low_time=0;
}
else //设置温度不大于当前温度
{
for(i=0;i<10;i++)
{
get_temper();
rin = s; // Read Input
rout = PIDCalc ( &spid,rin ); // Perform PID Interation
}
if (high_time<=100) high_time=(unsigned char)(rout/800);
else high_time=100;
low_time= (100-high_time);
}
}
else if(set_temper<=temper) //设置温度不大于当前温度
{
ledred=1;
ledgreen=0;
if(temper-set_temper>0) //温度相差0度以上
{
high_time=0;
low_time=100;
}
else
{
for(i=0;i<10;i++)
{
get_temper();
rin = s; // Read Input
rout = PIDCalc ( &spid,rin ); // Perform PID Interation
}
if (high_time<100) high_time=(unsigned char)(rout/10000);
else high_time=0;
low_time= (100-high_time);
}
}
}
/*****************************************************
T0中断服务子程序,用于控制电平的翻转 ,40us*100=4ms周期
******************************************************/
void serve_T0() interrupt 1 using 1
{
if(++count<=(high_time)) output=0;
else if(count<=100)
{
output=1;
}
else count=0;
TH0=0x2f;
TL0=0x40;
}
/***********主函数**********/
void main(void)
{
unsigned char i;
init();//LCD初始化
TMOD=0x01;
TH0=0x2f;
TL0=0x40;
EA=1;
ET0=1;
TR0=1;
high_time=50;
low_time=50;
PIDInit ( &spid ); // Initialize Structure
spid.Proportion= 10; // Set PID Coefficients
spid.Integral = 8;
spid.Derivative =6;
spid.SetPoint =100; // Set PID Setpoint
set[0]=set_temper/10;
set[1]=set_temper%10;
wr_com(0x80+0x40+9); //显示设置温度
wr_data(table[set[0]]);
delay(1);
wr_com(0x80+0x40+10);
wr_data(table[set[1]]);
delay(1);
wr_com(0x80+0x40+14); //显示温度符号
wr_data(0xdf);
delay(1);
while(1)
{
keyscan(); //按键扫描
for(i=0;i<10;i++) //循环10次
{
dis_temp(get_temper()); //显示温度值
if((key0==0)||(key1==0)) break; //如果有按键退出显示循环
}
if((key0!=0)&&(key1!=0)) compare_temper(); //比较温度
}
}
六、资源获取
本项目包含的所有文件都可以点击下面的名片,发送 “ 57、基于51单片机PID算法温度控制系统设计 ” 获取!
项目纯手打,不是免费的哦~
希望可以帮到你哈!