基于STM32智能物联水控系统研究
资料
资源链接!!!https://download.csdn.net/download/wangshuqian1314/85214960
蓝牙研究
http://app.gzjkw.net/login/ 可以通过这个进行图形化开发蓝牙APP!
温度程序
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart1.h"
#include "LCD1602.h"
#include "ds18b20.h"
#include "string.h"
#include "stdio.h"
char send_data[]="Heartbeats:000,Temp:00.0C\r\n";
#define true 1
#define false 0
int Num;
unsigned char firstBeat = true;
unsigned char secondBeat = false;
unsigned char DisBuff[4]={0};
u8 setn = 0;
u8 tempMax=38;
void keyscan()
{
if(KEY1==0)
{
delay_ms(20);
if(KEY1==0)
{
while(KEY1==0);
setn++;
if(setn>1)
{
setn = 0;
LCD_Write_String(0,1,"Temp: 00.0C ");
}
if(setn==1)
{
LCD_Write_String(0,0," set Temperature");
LCD_Write_String(0,1," 00.0C ");
LCD_Write_Char(7,1,tempMax%100/10+'0');
LCD_Write_Char(8,1,tempMax%10+'0');
}
}
}
if(KEY2==0)
{
delay_ms(20);
if(KEY2==0)
{
while(KEY2==0);
if(setn==1)
{
if(tempMax < 99)tempMax++;
LCD_Write_Char(7,1,tempMax%100/10+'0');
LCD_Write_Char(8,1,tempMax%10+'0');
}
}
}
if(KEY3==0)
{
delay_ms(20);
if(KEY3==0)
{
while(KEY3==0);
if(setn==1)
{
if(tempMax > 0)tempMax--;
LCD_Write_Char(7,1,tempMax%100/10+'0');
LCD_Write_Char(8,1,tempMax%10+'0');
}
}
}
}
int main(void)
{
unsigned int count,cnt;
unsigned short temperature=0;
delay_init();
NVIC_Configuration();
Usart1_Init(9600);
delay_ms(300);
LCD_Init();
KEY_IO_Init();
BEEP_DISENABLE();
DS18B20_Init();
LCD_Write_String(0,1,"Temp: 00.0C ");
temperature = DS18B20_Get_Temp();
while(1)
{
keyscan();
if(count++ > 200 && setn == 0)
{
temperature = DS18B20_Get_Temp();
LCD_Write_Char(6,1,temperature%1000/100+'0');
LCD_Write_Char(7,1,temperature%100/10+'0');
LCD_Write_Char(9,1,temperature%10+'0');
send_data[20] = temperature%1000/100+'0';
send_data[21] = temperature%100/10+'0';
send_data[23] = temperature%10+'0';
if(cnt++ > 10)
{
cnt = 0;
Uart1_SendStr(send_data);
}
count = 0;
}
delay_ms(1);
}
}
智能水控系统
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "usart2.h"
#include "lcd.h"
#include "key.h"
#include "malloc.h"
#include "MMC_SD.h"
#include "ff.h"
#include "exfuns.h"
#include "fontupd.h"
#include "text.h"
#include "hc05.h"
#include "string.h"
#include "adc.h"
#include "timer.h"
#include "ds18b20.h"
#include "tempProcess.h"
#include "control.h"
#include "TouchDialog.h"
#include "stdlib.h"
#include "touch.h"
#include "myiic.h"
#include "24cxx.h"
#include "chaoshengbo.h"
#define TIMI 20
u32 tempall[3];
u8 tempstr[10];
u8 tempstr1[10];
u8 tempstr2[10];
u8 humistr[10];
u8 volstr[10];
u8 WaterFlag=0,OnceFlag=0;
u8 tempMeasure,vol=0;
char strsum[20]={0};
extern u8 TIM4CH3_CAPTURE_STA;
extern u16 TIM4CH3_CAPTURE_VAL;
void Int2Str(u8* str, u32 intnum)
{
u32 i, Div = 1000000000, j = 0, Status = 0;
for (i = 0; i < 10; i++)
{
str[j++] = (intnum / Div) + '0';
intnum = intnum % Div;
Div /= 10;
if ((str[j-1] == '0') & (Status == 0))
{
j = 0;
}
else
{
Status++;
}
}
}
void strcats(){
strcat(strsum,(char*)tempstr);
strcat(strsum,"+");
strcat(strsum,(char*)tempstr1);
strcat(strsum,"+");
strcat(strsum,(char*)tempstr2);
strcat(strsum,"#");
}
void lengthMeasure(void)
{
GPIO_SetBits(GPIOC,GPIO_Pin_0);
delay_us(15);
GPIO_ResetBits(GPIOC,GPIO_Pin_0);
}
int main(void)
{
u32 temperature,temperature1,temperature2;
float hottime=0,coldtime=0;
float distance;
u8 temp;
u8 temper=0;
u16 adcx;
u8 key,t=0,k;
u8 reclen=0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init();
uart_init(9600);
LCD_Init();
TIM3_Int_Init(1000,7199);
TIM_Cmd(TIM3, DISABLE);
TIM2_Int_Init(1000,7199);
TIM_Cmd(TIM3, DISABLE);
LED_Init();
KEY_Init();
Control_Init();
inputint();
Adc_Init();
mem_init();
exfuns_init();
f_mount(fs[0],"0:",1);
f_mount(fs[1],"1:",1);
while(font_init())
{
LCD_ShowString(60,70,200,16,16,"SD Card OK");
LCD_ShowString(60,90,200,16,16,"Font Updating...");
key=update_font(20,110,16);
while(key)
{
LCD_ShowString(60,110,200,16,16,"Font Update Failed!");
delay_ms(200);
LCD_Fill(20,110,200+20,110+16,WHITE);
delay_ms(200);
}
LCD_ShowString(60,110,200,16,16,"Font Update Success!");
delay_ms(1500);
LCD_Clear(WHITE);
}
POINT_COLOR=RED;
Show_Str(50,20,200,24,"智能水控系统",24,0);
Show_Str(30,100,200,16,"当前热水温度: . C",16,0);
Show_Str(30,120,200,16,"当前冷水温度: . C",16,0);
Show_Str(30,140,200,16,"当前混合水温度: . C",16,0);
Show_Str(30,160,200,16,"本次用水:",16,0);
while(DS18B20_Init())
{
LCD_ShowString(60,130,200,16,16,"DS18B20 Error");
delay_ms(200);
LCD_Fill(60,130,239,130+16,WHITE);
delay_ms(200);
}
while(DS18B20_Init1())
{
LCD_ShowString(60,130,200,16,16,"DS18B20 Error");
delay_ms(200);
LCD_Fill(60,130,239,130+16,WHITE);
delay_ms(200);
}
while(DS18B20_Init2())
{
LCD_ShowString(60,130,200,16,16,"DS18B20 Error");
delay_ms(200);
LCD_Fill(60,130,239,130+16,WHITE);
delay_ms(200);
}
while(HC05_Init())
{
LCD_ShowString(30,90,200,16,16,"ATK-HC05 Error!");
delay_ms(500);
LCD_ShowString(30,90,200,16,16,"Please Check!!!");
delay_ms(100);
}
key=HC05_Get_Role();
HC05_Set_Cmd("AT+ROLE=0");
HC05_Set_Cmd("AT+RESET");
while(1)
{
if(t%10==0)
{
temperature=DS18B20_Get_Temp();
temperature1=DS18B20_Get_Temp1();
temperature2=DS18B20_Get_Temp2();
tempall[0]=temperature/10;
tempall[1]=temperature1/10;
tempall[2]=temperature2/10;
Int2Str(tempstr,tempall[0]);
Int2Str(tempstr1,tempall[1]);
Int2Str(tempstr2,tempall[2]);
strcats();
LCD_ShowString(80,200,209,119,16,(u8*)strsum);
u2_printf("%s#",(u8*)strsum);
for(k=0;k<20;k++){
strsum[k]='\0';
}
if(temperature<0)
{
LCD_ShowChar(30+70+32,100,'-',16,0);
temperature=-temperature;
}else LCD_ShowChar(30+70+32,100,' ',16,0);
LCD_ShowNum(30+70+8+32,100,temperature/10,2,16);
LCD_ShowNum(30+70+32+32,100,temperature%10,1,16);
if(temperature1<0)
{
LCD_ShowChar(30+70+32,120,'-',16,0);
temperature1=-temperature1;
}else LCD_ShowChar(30+70+32,120,' ',16,0);
LCD_ShowNum(30+70+8+32,120,temperature1/10,2,16);
LCD_ShowNum(30+70+32+32,120,temperature1%10,1,16);
if(temperature2<0)
{
LCD_ShowChar(30+70+48,140,'-',16,0);
temperature2=-temperature2;
}else LCD_ShowChar(30+70+48,140,' ',16,0);
LCD_ShowNum(30+70+8+48,140,temperature2/10,2,16);
LCD_ShowNum(30+70+32+48,140,temperature2%10,1,16);
}
delay_ms(10);
t++;
if(t==20)
{
t=0;
LED0=!LED0;
}
if(USART2_RX_STA&0X8000)
{
reclen=USART2_RX_STA&0X7FFF;
USART2_RX_BUF[reclen]=0;
if(reclen<USART2_MAX_RECV_LEN)
{
if(!strcmp((const char*)USART2_RX_BUF,"w")){
WaterFlag=0;
}else {
WaterFlag=1;
}
}
LCD_ShowString(30,200,209,119,16,USART2_RX_BUF);
for(k=0;k<200;k++){
USART2_RX_BUF[k]='\0';
}
USART2_RX_STA=0;
LED1=1;
}
if(WaterFlag){
Get_Distance();
while(!FLAG_CSB);
FLAG_CSB=0;
distance=(float)(TIME_GET)*0.034*0.5;
LCD_ShowxNum(135,220,(u16)distance,2,16,0x80);
if((distance<=5)&&(!OnceFlag)){
OnceFlag=1;
LED1=0;
temper=tempControl();
hottime=getHotwaterTime(temper);
coldtime=getColdwaterTime(temper);
LCD_ShowNum(30,240,temper,2,16);
LCD_ShowNum(30,260,hottime,3,16);
LCD_ShowNum(30,280,coldtime,3,16);
if(hottime>0){
IN1=1;
TIM2->ARR=hottime*1000-1;
TIM_Cmd(TIM2, ENABLE);
}
if(coldtime>0){
IN2=1;
TIM3->ARR=coldtime*1000-1;
TIM_Cmd(TIM3, ENABLE);
}
vol=hottime*3.2+coldtime*4.7;
LCD_ShowNum(30+70+8,160,vol,3,16);
}
else
{
if(distance>=25)
{
OnceFlag=0;
}
LED1=1;
}
}
}
}
|