C51 COMPILER V7.09   SHTXX_DUMMY_CODE                                                      07/03/2006 11:00:03 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE SHTXX_DUMMY_CODE
OBJECT MODULE PLACED IN SHTxx_dummy_code.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE SHTxx_dummy_code.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*
   2          **********************************************************************************************************
             -*********
   3          *                                                               SHT10 sensor demonstration program, test on dummy data
   4          * Description:  This program tests calc_sht10() funtionality for precision against the original
   5          *                               sht11 demo program (V2.05) released by Sensirion.
   6          *                               ORIGINAL, floating point math:
   7          *                               void calc_sth11(float *p_humidity ,float *p_temperature)
   8          *                               NOW, 2*linear results:
   9          *                               void calc_sht10(unsigned int *p_humidity ,int *p_temperature)
  10          *                               Computation results calculated by floating point method is compared against 2*linear results
  11          *                               in an EXCEL file.
  12          *                               Use either Docklight or Serial Window #1 by Ctrl+F5 Debug session
  13          * File:                 SHTxx_dummy_code.c
  14          * Software:             Keil C (C51) compiler, Eval version 7.09 under uVision2 IDE v2.40
  15          * Programmer:   John Leung, TechToys Co. (www.TechToys.com.hk)
  16          * Hardware:             AT89S52-gLCD-STK1
  17          * Date:                 30th May 2006
  18          * Version:              1.0
  19          **********************************************************************************************************
             -*********
  20          */
  21          
  22          #include <REGX52.h>             //Microcontroller specific library, e.g. port definitions
  23          #include <stdio.h>              //Keil library
  24          #include <math.h>
  25          
  26          //----------------------------------------------------------------------------------
  27          void init_uart()
  28          //----------------------------------------------------------------------------------
  29          //9600 bps @ 11.059 MHz 
  30          {SCON  = 0x52;    
  31   1       TMOD  = 0x20;    
  32   1       TCON  = 0x69;    
  33   1       TH1   = 0xfd;    
  34   1      }
  35          
  36          //See an application note Non-linearity Compensation from www.Sensirion.com for details
  37          //----------------------------------------------------------------------------------------
  38          void calc_sht10(unsigned int *p_humidity ,int *p_temperature)
  39          //----------------------------------------------------------------------------------------
  40          // calculates temperature [Deg Cel] and humidity [%RH] 
  41          // input :  humi [Ticks] (12 bit) 
  42          //          temp [Ticks] (14 bit)
  43          // output:  humi [10x %RH] for 1 decimal place
  44          //          temp [100x Deg Cel] for 2 decimal places
  45          { 
  46   1              unsigned int rh = *p_humidity;
  47   1              int t   = *p_temperature;
  48   1              int t_C;
  49   1              unsigned int rh_lin;
  50   1      
  51   1              //t_C=t*0.01-40
  52   1              //multiplied by 100, t_C=t-4000
  53   1              t_C = t - 4000;
C51 COMPILER V7.09   SHTXX_DUMMY_CODE                                                      07/03/2006 11:00:03 PAGE 2   

  54   1      
  55   1              //58<=rh<=1720,         (1430*rh-5120*16)/4096,         in x10
  56   1              //1721<=rh<=3273,       (1110*rh+28930*16)/4096,        in x10
  57   1              //From : Application Note Non-Linearity compensation, Sensirion
  58   1              if(rh<=1720)
  59   1              {
  60   2                      rh_lin=(1430UL*(long)rh)>>12;
  61   2                      (rh_lin>=20)?(rh_lin = rh_lin-20):(rh_lin=0);
  62   2              } 
  63   1              else
  64   1              {
  65   2                      //rh_lin = (1110*rh + 12320 + 4096*110)/4096, in x10
  66   2                      rh_lin=((1110UL*(long)rh+12320UL)>>12)+110;
  67   2                      if(rh_lin>1000) rh_lin=1000;
  68   2              }
  69   1      
  70   1              //rh_true = (t_C-25)*(rh*0.00008+0.01)+rh_lin
  71   1              //~0.12 %RH /deg C, this factor has been ignored at this moment
  72   1              *p_temperature = t_C;
  73   1              *p_humidity = rh_lin;
  74   1      }
  75          
  76          
  77          //----------------------------------------------------------------------------------
  78          void main()
  79          //----------------------------------------------------------------------------------
  80          // Sample program that shows how to use calc_sht10() function
  81          // 1. input 12 bit values for humi_val, its is dummy data for RH
  82          // 2. calculate humidity [10x %RH]
  83          // 3. print humidity value in one decimal place
  84          // 4. input 14 bit values for temp_val, it is dummy data for testing
  85          // 5. calculate temperature [100x Deg Cel]
  86          // 6. print temperature value in two decimal places
  87          // 7. use either Docklight or Serial Window #1 by Ctrl+F5 Debug session
  88          
  89          { unsigned int  humi_val;
  90   1        int                   temp_val;
  91   1        unsigned int  raw_data;
  92   1      
  93   1        init_uart();
  94   1      
  95   1              //test on humidity, 12-bit range
  96   1              for(raw_data=100;raw_data<3400;raw_data+=100)
  97   1              {
  98   2                      humi_val=raw_data;
  99   2                      calc_sht10(&humi_val, &temp_val);
 100   2                      printf("raw_data: %d humidity: %d.%u \n", raw_data, humi_val/10, humi_val%10);
 101   2              }
 102   1        
 103   1              printf("BREAK \n");
 104   1      
 105   1              //test on temperature, 14-bit range
 106   1              for(raw_data=0;raw_data<16384;raw_data+=406)
 107   1              {
 108   2                      temp_val=raw_data;
 109   2                      calc_sht10(&humi_val, &temp_val);
 110   2                      printf("raw_data: %d temp: %d.%u\n", raw_data, temp_val/100, abs(temp_val)%100/10);
 111   2              }
 112   1      
 113   1              while(1);
 114   1      }

C51 COMPILER V7.09   SHTXX_DUMMY_CODE                                                      07/03/2006 11:00:03 PAGE 3   


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    413    ----
   CONSTANT SIZE    =     65    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      18
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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