欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
基于單片機DHT11濕度測量與控制-CO2光照報警系統程序和仿真
[打印本頁]
作者:
bbxyliyang
時間:
2023-11-26 19:32
標題:
基于單片機DHT11濕度測量與控制-CO2光照報警系統程序和仿真
一、系統方案
1、本設計采用這51單片機作為主控器。
2、DHT11溫濕度、CO2、光照強度送到液晶1602顯示。
3、按鍵設置報警值。
4、蜂鳴器報警。
1.png
(5.52 KB, 下載次數: 53)
下載附件
2023-11-26 19:32 上傳
二、硬件設計
原理圖如下:
2.png
(82.61 KB, 下載次數: 40)
下載附件
2023-11-26 19:32 上傳
三、單片機軟件設計
1、首先是系統初始化
//初始化LCD************************************************************
void LCD_Initial()
{
E=0;
LCD_Write(LCD_COMMAND,0x38); //8位數據端口,2行顯示,5*7點陣
LCD_Write(LCD_COMMAND,0x38);
LCD_SetDisplay(LCD_SHOW|LCD_NO_CURSOR); //開啟顯示, 無光標
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
LCD_SetInput(LCD_AC_UP|LCD_NO_MOVE); //AC遞增, 畫面不動
}
2、液晶顯示程序
//1602程序
//內部等待函數*************************************************************
unsigned char LCD_Wait(void)
{
RS=0;
RW=1; _nop_();
E=1; _nop_();
E=0;
return DBPort;
}
//向LCD寫入命令或數據********************************************************
#define LCD_COMMAND 0 // Command
#define LCD_DATA 1 // Data
#define LCD_CLEAR_SCREEN 0x01 // 清屏
#define LCD_HOMING 0x02 // 光標返回原點
void LCD_Write(bit style, unsigned char input)
{
E=0;
RS=style;
RW=0; _nop_();
DBPort=input; _nop_();//注意順序
E=1; _nop_();//注意順序
E=0; _nop_();
LCD_Wait();
}
3、按鍵程序
void key()
{
uchar m;
if (k1==0) //調整按鍵檢測
{
delay(10);
if (k1==0)
{
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
presskeynum++;
if(presskeynum==8)
{
presskeynum=0;
}
while(k1==0);
}
}
if(presskeynum==1)//溫度上限設置
{
if(k2==0)// 加
{
delay(300);
temp_high++;
if (temp_high>99)
temp_high=0;
if (temp_high<0)
temp_high=99;
while(k2==0); //加上此句必須松按鍵才處理
}
if(k3==0)//減
{
delay(300);
temp_high--;
if (temp_high>99)
temp_high=0;
if (temp_high<0)
temp_high=99;
while(k3==0); //加上此句必須松按鍵才處理
}
}
if(presskeynum==2)//溫度下限設置
{
if(k2==0)// 加
{
delay(300);
temp_low++;
if (temp_low>99)
temp_low=0;
if (temp_low<0)
temp_low=99;
while(k2==0);
}
if(k3==0)
{
delay(300);
temp_low--;
if (temp_low>99)
temp_low=0;
if (temp_low<0)
temp_low=99;
while(k3==0);
}
}
if(presskeynum==3)//濕度上限設置
{
if(k2==0)// 加
{
delay(300);
humi_high++;
if (humi_high>99)
humi_high=0;
if (humi_high<0)
humi_high=99;
while(k2==0);
}
if(k3==0)
{
delay(300);
humi_high--;
if (humi_high>99)
humi_high=0;
if (humi_high<0)
humi_high=99;
while(k3==0);
}
}
if(presskeynum==4)//濕度下限設置
{
if(k2==0)//加
{
delay(300);
humi_low++;
if (humi_low>99)
humi_low=0;
if (humi_low<0)
humi_low=99;
while(k2==0);
}
if(k3==0)// 減
{
delay(300);
humi_low--;
if (humi_low>99)
humi_low=0;
if (humi_low<0)
humi_low=99;
while(k3==0);
}
}
if(presskeynum==5)//濕度下限設置
{
if(k2==0)//加
{
delay(300);
gh++;
if (gh>99)
gh=0;
while(k2==0);
}
if(k3==0)// 減
{
delay(300);
gh--;
gh=99;
while(k3==0);
}
}
if(presskeynum==6)//濕度下限設置
{
if(k2==0)//加
{
delay(300);
gl++;
if (gl>99)
gl=0;
humi_low=99;
while(k2==0);
}
if(k3==0)// 減
{
delay(300);
gl--;
if (gl<0)
gl=99;
while(k3==0);
}
}
if(presskeynum==7)//濕度下限設置
{
if(k2==0)//加
{
delay(300);
CO2++;
if (CO2>99)
CO2=0;
while(k2==0);
}
if(k3==0)// 減
{
delay(300);
CO2--;
if (CO2<0)
CO2=99;
while(k3==0);
}
}
if(k4==0)// 退出鍵
{
delay(10);
if(k4==0)
{
while(k4==0);
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
presskeynum=0;
temp_humi_cache[0]=temp_high;
temp_humi_cache[1]=temp_low;
temp_humi_cache[2]=humi_high;
temp_humi_cache[3]=humi_low;
temp_humi_cache[4]=gh;
temp_humi_cache[5]=gl;
temp_humi_cache[6]=CO2;
for(m=0;m<=6;m++)
{
WriteIIC(W_cmd,0x00+m,temp_humi_cache[m]); //設定值寫入24c02
}
}
}
}
4、核心算法程序
unsigned char adc0832(unsigned char CH)
{
unsigned char i,test,adval;
adval = 0x00;
test = 0x00;
Clk = 0;
DATI = 1;
_nop_();
CS = 0;
_nop_();
Clk = 1;
_nop_();
if ( CH == 0x00 )
{
Clk = 0;
DATI = 1;
_nop_();
Clk = 1;
_nop_();
Clk = 0;
DATI = 0;
_nop_();
Clk = 1;
_nop_();
}
else
{
Clk = 0;
DATI = 1;
_nop_();
Clk = 1;
_nop_();
Clk = 0;
DATI = 1;
_nop_();
Clk = 1;
_nop_();
}
Clk = 0;
DATI = 1;
for( i = 0;i < 8;i++ )
{
_nop_();
adval <<= 1;
Clk = 1;
_nop_();
Clk = 0;
if (DATO)
adval |= 0x01;
else
adval |= 0x00;
}
for (i = 0; i < 8; i++)
{
test >>= 1;
if (DATO)
test |= 0x80;
else
test |= 0x00;
_nop_();
Clk = 1;
_nop_();
Clk = 0;
}
if (adval == test)
dat = test;
_nop_();
CS = 1;
DATO = 1;
Clk = 1;
return dat;
}
復制代碼
四、 proteus仿真設計
Proteus軟件是一款應用比較廣泛的工具,它可以在沒有硬件平臺的基礎上通過自身的軟件仿真出硬件平臺的運行情況,這樣就可以通過軟件仿真來驗證我們設計的方案有沒有問題,如果有問題,可以重新選擇器件,連接器件,直到達到我們設定的目的,避免我們搭建實物的時候,如果當初選擇的方案有問題,我們器件都已經焊接好了,再去卸載下去,再去焊接新的方案的器件,測試,這樣會浪費人力和物力,也給開發者帶來一定困惑,Proteus仿真軟件就很好的解決這個問題,我們在設計之初,就使用該軟件進行模擬仿真,測試,選擇滿足我們設計的最優方案。最后根據測試沒問題的仿真圖紙,焊接實物,調試,最終完成本設計的作品。
作者:
一起追風箏
時間:
2024-4-16 09:45
您好,可以在附件分享一下電路圖設計和仿真圖設計嗎
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1