×
单片机 > 单片机程序设计 > 详情

SHT10温湿度传感器应用,含单片机源码

发布时间:2020-06-18 发布时间:
|

早几年用了SHT10的温湿度传感器,稳定,可靠,就是更新数据时间比较长些,
电路很简单,请看手册,
已经在产品中使用了,请放心使用和指正,

#include

#include

#include

/*********************************************************************************************************/         

#include "sht.h"

#include "uart.h"

#include "key.h"

#include "IO.h" 

#include "Lcd.h"

/*********************************************************************************************************/

enum {TEMP,HUMI};  

/*********************************************************************************************************/

//0: 温度1, 1:湿度1 , 2 : 温度2, 3: 湿度2

float   todao[4];                                        //{temp,rh};  模拟量寄存器从1到2      

float   humi_val1;                                       //湿度变量

float   temp_val1;                                       //温度变量


unsigned int   humi_val;                                //湿度变量

unsigned int   temp_val;                                //温度变量

unsigned char  checksum;

/*

const float C1=-4;                                      // for 12 Bit RH

const float C2=+0.0405;                                 // for 12 Bit RH

const float C3=-0.0000028;                              // for 12 Bit RH

const float T1=+0.01;                                   // for 12 Bit RH

const float T2=+0.00008;                                // for 12 Bit RH

*/

const float C1=-2.0468;                                 // for 12 Bit RH

const float C2=+0.0367;                                 // for 12 Bit RH

const float C3=-0.0000015955;                           // for 12 Bit RH

const float T1=+0.01;                                   // for 12 Bit RH

const float T2=+0.00008;                                // for 12 Bit RH


/*********************************************************************************************************/

extern unsigned char wendu1_biaozhi;

extern unsigned char wendu2_biaozhi;    

extern unsigned char  R_KeyValue1;                                                                                

/*********************************************************************************************************/ 


/**********************************************************************************************************

** 函数名称: s_write_byte()

** 函数功能: SHT10写单个字节, 写一个字节并输出ACK验证

** 入口参数: 写入单个字节

** 出口参数: ACK验证

** 说    明: writes a byte on the Sensibus and checks the acknowledge

*********************************************************************************************************/

                     

unsigned char s_write_byte(unsigned char value)                                                                            

{                                                                                                                 

    unsigned char i,j,error1=0;                                                                                        

    SHT10_SDA1_OUT;

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

     {                                                                                                                  

       if (i & value)                                                                                                   

               SHT10_SDA1_OUT1;                  //masking value with i , write to SENSI-BUS                                                

       else                                                                                                           

              SHT10_SDA1_OUT0;                                                                                                      

       SHT10_SCK1_OUT1;                   //clk for SENSI-BUS                                                           

       for(j = 0; j<40;j++)

           {

             NOP();                           //pulswith approx. 5 us                                                                                                         

       }

       SHT10_SCK1_OUT0;                                                                                                           

     }    

        NOP();                                                                                                         

NOP();



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
51单片机的线阵CCD实时检测系统的开发