当前位置:首页 > 毕业设计 基于PROTEUS的温湿度测量系统设计
河南城建学院本科毕业设计(论文) 附录A 系统源程序
}
/*========================================= 发送指令到SHT11执行温度和湿度的测量转换 =========================================*/ convert_SHT(SHT_dat *s,uchar mode) { uchar i,ack=0;
uchar valueM,valueL,checksum; float com; do{reset_SHT();
switch(mode)
{ case TEMP: ack=write_byte(0x03);break; case HUMI: ack=write_byte(0x05);break; default: break;} }while(ack==1);
for(i=0;i<65535;i++) //等待测量结束 {
if(DQ==0)break;
} //若长时间数据线DQ没拉低,则说明测量有错误 valueM=read_byte(0); //数据的高字节 valueL=read_byte(0); //数据的低字节 checksum=read_byte(1); //CRC校验码 com=(float)valueM*256+(float)valueL; if(mode==TEMP)
{ s->temperature=com;
s->crc_temp=(float)checksum; } if(mode==HUMI) { s->humidity=com;
s->crc_humi=(float)checksum; } }
/*========================================= 温度和湿度补偿及输出温度值和相对湿度值 =========================================*/ void caculation_SHT(SHT_dat *s) { const float c1=-4.0;
45
河南城建学院本科毕业设计(论文) 附录A 系统源程序
const float c2=+0.0405;
const float c3=-0.0000028; //以上为12位湿度修正公示取值 const float t1=+0.01;
const float t2=+0.00008; //以上为14位温度修正公示取值 float t=s->temperature; float rh=s->humidity; float rh_lin; float rh_ture; float t_c;
t_c=t * 0.01 - 40; //温度的补偿
rh_lin=c3*rh*rh + c2*rh + c1; //相对湿度非线性补偿 rh_ture=( t_c - 25 ) * ( t1 + t2*rh ) + rh_lin; //相对湿度对于温度依赖性补偿
if( rh_ture > 100 ) rh_ture=100; //相对湿度最大值修正 if( rh_ture < 0.1 ) rh_ture=0.1; //相对湿度最小值修正 if(t_c<0)t_c=0;
s->temperature=t_c; //保存温度补偿后的结果 s->humidity=rh_ture; //保存相对湿度补偿后的结果 }
/*========================================= 计算绝对湿度值
========================================= float calc_dewpoint(float h,float t) {
float logEx,dew_point;
logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
dew_point = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx); return dew_point; }
/*========================================= 浮点数数据处理
=========================================*/ void float_convert(SHT_dat *s) {
46
共分享92篇相关文档