一.系统概述
智能鱼缸系统采用STM32单片机作为主控单元,通过温度传感器和水位传感器来监测鱼缸中的温度和水位数据,并在显示屏上展示这些信息。系统提供两种控制模式:手动和自动。默认情况下,系统处于手动控制模式,用户可以通过手动操作来控制抽水和散热等功能。而在自动模式下,系统会根据水位和温度的变化进行智能调节。
二.仿真概述
- 在手动模式下,按下抽水按钮将启动抽水功能,按下散热按钮则会启动风扇,按下停止按钮则会停止抽水和散热功能。
- 通过按下手动/自动切换按钮,系统会转换为自动模式。
- 在自动模式下,当水位超过设定阈值时,系统会自动启动抽水功能。
- 自动模式下,当温度低于设定的下限时,系统会启动加热功能。
- 同样在自动模式下,当温度超出设定阈值时,系统会启用散热功能。
- 在自动模式下,按下设置按钮即可调整温度和水位的设定阈值。
三.程序设计
#include <stm32f10x.h>
#include <Lcd1602.h>
#include <Led.h>
#include <Ds18b20.h>
#include <Beep.h>
#include <key.h>
#include "PCF8591.h"
int main(void)
{
u8 temp,water,key,m=0,as=0,Tmax=25,Tmin=20,Wmin=45,Wmax=50;
Key_Init();//pb12-15
Lcd1602_Init();//pa0-7 pb0-3
Led1_Init();//PC1-4
Beep_Init();//Pc0
Ds18b20_Init();//PA12
PCF8591_Init();//pb10 11
Lcd1602_Write_String(0x80,2,(u8*)"T:");
Lcd1602_Write_String(0x88+1,1,(u8*)"-");
Lcd1602_Write_String(0x84,2,(u8*)"c");
Lcd1602_Write_String(0xc0,2,(u8*)"W:");
Lcd1602_Write_String(0xc8+1,1,(u8*)"-:");
Lcd1602_Write_String(0xc4,1,(u8*)"%");
while(1)
{
key =Key_detect();
// Lcd1602_Write_Num8(0x8c,m);
temp =Ds18b20_Temp() ;
Lcd1602_Write_Num8(0x82,temp);
Lcd1602_Write_Num8(0x86+1,Tmin);
Lcd1602_Write_Num8(0x89+1,Tmax);
water =PCF8591_ADC_Input(0x90,1);
Lcd1602_Write_Num8(0xc2,water);
Lcd1602_Write_Num8(0xc6+1,Wmin);
Lcd1602_Write_Num8(0xc9+1,Wmax);
if(Key2==0) //设置
{ m++;
if(m==5) m=0;
}
if(Key3==0&& m!=0) { m=0; }//确认
switch(m)
{
case 0:
Lcd1602_Write_String(0xc6,1,(u8*)" ");
Lcd1602_Write_String(0x8c,1,(u8*)" ");
Lcd1602_Write_String(0xcc,1,(u8*)" ");
Lcd1602_Write_String(0x86,1,(u8*)" ");break;
case 1:
Lcd1602_Write_String(0xc6,1,(u8*)" ");
Lcd1602_Write_String(0x8c,1,(u8*)" ");
Lcd1602_Write_String(0xcc,1,(u8*)" ");
Lcd1602_Write_String(0x86,1,(u8*)">");
if(Key0==0) { Tmin++; }
if(Key1==0) { Tmin--; }
break;
case 2:
Lcd1602_Write_String(0x86,1,(u8*)" ");
Lcd1602_Write_String(0x8c,1,(u8*)" ");
Lcd1602_Write_String(0xcc,1,(u8*)" ");
Lcd1602_Write_String(0xc6,1,(u8*)">");
if(Key0==0) { Wmin++; }
if(Key1==0) { Wmin--; }
break;
case 3:
Lcd1602_Write_String(0xc6,1,(u8*)" ");
Lcd1602_Write_String(0xcc,1,(u8*)" ");
Lcd1602_Write_String(0x86,1,(u8*)" ");
Lcd1602_Write_String(0x8c,1,(u8*)"<");
if(Key0==0) { Tmax++; }
if(Key1==0) { Tmax--; }
break;
case 4:
Lcd1602_Write_String(0xc6,1,(u8*)" ");
Lcd1602_Write_String(0x8c,1,(u8*)" ");
Lcd1602_Write_String(0x86,1,(u8*)" ");
Lcd1602_Write_String(0xcc,1,(u8*)"<");
if(Key0==0) { Wmax++; }
if(Key1==0) { Wmax--; }
break;
}
}
}
24-32f-30