基于51单片机的恒温控制系统,温度传感器是DS18B20,LCD1602显示,DAC0832电压输出,电机驱动控制
通过2个电机的通断来控制温度保持在20-30度之间。
当温度小于20度时,电机A工作、B停止,温度大于30度时,电机B工作、A停止,温度在20-30时,电机A、B均停止工作
液晶显示屏显示当前温度:
附件内容包括仿真电路+仿真代码.c文件。
完整版 电路图和程序代码 下载地址
https://pan.baidu.com/s/1RFQoyvW8KndWm3seNoYStA?pwd=8888
部分代码展示
#include <reg52.h>
#include "LCD1602.H"
#include "DS18B20.H"
#include "DAC0832.H"
#include "MOTOR.H"
#define ON 0 //指示灯亮
#define OFF 1 //指示灯灭
sbit LED_B = P3^0; //蓝色指示灯
sbit LED_G = P2^4; //绿色指示灯
sbit LED_R = P2^3; //红色指示灯
long wendu = 0; //温度值
unsigned int t0,t1;
unsigned int i;
void delay(unsigned int z); //延时函数
void System_Init(void);
void main(void)
{
System_Init();
LCD1602_DisplayString(2,1,"The Temp=");
delay(50);
while(1)
{
wendu=DS18B20_GetTemperature(); //读取当前环境温度值
LCD1602_DisplayChar(2,11,wendu/10+0x30);
LCD1602_DisplayChar(2,12,wendu%10+0x30);
if(wendu > 30)
{
DAC0832_Output(0x48);
MOTOR1(Stop);
MOTOR2(ZZ);
}
else
{
if(wendu < 20)
{
DAC0832_Output(0xff);
MOTOR1(ZZ);
MOTOR2(Stop);
}
else
{
DAC0832_Output(0x48);
MOTOR1(Stop);
MOTOR2(Stop);
}
}
if(wendu > 30)
{
LED_G = OFF;
for(i=0;i<5;i++)
{
LED_R = ~LED_R;
delay(100);
}
LED_R = OFF;
}
else
{
if(wendu<20)
{
LED_G = OFF;
for(i=0;i<5;i++)
{
LED_B = ~LED_B;
delay(100);
}
LED_B = OFF;
}
else{LED_R = OFF;LED_G = ON;}
}
}
}
void System_Init(void) //系统初始化
{
unsigned int i;
LCD1602_Init(1,0,0);
DS18B20_Reset();
LCD1602_DisplayString(1,1,"Welcome to xyxy");
LCD1602_DisplayString(2,1,"System Init ...");
delay(800);
for(i=0;i<3;i++)
{
LED_R = ON;
delay(100);
LED_R = OFF;
delay(100);
}
delay(400);
for(i=0;i<3;i++)
{
LED_G = ON;
delay(100);
LED_G = OFF;
delay(100);
}
delay(400);
for(i=0;i<3;i++)
{
LED_B = ON;
delay(100);
LED_B = OFF;
delay(100);
}
delay(400);
for(i=0;i<3;i++)
{
LED_R = ON;
LED_G = ON;
LED_B = ON;
delay(100);
LED_R = OFF;
LED_G = OFF;
LED_B = OFF;
delay(100);
}
LED_R = OFF;
LED_G = OFF;
LED_B = OFF;
delay(500);
LCD1602_DisplayString(2,1," ");
}