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

📄 sht7i.lst

📁 sht71瑞士公司生产的用来测量温湿度的芯片
💻 LST
📖 第 1 页 / 共 5 页
字号:
 264            return error;                     //error=1 in case of no response form the sensor
 265          }
 266          */
 267          
 268          
 269          /*
 270          //----------------------------------------------------------------------------------
 271          char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
 272          //----------------------------------------------------------------------------------
 273          // makes a measurement (humidity/temperature) with checksum
 274          { 
 275            unsigned error=0;
 276            unsigned int i;
 277          
 278            s_transstart();                   //transmission start
 279            switch(mode){                     //send command to sensor
 280              case TEMP	: error+=s_write_byte(MEASURE_TEMP); break;
 281              case HUMI	: error+=s_write_byte(MEASURE_HUMI); break;
 282              default     : break;	 
 283            }
 284            for (i=0;i<65535;i++) if(DATA==0) break; //wait until sensor has finished the measurement
 285            if(DATA) error+=1;                // or timeout (~2 sec.) is reached
 286            *(p_value)  =s_read_byte(ACK);    //read the first byte (MSB)
 287            *(p_value+1)=s_read_byte(ACK);    //read the second byte (LSB)
 288            *p_checksum =s_read_byte(noACK);  //read checksum
 289            Prints("MSB=");
 290              Puthexbyte(*p_value);
 291              Prints("\r\n");
 292              Prints("LSB=");
 293              Puthexbyte(*(p_value+1));
 294              Prints("\r\n");
 295          
 296              return error;
 297          }
 298          */
 299          
 300          //----------------------------------------------------------------------------------
 301          char s_humi(uchar *p_value, uchar *p_checksum)
 302          //----------------------------------------------------------------------------------
 303          // reads the status register with checksum (8-bit)
C51 COMPILER V3.96,  SN-83203013  SHT7I                                                    06/22/05  10:35:56  PAGE 6   

 304          { 
 305   1      	
 306   1        uchar error=0;
 307   1        uint i;
 308   1        s_transstart();                   //transmission start
 309   1        error=s_write_byte(MEASURE_HUMI); //send messure huminity command to sensor
 310   1        for (i=0;i<65535;i++) if(DATA==0) break; //wait until sensor has finished the measurement
 311   1        if(DATA) error+=1;                // or timeout (~2 sec.) is reached
 312   1        *(p_value)  =s_read_byte(ACK);    //read the first byte  (MSB)
 313   1        *(p_value+1)=s_read_byte(ACK);    //read the second byte (LSB)
 314   1        *p_checksum=s_read_byte(noACK);   //read checksum (8-bit) 
 315   1      //    Prints("\r\n");
 316   1      //    Prints("humi=");
 317   1      //    Puthexbyte(*p_value);
 318   1      //    Puthexbyte(*(p_value+1));
 319   1      //    Prints("\r\n"); 
 320   1          
 321   1        return error;                     //error=1 in case of no response form the sensor
 322   1      }
 323          
 324          
 325          //----------------------------------------------------------------------------------
 326          char s_temp(uchar *p_value, uchar *p_checksum)
 327          //----------------------------------------------------------------------------------
 328          // reads the status register with checksum (8-bit)
 329          { 
 330   1      	unsigned int tt;
 331   1        unsigned char t;
 332   1        uchar error=0;
 333   1        uint i;
 334   1        s_transstart();                   //transmission start
 335   1        error=s_write_byte(MEASURE_TEMP); //send messure tempture command to sensor
 336   1        for (i=0;i<65535;i++) if(DATA==0) break; //wait until sensor has finished the measurement
 337   1        if(DATA) error+=1;                // or timeout (~2 sec.) is reached
 338   1        *(p_value)  =s_read_byte(ACK);    //read the first byte  (MSB)
 339   1        *(p_value+1)=s_read_byte(ACK);    //read the second byte (LSB)
 340   1        *p_checksum=s_read_byte(noACK);   //read checksum (8-bit) 
 341   1      //    Prints("temp=");
 342   1      //    Puthexbyte(*p_value);
 343   1      //    Puthexbyte(*(p_value+1));
 344   1      //    Prints("\r\n");
 345   1      //    tt=*((unsigned int *)p_value);
 346   1      //    tt=(tt/100-40);
 347   1      //    t=(tt%100);
 348   1      //    Puthexbyte(tt); 
 349   1      //    Putchar('.');
 350   1      //    Puthexbyte(t); 
 351   1      //    Prints("\r\n");
 352   1          return error;                   //error=1 in case of no response form the sensor
 353   1      }
 354          
 355          
 356          //----------------------------------------------------------------------------------------
 357          void calc_sth11(float *p_humidity ,float *p_temperature)
 358          //----------------------------------------------------------------------------------------
 359          // calculates temperature  and humidity [%RH] 
 360          // input :  humi [Ticks] (12 bit) 
 361          //          temp [Ticks] (14 bit)
 362          // output:  humi [%RH]
 363          //          temp 
 364          { const float C1=-4.0;               // for 12 Bit
 365   1        const float C2=+0.0405;            // for 12 Bit
C51 COMPILER V3.96,  SN-83203013  SHT7I                                                    06/22/05  10:35:56  PAGE 7   

 366   1        const float C3=-0.0000028;         // for 12 Bit
 367   1        const float T11=+0.01;             // for 14 Bit @ 5V
 368   1        const float T22=+0.00008;          // for 14 Bit @ 5V	
 369   1      
 370   1        float rh=*p_humidity;             // rh:      Humidity [Ticks] 12 Bit 
 371   1        float t=*p_temperature;           // t:       Temperature [Ticks] 14 Bit
 372   1        float rh_lin;                     // rh_lin:  Humidity linear
 373   1        float rh_true;                    // rh_true: Temperature compensated humidity
 374   1        float t_C;                        // t_C   :  Temperature 
 375   1      
 376   1        t_C=t*0.01 - 40;                  //calc. temperature from ticks to
 377   1         printf("temp:%f\n",t_C);
 378   1         Prints("\r\n");
 379   1        rh_lin=C3*rh*rh + C2*rh + C1;     //calc. humidity from ticks to [%RH]
 380   1        rh_true=(t_C-25)*(T11+T22*rh)+rh_lin;   //calc. temperature compensated humidity [%RH]
 381   1        if(rh_true>100)rh_true=100;       //cut if the value is outside of
 382   1        if(rh_true<0.1)rh_true=0.1;       //the physical possible range
 383   1         printf("%humi:%f\n",rh_true);
 384   1         Prints("\r\n");
 385   1        *p_temperature=t_C;               //return temperature 
 386   1        *p_humidity=rh_true;              //return humidity[%RH]
 387   1      }
 388          
 389          
 390          /*
 391          //--------------------------------------------------------------------
 392          float calc_dewpoint(float h,float t)
 393          //--------------------------------------------------------------------
 394          // calculates dew point
 395          // input:   humidity [%RH], temperature
 396          // output:  dew point 
 397          { float logEx,dew_point;
 398            logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
 399            dew_point = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx);
 400            return dew_point;
 401          }
 402          */
 403          
 404          void main()
 405          { 
 406   1      
 407   1        value humi_val,temp_val;
 408   1       // float dew_point;
 409   1       
 410   1      //  char temp,humi;
 411   1        uchar error,checksum;
 412   1      //  uchar statusreg=0x01;
 413   1      //  uchar status=0;
 414   1        float f =0.02;
 415   1        unsigned int i;
 416   1        for(i=0;i<1000;i++);
 417   1        InitialIO();
 418   1        InitialUart();
 419   1        //Prints("Initial is over\r\n");
 420   1        //s_connectionreset();
 421   1      
 422   1        while(1)                     //调试用程序,试验证明可对寄存器的读取操作;
 423   1         {                            //证明硬件电路没有问题;
 424   2           
 425   2      //    error=0;
 426   2      //    f=f*0.01 - 40;  
 427   2      //    Putchar('a');
C51 COMPILER V3.96,  SN-83203013  SHT7I                                                    06/22/05  10:35:56  PAGE 8   

 428   2      //f=f*0.01*f - 40*f*f;                //calc. temperature from ticks to 
 429   2        //rh_lin=C3*rh*rh + C2*rh + C1;     //calc. humidity from ticks to [%RH]
 430   2           //printf("temp:%f\n",f);
 431   2      //    error+=s_softreset();
 432   2      //    Prints("error=");
 433   2      //    Puthexbyte(error);
 434   2      //    Prints("\r\n");
 435   2      //  error+= s_write_statusreg( &statusreg);
 436   2      //   Prints("error=");
 437   2      //   Puthexbyte(error);
 438   2      //   Prints("\r\n");
 439   2      //  error+= s_read_statusreg( &status,&checksum);
 440   2      //   Prints("error=");
 441   2      //   Puthexbyte(error);
 442   2      //   Prints("\r\n");
 443   2           error+=s_humi((unsigned char*) &humi_val,&checksum);      //measure humidity
 444   2           error+=s_temp((unsigned char*) &temp_val,&checksum);      //measure temperature
 445   2        
 446   2      
 447   2           if(error!=0) s_connectionreset();         //in case of an error: connection reset
 448   2           else
 449   2           {
 450   3          	 
 451   3      
 452   3              humi_val.f=(float)humi_val.i;            //converts integer to float
 453   3              temp_val.f=(float)temp_val.i;            //converts integer to float
 454   3              calc_sth11(&humi_val.f,&temp_val.f);     //calculate humidity, temperature
 455   3              
 456   3            }    
 457   2          }
 458   1      }
 459          
 460          /*  s_connectionreset();
 461            while(1)
 462            { 
 463              error=0;
 464          //  error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  
 465              error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  
 466          //    error+=s_softreset();
 467          //    Prints("error=");
 468          //    Puthexbyte(error);
 469          //    Prints("\r\n");
 470              if(error!=0) s_connectionreset();                 //in case of an error: connection reset
 471              else
 472              { 
 473                humi_val.f=(float)humi_val.i;                 //converts integer to float
 474                temp_val.f=(float)temp_val.i;                   //converts integer to float
 475                calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature
 476               // dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
 477               // printf("temp:%5.1fC humi:%5.1f%% dew point:%5.1fC\n",temp_val.f,humi_val.f,dew_point);
 478              }
 479              //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------      
 480             // for (i=0;i<40000;i++);     //(be sure that the compiler doesn't eliminate this line!)
 481              //-----------------------------------------------------------------------------------                 
             -      
 482            
 483           // }
 484          }*/ 
C51 COMPILER V3.96,  SN-83203013  SHT7I                                                    06/22/05  10:35:56  PAGE 9   

ASSEMBLY LISTING OF GENERATED OBJECT CODE


             ; FUNCTION _Puthexbyte (BEGIN)
0000 8F00    R     MOV     ch,R7
                                           ; SOURCE LINE # 49
                                           ; SOURCE LINE # 50
                                           ; SOURCE LINE # 52
0002 E500    R     MOV     A,ch
0004 C4            SWAP    A
0005 540F          ANL     A,#0FH
0007 F500    R     MOV     i,A
                                           ; SOURCE LINE # 53
0009 D3            SETB    C
000A 9409          SUBB    A,#09H
000C 500A          JNC     ?C0001
000E E500    R     MOV     A,i
0010 2430          ADD     A,#030H
0012 FF            MOV     R7,A
0013 120000  R     LCALL   _Putchar
0016 8008          SJMP    ?C0002
0018         ?C0001:
                                           ; SOURCE LINE # 54
0018 E500    R     MOV     A,i
001A 2437          ADD     A,#037H
001C FF            MOV     R7,A
001D 120000  R     LCALL   _Putchar
0020         ?C0002:
                                           ; SOURCE LINE # 55
0020 E500    R     MOV     A,ch
0022 540F          ANL     A,#0FH
0024 F500    R     MOV     i,A
                                           ; SOURCE LINE # 56
0026 D3            SETB    C
0027 9409          SUBB    A,#09H
0029 5009          JNC     ?C0003
002B E500    R     MOV     A,i
002D 2430          ADD     A,#030H
002F FF            MOV     R7,A
0030 120000  R     LCALL   _Putchar
0033 22            RET     
0034         ?C0003:
                                           ; SOURCE LINE # 57
0034 E500    R     MOV     A,i
0036 2437          ADD     A,#037H
0038 FF            MOV     R7,A
0039 120000  R     LCALL   _Putchar
                                           ; SOURCE LINE # 58
003C         ?C0005:
003C 22            RET     

⌨️ 快捷键说明

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