⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rw_sht.lst

📁 盛世瑞恩公司SHT90温湿度传感器 测量温湿度的源代码 C语言 51单片机
💻 LST
字号:
C51 COMPILER V7.20   RW_SHT                                                                04/30/2009 12:02:11 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE RW_SHT
OBJECT MODULE PLACED IN D:\QCXS_D~1\CXSY_W~1\PROJECT\SOURCE~1\V1.1\RW_SHT.OBJ
COMPILER INVOKED BY: D:\programs\keil\C51\BIN\C51.EXE D:\QCXS_D~1\CXSY_W~1\PROJECT\SOURCE~1\V1.1\RW_SHT.C DB SB OE

line level    source

   1          /*****************************************************************************************************
   2          * Filename:      SHT91_Sample_code
   3          * File func:     the command to write/read the sht_sensor
   4          * File description: the file is included in "main.c" to fulfill the read_write command
   5          * Prozessor:     80C51 Family
   6          * Compiler:      Keil    Wave IDE
   7          * Author:        qcx
   8          * Version:     v1.1
   9          *********************************************************************************************************/
  10          //-------------------------------------------------------------------------
  11          #include "math.h"
  12          #include "intrins.h"
  13          #include "sht_demo.h"
  14          //--------------------------------------------------------------------------
  15          char s_write_byte(unsigned char value)
  16          //--------------------------------------------------------------------------
  17          //writes a byte on the Sensibu and checks the acknowledge
  18          {
  19   1          unsigned char i,error=0;
  20   1          for (i=0x80;i>0;i/=2)       //shift bit for masking
  21   1          {
  22   2             if(i & value) DATA=1;    //masking value with i,write every bit of value
  23   2             else DATA=0;             //to SENSI-BUS
  24   2             SCK=1;                   //clk for SENSI-BUS
  25   2             _nop_ ();                //The frequancy of the clk should be less than
  26   2             _nop_ ();                //4k Hz
  27   2             _nop_ ();
  28   2             SCK=0;
  29   2          }
  30   1          DATA=1;
  31   1          SCK=1;
  32   1          error=DATA;
  33   1          SCK=0;
  34   1          return error;               //error=1 in case of no acknowledge
  35   1      }
  36          
  37          //-----------------------------------------------------------------------
  38          char s_read_byte(unsigned char ack)
  39          //-----------------------------------------------------------------------
  40          //func: read a byte from Sens-bus and gives an acknowledge
  41          {
  42   1          unsigned char i,val=0;
  43   1          for(i=0x80;i>0;i/=2)
  44   1          {
  45   2              SCK=1;
  46   2              if (DATA) val=(val | i);
  47   2              SCK=0;
  48   2          }
  49   1          DATA= !ack;              //in case of "ack==1" pull down DATA-Line
  50   1          SCK=1;
  51   1          _nop_();
  52   1          _nop_();    _nop_();
  53   1          DATA=1;
  54   1          return val;
  55   1      }
C51 COMPILER V7.20   RW_SHT                                                                04/30/2009 12:02:11 PAGE 2   

  56          
  57          //-------------------------------------------------------------------------
  58          void s_transstart(void)
  59          //-------------------------------------------------------------------------
  60          //func: generate a transmission start signal
  61          {
  62   1          DATA=1;
  63   1          SCK=0;             //initial state
  64   1          _nop_();
  65   1          SCK=1;
  66   1          _nop_();
  67   1          DATA=0;
  68   1          _nop_();
  69   1          SCK=0;
  70   1          _nop_();
  71   1          _nop_();
  72   1          _nop_();
  73   1          SCK=1;
  74   1          _nop_();
  75   1          DATA=1;
  76   1          _nop_();
  77   1          SCK=0;       // refer to the pdf from SENSIRION(start transmission)
  78   1      }
  79          
  80          //------------------------------------------------------------------------------
  81          void s_connectionreset(void)
  82          //------------------------------------------------------------------------------
  83          //func: communication reset:DATA-line and at least 9 sck cycles followed by transstart
  84          {
  85   1          unsigned char i;
  86   1          DATA=1;
  87   1          SCK=0;
  88   1          for(i=0;i<9;i++)
  89   1          {
  90   2              SCK=1;
  91   2              SCK=0;
  92   2          }
  93   1          s_transstart();
  94   1      }
  95          
  96          //--------------------------------------------------------------------------------
  97          char s_softreset(void)
  98          //--------------------------------------------------------------------------------
  99          //func: reset the sensor by a softreset
 100          {
 101   1          unsigned char error=0;
 102   1          s_connectionreset();        //reset communication
 103   1          error+=s_write_byte(RESET); //send RESET -command to sensor
 104   1          return error;               //sensor=1 in case of no response from sensor
 105   1      }
 106          
 107          //-----------------------------------------------------------------------------------
 108          char s_read_statusreg(unsigned char *p_value, unsigned char *p_checksum)
 109          //-----------------------------------------------------------------------------------
 110          //func: read the status register with checksum (8 bit)
 111          {
 112   1          unsigned char error=0;
 113   1          s_transstart();                     //transmission start
 114   1          error=s_write_byte(STATUS_REG_R);   //send command to sensor
 115   1          *p_value=s_read_byte(ACK);          //read status register(8 bit)
 116   1          *p_checksum=s_read_byte(noACK);     //read checksum (8 bit)
 117   1          return error;                       //error=1 in case of no response from sensor
C51 COMPILER V7.20   RW_SHT                                                                04/30/2009 12:02:11 PAGE 3   

 118   1      }
 119          
 120          //----------------------------------------------------------------------------------------
 121          char s_write_statusreg(unsigned char *p_value)
 122          //----------------------------------------------------------------------------------------
 123          //func: writes the status register with checksum(8 bit)
 124          {
 125   1          unsigned char error=0;
 126   1          s_transstart();                     //transmission start
 127   1          error+=s_write_byte(STATUS_REG_W);  //send command to sensor
 128   1          error+=s_write_byte(*p_value);      //send value of status register
 129   1          return error;                       //error >= 1 in case of no response from sensor
 130   1      }
 131          
 132          //-----------------------------------------------------------------------------------------
 133          char s_measure(unsigned char *p_value,unsigned char *p_checksum,unsigned char mode)
 134          //-----------------------------------------------------------------------------------------
 135          //func: make a measurement(temperature or humity) with checksum
 136          {
 137   1          unsigned char error=0;
 138   1          unsigned int  i;
 139   1          s_transstart();                           //start transmission
 140   1          switch(mode)                              //send command to sensor
 141   1          {
 142   2             case TEMP: error+=s_write_byte(MEASURE_TEMP);break;
 143   2             case HUMI: error+=s_write_byte(MEASURE_HUMI);break;
 144   2             default:   break;
 145   2          }
 146   1          for(i=0;i<65535;i++)
 147   1             if(DATA==0) break;
 148   1          if(DATA==1)  error+=1;
 149   1          *(p_value)=s_read_byte(ACK);      //read the first byte
 150   1          *(p_value+1) = s_read_byte(ACK);  //read the second byte
 151   1          *p_checksum = s_read_byte(noACK); //read checksum
 152   1          return error;
 153   1      }
 154          
 155          //-----------------------------------------------------------------------------------------------
 156          void calc_sth(float *p_humidity,float *p_temperature)
 157          //-----------------------------------------------------------------------------------------------
 158          //func: calculates temperature and humidity
 159          {
 160   1          const float C1=-4.0;
 161   1          const float C2=0.0405;
 162   1          const float C3=-0.0000028;
 163   1          const float T1=0.01;
 164   1          const float T2=0.00008;
 165   1          float rh=*p_humidity;
 166   1          float t=*p_temperature;
 167   1          float rh_lin;
 168   1          float rh_ture;
 169   1          float t_C;
 170   1      
 171   1          t_C=t*0.01 - 40;
 172   1          rh_lin=C3*rh*rh + C2*rh + C1;
 173   1          rh_ture=(t_C-25)*(T1+T2*rh)+rh_lin;
 174   1          if(rh_ture > 100) rh_ture=100;
 175   1          if(rh_ture < 0.1) rh_ture=0.1;
 176   1      
 177   1          *p_temperature=t_C;
 178   1          *p_humidity=rh_ture;
 179   1      }
C51 COMPILER V7.20   RW_SHT                                                                04/30/2009 12:02:11 PAGE 4   

 180          
 181          //--------------------------------------------------------------------------------------------------
 182          float calc_dewpoint(float h,float t)
 183          //----------------------------------------------------------------------------------------------------
 184          //func: calculates the dewpoint
 185          //input: humidity[%RH] , temperature[C]
 186          //output: dew point
 187          {
 188   1          float k,dew_point;
 189   1          k = (log10(h)-2)/0.4343 + (17.62*t)/(243.12+t);
 190   1          dew_point = 243.12 * k/(17.62-k);
 191   1          return dew_point;
 192   1      }
C51 COMPILER V7.20   RW_SHT                                                                04/30/2009 12:02:11 PAGE 5   

NAME                                    CLASS   MSPACE  TYPE    OFFSET  SIZE
====                                    =====   ======  ====    ======  ====


P1 . . . . . . . . . . . . . . . . . .  SFR      DATA   U_CHAR   0090H  1
P2 . . . . . . . . . . . . . . . . . .  SFR      DATA   U_CHAR   00A0H  1
_log10 . . . . . . . . . . . . . . . .  EXTERN   CODE   PROC     -----  -----
_s_read_statusreg. . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  p_value. . . . . . . . . . . . . . .  AUTO     DATA   PTR      0001H  3
  p_checksum . . . . . . . . . . . . .  AUTO     DATA   PTR      0003H  3
  error. . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0004H  1
DATA . . . . . . . . . . . . . . . . .  ABSBIT   -----  BIT      0091H  1
value. . . . . . . . . . . . . . . . .  TYPEDEF  -----  UNION    -----  4
  i. . . . . . . . . . . . . . . . . .  MEMBER   -----  U_INT    0000H  2
  f. . . . . . . . . . . . . . . . . .  MEMBER   -----  FLOAT    0000H  4
_calc_sth. . . . . . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  p_humidity . . . . . . . . . . . . .  AUTO     DATA   PTR      0000H  3
  p_temperature. . . . . . . . . . . .  AUTO     DATA   PTR      0003H  3
  C1 . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    0006H  4
  C2 . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    000AH  4
  C3 . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    000EH  4
  T1 . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    0012H  4
  T2 . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    0016H  4
  rh . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    001AH  4
  t. . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    001EH  4
  rh_lin . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    0022H  4
  rh_ture. . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    0026H  4
  t_C. . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    002AH  4
_s_measure . . . . . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  p_value. . . . . . . . . . . . . . .  AUTO     DATA   PTR      0000H  3
  p_checksum . . . . . . . . . . . . .  AUTO     DATA   PTR      0003H  3
  mode . . . . . . . . . . . . . . . .  AUTO     DATA   U_CHAR   0006H  1
  error. . . . . . . . . . . . . . . .  AUTO     DATA   U_CHAR   0007H  1
  i. . . . . . . . . . . . . . . . . .  * REG *  DATA   U_INT    0082H  2
_s_write_statusreg . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  p_value. . . . . . . . . . . . . . .  * REG *  DATA   PTR      0001H  3
  error. . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0004H  1
s_transstart . . . . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
s_connectionreset. . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  i. . . . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0007H  1
HUMI . . . . . . . . . . . . . . . . .  E_CONST  -----  U_CHAR   -----  1
TEMP . . . . . . . . . . . . . . . . .  E_CONST  -----  U_CHAR   -----  1
s_softreset. . . . . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  error. . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0004H  1
_calc_dewpoint . . . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  h. . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    0004H  4
  t. . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    0004H  4
  k. . . . . . . . . . . . . . . . . .  AUTO     DATA   FLOAT    0008H  4
  dew_point. . . . . . . . . . . . . .  * REG *  DATA   FLOAT    0004H  4
SCK. . . . . . . . . . . . . . . . . .  ABSBIT   -----  BIT      0090H  1
_s_read_byte . . . . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  ack. . . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0007H  1
  i. . . . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0005H  1
  val. . . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0006H  1
_s_write_byte. . . . . . . . . . . . .  PUBLIC   CODE   PROC     0000H  -----
  value. . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0007H  1
  i. . . . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0005H  1
  error. . . . . . . . . . . . . . . .  * REG *  DATA   U_CHAR   0006H  1


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    892    ----
C51 COMPILER V7.20   RW_SHT                                                                04/30/2009 12:02:11 PAGE 6   

   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      72
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -