Ⅰ 基於C52單片機溫濕度監測系統 求高手指點迷津
1、加紅外收發裝置與其系統通訊
2、擴展塊FLASH存儲檢測數據本存儲
3、加鍾採用專用歷晶元反顯示1602便
Ⅱ Proteus模擬單片機測量空氣濕度
幾點說明:
1.主要是分以下幾個模塊寫的:SHT10,LCD1602,主函數,頭文件。
2.每支SHTxx感測器都在25℃(77 °F)和 3.3V條件下進行過標定並且完全符合精度指標.因為考慮到實際硬體5V的電壓比較好操作,所以SHT10用的精度採用的為5V時的參數。其他的都採取默認值(14bit濕度, 12bit 溫度)。
3.SHT10中所以部分我都編寫了。有的部分在本次程序中沒用到,也可以作為參考。
4.所有程序都已經加了注釋,且有模擬圖。
5.個人認為還可以在此基礎上添加個中斷。
6.程序編寫keil 4 ,模擬 protues7.5
/***********************************************************************************************************************************************************/
頭文件(tou.h):
#ifndef __TOU_H__
#define __TOU_H__
#include<reg52.h>
#include <intrins.h>
//#include <math.h> //Keil library
#define uchar unsigned char
enum {TEMP,HUMI};
sbit DATA = P1^7;
sbit SCK = P1^6;
sbit LcdRs= P2^4;
sbit LcdRw= P2^5;
sbit LcdEn= P2^6;
sfr DBPort= 0x80; //P0=0x80,P1=0x90,P2=0xA0,P3=0xB0.數據埠
/******** DS1602函數聲明 ********/
void LCD_Initial();
void GotoXY(unsigned char x, unsigned chary);
void Print(unsigned char *str);
void LCD_Write(bit style, unsigned charinput);
/******** SHT10函數聲明 ********/
void s_connectionreset(void);
char s_measure(unsigned char *p_value,unsigned char *p_checksum, unsigned char mode);
void calc_sth10(float *p_humidity ,float*p_temperature);
//float calc_dewpoint(float h,float t);
#endif
/***********************************************************************************************************************************************************/
SHT10程序(SHT10.c):
#include<tou.h>
#define noACK 0 //繼續傳輸數據,用於判斷是否結束通訊
#define ACK 1//結束數據傳輸;
//地址命令 讀/寫
#define STATUS_REG_W 0x06 //0000011 0
#define STATUS_REG_R 0x07 //0000011 1
#define MEASURE_TEMP 0x03 //0000001 1
#define MEASURE_HUMI 0x05 //0000010 1
#define RESET 0x1e//000 1111 0
//寫位元組程序
char s_write_byte(unsigned char value)
{
unsignedchar i,error=0;
for(i=0x80;i>0;i>>=1)//高位為1,循環右移
{
if(i&value) DATA=1; //和要發送的數相與,結果為發送的位
else DATA=0;
SCK=1;
_nop_();_nop_();_nop_(); //延時3us
SCK=0;
}
DATA=1; //釋放數據線
SCK=1;
error=DATA; //檢查應答信號,確認通訊正常
_nop_();_nop_();_nop_();
SCK=0;
DATA=1;
returnerror; //error=1 通訊錯誤
}
//讀位元組程序
char s_read_byte(unsigned char ack)
//----------------------------------------------------------------------------------
{
unsignedchar i,val=0;
DATA=1; //釋放數據線
for(i=0x80;i>0;i>>=1) //高位為1,循環右移
{
SCK=1;
if(DATA) val=(val|i); //讀一位數據線的值
SCK=0;
}
DATA=!ack; //如果是校驗,讀取完後結束通訊;
SCK=1;
_nop_();_nop_();_nop_(); //延時3us
SCK=0;
_nop_();_nop_();_nop_();
DATA=1; //釋放數據線
returnval;
}
//啟動傳輸
void s_transstart(void)
// generates a transmission start
//_____ ________
// DATA: |_______|
//___ ___
// SCK : ___| |___||______
{
DATA=1; SCK=0; //准備
_nop_();
SCK=1;
_nop_();
DATA=0;
_nop_();
SCK=0;
_nop_();_nop_();_nop_();
SCK=1;
_nop_();
DATA=1;
_nop_();
SCK=0;
}
//連接復位
void s_connectionreset(void)
// communication reset: DATA-line=1 and atleast 9 SCK cycles followed by transstart
//_____________________________________________________ ________
// DATA:|_______|
//_ _ __ _ __ _ ____ ___
// SCK : __| |__| |__| |__| |__| |__| |__||__| |__| |______| |___| |______
{
unsignedchar i;
DATA=1;SCK=0; //准備
for(i=0;i<9;i++) //DATA保持高,SCK時鍾觸發9次,發送啟動傳輸,通迅即復位
{
SCK=1;
SCK=0;
}
s_transstart(); //啟動傳輸
}
//軟復位程序
char s_softreset(void)
// resets the sensor by a softreset
{
unsignedchar error=0;
s_connectionreset(); //啟動連接復位
error+=s_write_byte(RESET); //發送復位命令
returnerror; //error=1 通訊錯誤
}
/*讀狀態寄存器
char s_read_statusreg(unsigned char*p_value, unsigned char *p_checksum)
//----------------------------------------------------------------------------------
// reads the status register with checksum(8-bit)
{
unsignedchar error=0;
s_transstart(); //transmission start
error=s_write_byte(STATUS_REG_R);//send command to sensor
*p_value=s_read_byte(ACK); //read status register (8-bit)
*p_checksum=s_read_byte(noACK); //read checksum (8-bit)
returnerror; //error=1 incase of no response form the sensor
}
Ⅲ 51單片機的溫濕度檢測中加入一個PM值檢測模塊,兩個模塊是並行的嗎
單片機的程序不是並行的.
每個檢測都是分先後次序進行的.
Ⅳ 51單片機c語言編程的溫濕度檢測控製程序
/********************************************************************
*
文件名
:
溫度採集DS18B20.c
*
描述
:
該文件實現了用溫度感測器件DS18B20對溫度的採集,並在數碼管上顯示出來。
*
創建人
:
東流,2009年4月10日
*
版本號
:
2.0
***********************************************************************/
#include<reg52.h>
#define
uchar
unsigned
char
#define
uint
unsigned
int
#define
jump_ROM
0xCC
#define
start
0x44
#define
read_EEROM
0xBE
sbit
DQ
=
P2^3;
//DS18B20數據口
unsigned
char
TMPH,TMPL;
uchar
code
table[10]
=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
/********************************************************************
*
名稱
:
delay()
*
功能
:
延時,延時時間大概為140US。
*
輸入
:
無
*
輸出
:
無
***********************************************************************/
void
delay_1()
{
int
i,j;
for(i=0;
i<=10;
i++)
for(j=0;
j<=2;
j++)
;
}
/********************************************************************
*
名稱
:
delay()
*
功能
:
延時函數
*
輸入
:
無
*
輸出
:
無
***********************************************************************/
void
delay(uint
N)
{
int
i;
for(i=0;
i<N;
i++)
;
}
/********************************************************************
*
名稱
:
Delay_1ms()
*
功能
:
延時子程序,延時時間為
1ms
*
x
*
輸入
:
x
(延時一毫秒的個數)
*
輸出
:
無
***********************************************************************/
void
Delay_1ms(uint
i)//1ms延時
{
uchar
x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
/********************************************************************
*
名稱
:
Reset()
*
功能
:
復位DS18B20
*
輸入
:
無
*
輸出
:
無
***********************************************************************/
uchar
Reset(void)
{
uchar
deceive_ready;
DQ
=
0;
delay(29);
DQ
=
1;
delay(3);
deceive_ready
=
DQ;
delay(25);
return(deceive_ready);
}
/********************************************************************
*
名稱
:
read_bit()
*
功能
:
從DS18B20讀一個位值
*
輸入
:
無
*
輸出
:
從DS18B20讀出的一個位值
***********************************************************************/
uchar
read_bit(void)
{
uchar
i;
DQ
=
0;
DQ
=
1;
for(i=0;
i<3;
i++);
return(DQ);
}
/********************************************************************
*
名稱
:
write_bit()
*
功能
:
向DS18B20寫一位
*
輸入
:
bitval(要對DS18B20寫入的位值)
*
輸出
:
無
***********************************************************************/
void
write_bit(uchar
bitval)
{
DQ=0;if(bitval==1)
DQ=1;
delay(5);
DQ=1;
}
/********************************************************************
*
名稱
:
read_byte()
*
功能
:
從DS18B20讀一個位元組
*
輸入
:
無
*
輸出
:
從DS18B20讀到的值
***********************************************************************/
uchar
read_byte(void)
{
uchar
i,m,receive_data;
m
=
1;
receive_data
=
0;
for(i=0;
i<8;
i++)
{
if(read_bit())
{
receive_data
=
receive_data
+
(m
<<
i);
}
delay(6);
}
return(receive_data);
}
/********************************************************************
*
名稱
:
write_byte()
*
功能
:
向DS18B20寫一個位元組
*
輸入
:
val(要對DS18B20寫入的命令值)
*
輸出
:
無
***********************************************************************/
void
write_byte(uchar
val)
{
uchar
i,temp;
for(i=0;
i<8;
i++)
{
temp
=
val
>>
i;
temp
=
temp
&
0x01;
write_bit(temp);
delay(5);
}
}
/********************************************************************
*
名稱
:
Main()
*
功能
:
主函數
*
輸入
:
無
*
輸出
:
無
***********************************************************************/
void
main()
{
float
tt;
uint
temp;
P2
=
0x00;
while(1)
{
Reset();
write_byte(jump_ROM);
write_byte(start);
Reset();
write_byte(jump_ROM);
write_byte(read_EEROM);
TMPL
=
read_byte();
TMPH
=
read_byte();
temp
=
TMPL
/
16
+
TMPH
*
16;
P0
=
table[temp/10%10];
P2
=
6;
Delay_1ms(5);
P0
=
table[temp%10];
P2
=
7;
Delay_1ms(5);
}
}
Ⅳ 單片機C語言編程 用DHT11進行濕度檢測
嵌入式的編程對硬體依賴較大,不同硬體結構編出來的程序時序上差別很大。不知道你使用的是什麼單片機?怎麼連線驅動DHT11的?
Ⅵ 基於單片機的溫濕度檢測系統設計
<<pic單片機應用系統開發典型實例〉〉有差不多的例子,不過 是數碼顯示,不是液晶顯示。液晶程序上網上找就行啊,www.pic16.com上有很多程序,或許有現成的。
Ⅶ 單片機溫度濕度光照檢測,能問下這5各部分是什麼嗎。。。
1:電位器 調液晶亮度的
2:蜂鳴器 報警音
3:繼電器 隔離控制高壓端
4:不知道是個什麼模塊,看不到正面
5:溫濕度感測器
Ⅷ 溫濕度感測器為什麼要接單片機的中斷口才可以監測
因為單片機在溫濕度感測器中是以最小系統作為核心控制電路的,同時控制感測器採集的溫濕度的轉換。
單片機是一種集成電路晶元,是採用超大規模集成電路技術把具有數據處理能力的中央處理器CPU、隨機存儲器RAM、只讀存儲器ROM、多種I/O口和中斷系統、定時器/計數器等功能(可能還包括顯示驅動電路、脈寬調制電路、模擬多路轉換器、A/D轉換器等電路)集成到一塊矽片上構成的一個小而完善的微型計算機系統,在工業控制領域廣泛應用。
Ⅸ 基於單片機溫濕度測量系統(摘要翻譯)
Along with the humiture examination system's widespread utilization, the different profession and the domain have the various requirement and the standard to the humiture examination. This design mainly uses in the ordinary indoor humiture survey. Uses the DS2438, HIH3605B integration chip to take the humiture sensor. In the article has analyzed the humiture survey principle of work and the process, proposed the humiture examination system design's overall plan, has carried on the plan proof to each submole design and compares. The hardware design uses protel the 99se software, has completed the monolithic integrated circuit smallest system, the LCD display circuit, sensor's schematic diagram and the PCB chart. The software design uses Keil uVision2, has completed the program mole each mole design programming, has realized to the humiture signal processing process programming and the debugging. This measurement system humidity measuring range 0%~100%, resolution ±2%; Temperature survey scope - 40~+125℃, resolution ±0.5℃. Can meet the daily life humiture survey requirements.
key words: AT89S52; HIH3605B; DS2438; LCD; Data acquisition; Data processing