第一范文网 - 专业文章范例文档资料分享平台

毕业设计(论文)基于at89c51单片机温湿度显示报警系统设计

来源:用户分享 时间:2025/5/20 4:49:39 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

附录

}

void s_connectionreset(void) //连接复位函数

// communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart // _____________________________________________________ ________

// DATA: |_______| // _ _ _ _ _ _ _ _ _ ___ ___ // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ {

unsigned char i;

DATA=1; SCK=0; //Initial state for(i=0;i<9;i++) //9 SCK cycles { SCK=1; SCK=0; }

s_transstart(); //transmission start }

char s_write_byte(unsigned char value) // SHT10写字节函数 //---------------------------------------------------------------------------------- // writes a byte on the Sensibus and checks the acknowledge {

unsigned char i,error=0;

for (i=0x80;i>0;i/=2) //shift bit for masking {

第37页(共43页)

基于单片机温湿度显示报警系统设计

if (i & value) DATA=1; //masking value with i , write to SENSI-BUS else DATA=0;

SCK=1; //clk for SENSI-BUS _nop_();_nop_();_nop_(); //pulswith approx. 3 us SCK=0; }

DATA=1; //release DATA-line SCK=1; //clk #9 for ack

error=DATA; //check ack (DATA will be pulled down by DHT90),DATA在第9个上升沿将被DHT90自动下拉为低电平。 _nop_();_nop_();_nop_(); SCK=0;

DATA=1; //release DATA-line

return error; //error=1 in case of no acknowledge //返回:0成功,1失败 }

/*****SHT10读函数 reads a byte form the Sensibus and gives an acknowledge in case of \ char s_read_byte(unsigned char ack) {

unsigned char i,val=0;

DATA=1; //release DATA-line for (i=0x80;i>0;i/=2) //shift bit for masking { SCK=1; //clk for SENSI-BUS if (DATA) val=(val | i); //read bit

_nop_();_nop_();_nop_(); //pulswith approx. 3 us

SCK=0;

第38页(共43页)

附录

}

if(ack==1)DATA=0; //in case of \ else DATA=1; //如果是校验(ack==0),读取完后结束通讯 _nop_();_nop_();_nop_(); //pulswith approx. 3 us SCK=1; //clk #9 for ack _nop_();_nop_();_nop_(); //pulswith approx. 3 us SCK=0;

_nop_();_nop_();_nop_(); //pulswith approx. 3 us DATA=1; //release DATA-line return val; }

/* 测量温湿度函数 makes a measurement (humidity/temperature) with checksum */

char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode) {

unsigned error=0; unsigned int i;

s_transstart(); //transmission start

switch(mode){ //send command to sensor case TEMP : error+=s_write_byte(MEASURE_TEMP); break; case HUMI : error+=s_write_byte(MEASURE_HUMI); break; default : break; }

for (i=0;i<65535;i++) if(DATA==0) break; //wait until sensor has finished the measurement

第39页(共43页)

基于单片机温湿度显示报警系统设计

if(DATA) error+=1; // or timeout (~2 sec.) is reached *(p_value) =s_read_byte(ACK); //read the first byte (MSB) *(p_value+1)=s_read_byte(ACK); //read the second byte (LSB) *p_checksum =s_read_byte(noACK); //read checksum return error; }

void calc_sht90(float *p_humidity ,float *p_temperature) //温湿度补偿函数 // calculates temperature [C] and humidity [%RH] // input : humi [Ticks] (12 bit) // temp [Ticks] (14 bit) // output: humi [%RH] // temp [C]

{ const float C1=-4.0; // for 12 Bit const float C2=+0.0405; // for 12 Bit const float C3=-0.0000028; // for 12 Bit const float T1=+0.01; // for 14 Bit @ 5V const float T2=+0.00008; // for 14 Bit @ 5V

float rh=*p_humidity; // rh: Humidity [Ticks] 12 Bit float t=*p_temperature; // t: Temperature [Ticks] 14 Bit float rh_lin; // rh_lin: Humidity linear

float rh_true; // rh_true: Temperature compensated humidity float t_C; // t_C : Temperature [C]

t_C=t*0.01 - 40; //calc. temperature from ticks to [C] rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH] rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity

第40页(共43页)

毕业设计(论文)基于at89c51单片机温湿度显示报警系统设计.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c12ahs9655t1klhk34qtg_10.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top