一、设计要求
本次设计为一个基于单片机的饮水机的温度控制系统,该系统可以实时检测饮水机水箱的水温,并且可以通过数码管显示饮水机水箱水温度数,可以通过键盘或开关选择制冷或加热,可以人为设置水的温度的上下限,如加热,当温度在设定的范围内时正常工作,当低于水温下限时控制加热器加热;如制冷,当温度高于水温上限时控制压缩机制冷,温度检测范围0~95℃,精度±1℃,当温度超过设定值时具有示警功能。
二、设计资料
三、部分程序代码
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char // 以后unsigned char就可以用uchar代替
#define uint unsigned int // 以后unsigned int 就可以用uint 代替
sbit LED = P1^0; //
sbit Lamp = P1^4; //
sbit Key1 = P1^1; // 按键1,模式切换按键
sbit Key2 = P1^2; //
sbit Key3 = P1^3; // 按键3,亮按键
sbit ADC_CS = P2^3; // ADC0832的CS引脚
sbit ADC_CLK = P2^0; // ADC0832的CLK引脚
sbit ADC_DAT = P2^1; // ADC0832的DI/DO引脚
sbit Module = P2^2; // 人体红外检测模块
uchar gCount=0; // 全局计数变量
uchar gIndex; // 度变量,
uint gTime=0; // 计时变量,用于计时多久没检测到有人
/*********************************************************/
// 毫秒级的延时函数,time是要延时的毫秒数
/*********************************************************/
void DelayMs(uint time)
{
uint i,j;
for(i=0;i<time;i++)
for(j=0;j<112;j++);
}
void WavePlus()
{
_nop_();
ADC_CLK = 1;
_nop_();
ADC_CLK = 0;
}
/*********************************************************/
// 获取指定通道的A/D转换结果
/*********************************************************/
uchar Get_ADC0832()
{
uchar i;
uchar dat1=0;
uchar dat2=0;
ADC_CLK = 0; // 电平初始化
ADC_DAT = 1;
_nop_();
ADC_CS = 0;
WavePlus(); // 起始信号
ADC_DAT = 1;
WavePlus(); // 通道选择的第一位
ADC_DAT = 0;
WavePlus(); // 通道选择的第二位
ADC_DAT = 1;
for(i=0;i<8;i++) // 第一次读取
{
dat1<<=1;
WavePlus();
if(ADC_DAT)
dat1=dat1|0x01;
else
dat1=dat1|0x00;
}
for(i=0;i<8;i++) // 第二次读取
{
dat2>>= 1;
if(ADC_DAT)
dat2=dat2|0x80;
else
dat2=dat2|0x00;
WavePlus();
}
四、protues仿真
五、AD原理图
六、PCB
六、全套设计资料扫一扫关注公众号立即获取