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

📄 sht10.lst

📁 温湿度变送器程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   SHT10                                                                 02/20/2009 14:03:13 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE SHT10
OBJECT MODULE PLACED IN SHT10.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE SHT10.C ROM(SMALL) OPTIMIZE(0,SPEED) BROWSE ORDER DEBUG OBJECTEXTEND

line level    source

   1          
   2          
   3          
   4          #include "cdltwk.h"
   5          
   6          
   7          
   8          bit rht_flag=0;
   9          bit sht_dam_flag=0;             //=1, 温湿度传感器损坏标志
  10          bit shtbit_flag=0;              //=1, 湿度8位分辨率, 温度12位分辨率
  11                                          //=0, 湿度12位分辨率,温度14位分辨率
  12          
  13          
  14          int out_temp=250;                 //室外温度
  15          int out_rh=0;                   //室外湿度
  16          int wb_rh=0;                    //做过温度补偿的室外湿度
  17          
  18          int uint_rht=0;                //从SHT10读出的温湿度整型数
  19          uchar wait_code=0;              //=0, 空闲状态
  20                                          //=1, 下一周期准备启动温度采集
  21                                          //=2, 等待温度转换结束
  22                                          //=3, 下一周期准备启动湿度采集
  23                                          //=4, 等待湿度转换结束
  24          int tempp;
  25          uchar temp[6]={0x20,0x20,0x20,0x20,0x20,0x20};
  26          uchar rh[6]={0x20,0x20,0x20,0x20,0x20,0x20};
  27          
  28          void temp_order();
  29          void rh_order();
  30          void sht10_statr();
  31          bit write_sht10(uchar dt);
  32          void rdsht10_state();
  33          void sht10_samp();
  34          void uart_send_byte(uchar udata);
  35          void uart_send1(uchar *send_buf,uchar n);
  36          //---------------------------------------------------------------
  37          //filename : void sht10_statr()
  38          //功    能 : 发送 SHT_10 起始位
  39          //           当SCK 时钟高电平时DATA 翻转为低电平,紧接着SCK变为
  40          //           低电平,随后是在SCK 时钟高电平时DATA 翻转为高电平
  41          //---------------------------------------------------------------
  42          //
  43          void sht10_statr()
  44          {
  45   1          sdat=1;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
  46   1          sclk=1;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
  47   1          sdat=0;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
  48   1          sclk=0;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
  49   1          sclk=1;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
  50   1          sdat=1;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
  51   1          sclk=0;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
  52   1      }
  53          //
  54          //---------------------------------------------------------------
  55          //filename : write_sht10(uchar dt)
C51 COMPILER V7.50   SHT10                                                                 02/20/2009 14:03:13 PAGE 2   

  56          //功    能 : 向SHT10发送1个字节的数据, 发送是高位在前,低位在后
  57          //           在发送完最低位后等待SHT10的应答信号,如果SHT10正确
  58          //           收到命令,会把数据线拉低
  59          //
  60          //           在CPU发出第8个sclk时钟的下降沿之后,SHT10将sdat下拉
  61          //           为低电平,在CPU发出第9个sclk时钟的下降沿之后,SHT10
  62          //           将释放sdat(恢复高电平)
  63          //
  64          //返回数据 : 0 无应答
  65          //           1 有应答
  66          //---------------------------------------------------------------
  67          //
  68          
  69          bit write_sht10(uchar dt)
  70          {
  71   1          uchar i;
  72   1      
  73   1          for(i=0;i<8;i++){sclk=0; sdat=(bit)(dt&0x80); dt<<= 1; sclk=1;}//发送数据
  74   1          sclk=0;_nop_();_nop_();_nop_();_nop_(); sdat=1;_nop_();_nop_();_nop_();
  75   1          i=240;
  76   1          while(i)         //等待SHT10的应答信号
  77   1          {   if(!sdat)    //检测到SHT10的应答信号
  78   2              {   sclk=1; _nop_();_nop_();_nop_(); sclk=0;_nop_();_nop_();
  79   3                  sht_dam_flag=0;  //温湿度传感器正常标志
  80   3      
  81   3                  return(1);
  82   3              }
  83   2              --i;
  84   2          }
  85   1          sht_dam_flag=1;  //温湿度传感器损坏标志
  86   1          return(0);       //没有检测到SHT10的应答信号
  87   1      }
  88          
  89          //
  90          //-------------------------------------------------------------------
  91          //filename : read_sht10()
  92          //功    能 : 从SHT10中读出1个字节的数据, 读出顺序是高位在前,低位在后
  93          //           CPU在收到SHT10发出的最低位(LSB)后,通过保持确认位ack高电
  94          //           平,来中止通讯(就是保持sdat为高电平)
  95          //-------------------------------------------------------------------
  96          //
  97          void read_sht10()
  98          {
  99   1          uchar i,j;
 100   1          for(i=0;i<8;i++)
 101   1          {   sclk=1;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
 102   2              j<<=1; j|=sdat;
 103   2              sclk=0;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
 104   2          }
 105   1          sdat=0;  sclk=1;     //发出1个字节的确认信号
 106   1          _nop_(); _nop_(); _nop_();
 107   1          sclk=0;  sdat=1;
 108   1          uint_rht=j;
 109   1          uint_rht = uint_rht << 8;
 110   1      
 111   1          j = 0;
 112   1          for(i=0;i<8;i++)
 113   1          {   sclk=1;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
 114   2              j<<=1; j|=sdat;
 115   2              sclk=0;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
 116   2          }
 117   1          uint_rht+=j;
C51 COMPILER V7.50   SHT10                                                                 02/20/2009 14:03:13 PAGE 3   

 118   1      }
 119          //
 120          //-------------------------------------------------------------------
 121          //filename : rdsht10_state()
 122          //功    能 : 读SHT10状态寄存器,判断SHT10分辨率
 123          //-------------------------------------------------------------------
 124          /*
 125          void rdsht10_state()
 126          {
 127              uchar i,j;
 128              i=80;
 129              while(i)
 130              {   sht10_statr();
 131                  if(write_sht10(0x07))   //收到应答信号
 132                  {   for(i=0;i<8;i++)
 133                      {   sclk=1;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
 134                          j<<=1; j|=sdat;
 135                          sclk=0;  _nop_(); _nop_(); _nop_();_nop_();_nop_();_nop_();
 136                      }
 137                      shtbit_flag=(bit)(j&0x01);
 138                      return;
 139                  }
 140                  else --i;
 141              }
 142              sht_dam_flag=1; //温湿度传感器损坏标志
 143          }
 144          
 145          

⌨️ 快捷键说明

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