湿度测量原理sht11
SHT11湿度传感器采用的是湿敏电阻原理,它是一种特殊的电阻,当它接触到水分时,它的电阻值会发生变化。SHT11湿度传感器的工作原理是,它将湿敏电阻与一个精确的电压分压电路相结合,当湿敏电阻接触到水分时,它的电阻值会发生变化,这种变化会影响分压电路的输出电压,从而可以检测出环境中的湿度。

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.数据端口
void LCD_Initial();
void GotoXY(unsigned char x, unsigned chary);
void Print(unsigned char *str);
void LCD_Write(bit style, unsigned charinput);
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? //000?0011 0
#define STATUS_REG_R 0x07? //000?0011 1
#define MEASURE_TEMP 0x03? //000?0001 1
#define MEASURE_HUMI 0x05? //000?0010 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
}


