標(biāo)題:
基于51單片機(jī)的智能空調(diào)程序
[打印本頁(yè)]
作者:
我是華夏人
時(shí)間:
2020-12-21 21:41
標(biāo)題:
基于51單片機(jī)的智能空調(diào)程序
#include "reg52.h"
#include "lcd.h"
#include "temp.h"
#include "i2c.h"
sbit k3=P3^2; //設(shè)置溫度上下限
sbit k1=P3^1; //加
sbit k2=P3^0; //減
sbit led=P2^4; //報(bào)警指示燈
sbit beep=P1^5; //蜂鳴器報(bào)警
sbit relay=P1^1; // 設(shè)備加熱和繼電器
sbit moto=P1^0; // 電機(jī)散熱
char set_temph=0,a=0;//,set_templ=28; //設(shè)定溫度限默認(rèn)值
u16 temp_val; //檢測(cè)的實(shí)際溫度
u8 mode; //溫度模式
void delay(u16 i)
{
while(i--);
}
void Temp_DataPros()
{
char set_temph=a;//,set_templ=28; //設(shè)定溫度上下限默認(rèn)值
short temp;
u8 temp_buf[5];
temp=Ds18b20ReadTemp();
temp_val=temp;
if(temp<0)
{
temp=-temp;
LCD_Dispstring(3+5,0,"-");
}
else
{
LCD_Dispstring(3+5,0," ");
}
temp_buf[0]=temp/100+0x30;
temp_buf[1]=temp%100/10+0x30;
temp_buf[2]='.';
temp_buf[3]=temp%100%10+0x30;
temp_buf[4]='\0';
LCD_Dispstring(3+6,0,temp_buf); //顯示檢測(cè)的溫度xx.x
set_temph=a;
temp_buf[0]=set_temph/10+0x30;
temp_buf[1]=set_temph%10+0x30;
temp_buf[2]='\0';
LCD_Dispstring(8,1,temp_buf); //顯示設(shè)定的溫度值xx */
}
#define K1_MODE 1
#define K2_ADD 2
#define K3_DEC 3
//mode: 0-單次掃描 1-連續(xù)掃描
u8 KEY_Scan(u8 mode)
{
static u8 key=1;
if(key&&(k1==0||k2==0||k3==0))
{
delay(1000); //消抖
key=0;
if(k3==0)
{
return K1_MODE;
}
else if(k1==0)
{
return K2_ADD;
}
else if(k2==0)
{
return K3_DEC;
}
}
else if(k1==1&&k2==1&&k3==1)
{
key=1;
}
if(mode)
{
key=1;
}
return 0;
}
void sound()
{
u8 i=50;
while(i--)
{
beep=!beep;
delay(10);
}
}
void KEY_Pros()
{
u8 key;
u8 temph_buf[3];
key=KEY_Scan(0);
if(key==K1_MODE) //模式選擇
{
mode++;
LCD_Clear();
if(mode==1)
{
LCD_Dispstring(4,0,"SET: C");
}
else
{
mode=0;
LCD_Dispstring(3,0,"Temp: C");
LCD_Dispstring(4,1,"SET: C");
}
}
if(mode==1) //溫度上限設(shè)置
{
switch(key)
{
case K2_ADD: //加
set_temph++;
if(set_temph>=80)set_temph=80;
break;
case K3_DEC: //減
set_temph--;
if(set_temph<=0)set_temph=0;
break;
}
a=set_temph;
temph_buf[0]=set_temph/10+0x30;
temph_buf[1]=set_temph%10+0x30;
temph_buf[2]='\0';
LCD_Dispstring(8,0,temph_buf);
At24c02Write(0,set_temph);
}
}
void TempData_Compare()
{
if(temp_val>(set_temph+1)*10) //實(shí)際溫度高于上限值 報(bào)警 散熱
{
led=1;
moto=1; //1
relay=0;
sound();
}
else if(temp_val<(set_temph-1)*10) //實(shí)際溫度低于下限值 報(bào)警 加熱
{
led=1;
moto=0; //0
relay=1;
sound();
}
else //實(shí)際溫度在下限值和上限值之間 取消報(bào)警 取消加熱 取消散熱
{
moto=1;
led=0;
relay=1;
}
}
void kai_display()
{
if(At24c02Read(255)!=18)
{
At24c02Write(0,set_temph);
At24c02Write(255,18);
}
else
{
set_temph=At24c02Read(0);
}
LCD_Dispstring(3,0,"Temp: C");
LCD_Dispstring(4,1,"SET: C");
}
void main()
{
moto=0;
led=0;
relay=0;
LCD_Init();
kai_display();
while(1)
{
TempData_Compare();
if(mode==0)
Temp_DataPros();
KEY_Pros();
}
}
作者:
我是華夏人
時(shí)間:
2020-12-21 21:42
有疑問(wèn)的黑子們可以咨詢(xún)我,實(shí)物已經(jīng)做成功了。
作者:
51hei團(tuán)團(tuán)
時(shí)間:
2020-12-22 03:11
能上傳下工程包嗎?缺少頭文件無(wú)法編譯
作者:
我是華夏人
時(shí)間:
2020-12-24 19:37
Keil代碼文件:
智能空調(diào).rar
2020-12-24 19:37 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
63.12 KB, 下載次數(shù): 65, 下載積分: 黑幣 -5
作者:
happy33
時(shí)間:
2021-9-23 21:47
程序?qū)懙貌诲e(cuò),不過(guò)叫空調(diào)有點(diǎn)不妥,畢竟他沒(méi)有壓縮機(jī),應(yīng)該叫溫控烤箱
作者:
好好聚聚
時(shí)間:
2021-12-10 16:52
誰(shuí)能根據(jù)樓主的資料 制作一個(gè)仿真圖嗎?
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1