最近设计了一个项目基于单片机的洗碗机 || 全自动洗碗机 || ,与大家分享一下:
一、基本介绍
项目名:洗碗机
项目编号:mcuclub-dz-295
单片机类型:STC89C52
具体功能:
1、清洗过程:加水——加洗涤剂(3s)——加热(3s)——清洗——排水——加水——清洗——排水——加热烘干(3s)——消毒(3s)(6个继电器模拟)
2、通过DS18B20检测温度,若温度高于设定最大阈值,进行声光报警,并结束清洗
3、通过按键设置温度最大值、启停或直接结束清洗
4、通过显示屏显示测量值、当前清洗状态。
5、通过蓝牙模块将测量数据发送到手机端,并可以控制启停或直接结束清洗
6、通过按键可选择精洗还是标准洗,精洗模式下,清洗时间为20s,精洗模式下,清洗时间为10s
7、通过液位检测模块检测液位,加水时,超过设置最大值才停止,排水时,液位为0时停止排水
二、51实物图
单片机型号:STC89C52
板子为绿色PCB板,两层板,厚度1.2,上下覆铜接地。元器件基本上为插针式,个别降压芯片会使用贴片式。
供电接口:TYPE-C
三、仿真图
四、原理图
软件版本:AD2013
电路连线方式:网络标号连线方式
注意:原理图只是画出了模块的引脚图,而并不是模块的内部结构原理图
五、PCB图
由原理图导出,封装很大一部分都是作者自己绘制,不提供封装库,只提供连接好的源文件。中间有一个项目编号,隐藏在单片机底座下,插入单片机后不会看到。
两层板,上下覆铜接地。
六、系统框图
本设计以单片机为核心控制器,加上其他模块一起组成此次设计的整个系统,其中包括中控部分、输入部分和输出部分。中控部分采用了单片机控制器,其主要作用是获取输入部分的数据,经过内部处理,逻辑判断,最终控制输出部分。输入由四部分组成,第一部分是水温检测模块,通过该模块检测当前洗碗机中的水温;第二部分是水位监测模块,通过该模块监测当前洗碗机中水的水位;第三部分是按键模块,通过该模块可以温度最大值、启停或直接结束清洗等;第四部分是供电模块,通过该模块可给整个系统进行供电。输出由三部分组成,第一部分是显示模块,通过该模块可以显示监测的数据以及设置的阈值;第二部分是继电器模块,通过六个继电器分别控制加水、加洗涤剂、加热、排水、消毒、清洗;第三部分是声光报警模块,若温度高于设定最大阈值,进行声光报警。除此之外,蓝牙模块既作为输入又作为输出,蓝牙模块和手机进行连接,通过蓝牙模块将测量数据发送到手机端,并可以控制启停或直接结束清洗。具体系统框图如图3.1所示。
七、软件设计流程
八、部分程序展示
软件版本:keil5
逻辑程序和驱动程序分开,分布于main.c和其他.c文件
*******处理函数
*****/
void Manage_function(void)
{
if(flag_display == 0)
{
if(flag_on == 1)
{
if(flag_begin == 1) //洗碗机开始
{
switch(flag_step)
{
case 0: //步骤0:第一次加水
if(distance_value < distance_max)
{
RELAY_JS = 0;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
else
{
flag_step = 1;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
break;case 1: //步骤1:加洗涤剂
flag_timer_begin = 1;
if(time_all > (time_rinse*2 + time_jiare*2 + time_disinfect))
{
if(flag_timer_begin == 1) //倒计时开始,每1分钟总时间-1
{
if(flag_1m == 1)
{
flag_1m = 0;if(time_all != 0)
time_all--;
}
}
RELAY_JS = 1;
RELAY_JXD = 0;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
else
{
time_all = time_rinse*2 + time_jiare*2 + time_disinfect + time_xidi; //总时间=清洗时间*2+加热时间*2+消毒时间+洗涤剂时间
flag_timer_begin = 0;
flag_1m = 0;
flag_step = 2;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
break;case 2: //步骤2:第一次加热
flag_timer_begin = 1;
if(time_all > (time_rinse*2 + time_jiare + time_disinfect + time_xidi))
{
if(flag_timer_begin == 1) //倒计时开始,每1分钟总时间-1
{
if(flag_1m == 1)
{
flag_1m = 0;if(time_all != 0)
time_all--;
}
}
if(temp_value < temp_max*10) //温度小于最大值,加热
{
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 0;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
else //温度超过最大值,结束清洗
{
while(BEEP_num<6)
{
BEEP = ~BEEP;
LED = ~LED;
Delay_function(500); //延时500ms
BEEP_num++;
}
BEEP_num = 0;
flag_on = 0;
}
}
else //加热时间结束
{
flag_step = 3;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
time_all = time_rinse*2 + time_jiare*2 + time_disinfect + time_xidi; //总时间=清洗时间*2+加热时间*2+消毒时间+洗涤剂时间
}
break;case 3: //步骤3:第一次清洗
flag_timer_begin = 1;
if(time_all > (time_rinse*1 + time_jiare*2 + time_disinfect + time_xidi))
{
if(flag_timer_begin == 1) //倒计时开始,每1分钟总时间-1
{
if(flag_1m == 1)
{
flag_1m = 0;if(time_all != 0)
time_all--;
}
}
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 0;
RELAY_PS = 1;
RELAY_XD = 1;
}
else
{
time_all = time_rinse*2 + time_jiare*2 + time_disinfect + time_xidi; //总时间=清洗时间*2+加热时间*2+消毒时间+洗涤剂时间
flag_timer_begin = 0;
flag_1m = 0;
flag_step = 4;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
break;case 4: //步骤4:第一次排水
if(distance_value > 0)
{
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 0;
RELAY_XD = 1;
}
else if(distance_value == 0)
{
flag_step = 5;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
break;
case 5: //步骤3:第二次加水
if(distance_value < distance_max)
{
RELAY_JS = 0;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
else
{
flag_step = 6;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
break;case 6: //步骤6:第二次清洗
flag_timer_begin = 1;
if(time_all > (time_rinse*1 + time_jiare*2 + time_disinfect + time_xidi))
{
if(flag_timer_begin == 1) //倒计时开始,每1分钟总时间-1
{
if(flag_1m == 1)
{
flag_1m = 0;if(time_all != 0)
time_all--;
}
}
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 0;
RELAY_PS = 1;
RELAY_XD = 1;
}
else
{
time_all = time_rinse*2 + time_jiare*2 + time_disinfect + time_xidi; //总时间=清洗时间*2+加热时间*2+消毒时间+洗涤剂时间
flag_timer_begin = 0;
flag_1m = 0;
flag_step = 7;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
break;case 7: //步骤7:第二次排水
if(distance_value > 0)
{
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 0;
RELAY_XD = 1;
}
else
{
flag_step = 8;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
break;case 8: //步骤8:第二次加热
flag_timer_begin = 1;
if(time_all > (time_rinse*2 + time_jiare + time_disinfect + time_xidi))
{
if(flag_timer_begin == 1) //倒计时开始,每1分钟总时间-1
{
if(flag_1m == 1)
{
flag_1m = 0;if(time_all != 0)
time_all--;
}
}
if(temp_value < temp_max*10)
{
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 0;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
else
{
while(BEEP_num<6)
{
BEEP = ~BEEP;
LED = ~LED;
Delay_function(500); //延时500ms
BEEP_num++;
}
BEEP_num = 0;
flag_on = 0;
}
}
else
{
flag_step = 9;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
time_all = time_rinse*2 + time_jiare*2 + time_disinfect + time_xidi; //总时间=清洗时间*2+加热时间*2+消毒时间+洗涤剂时间
}
break;case 9: //步骤9:消毒
flag_timer_begin = 1;
if(time_all > time_rinse*2 + time_jiare*2 + time_xidi)
{
if(flag_timer_begin == 1) //倒计时开始,每1分钟总时间-1
{
if(flag_1m == 1)
{
flag_1m = 0;if(time_all != 0)
time_all--;
}
}
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 0;
}
else
{
time_all = time_rinse*2 + time_jiare*2 + time_disinfect + time_xidi; //总时间=清洗时间*2+加热时间*2+消毒时间+洗涤剂时间
flag_timer_begin = 0;
flag_1m = 0;
flag_step = 10;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
break;case 10: //步骤10:结束清洗,蜂鸣器响三下,等待
while(BEEP_num<6)
{
BEEP = ~BEEP;
Delay_function(500); //延时50ms
BEEP_num++;
}
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
time_all =time_rinse*2 + time_jiare*2 + time_disinfect + time_xidi; //总时间=清洗时间*2+加热时间*2+消毒时间+洗涤剂时间
flag_begin = 0;
BEEP_num=0;
break;
default:
break;
}
}
else
{
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
flag_timer_begin = 0;
}
}
else //关电源
{
flag_step = 10;
flag_begin = 0;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
flag_timer_begin = 0;
time_all = time_rinse*2 + time_jiare*2 + time_disinfect + time_xidi; //总时间=加热时间*2+清洗时间*2+消毒时间+洗涤剂时间
}
}
else //切换到设置模式,暂停工作
{
flag_begin = 0;
LED = 1;
BEEP = 1;
RELAY_JS = 1;
RELAY_JXD = 1;
RELAY_JR = 1;
RELAY_QX = 1;
RELAY_PS = 1;
RELAY_XD = 1;
}
}