Rev 2836 Rev 2837
Line 16... Line 16...
16 /////////////////////////////////////////////////////////////////////////////// 16 ///////////////////////////////////////////////////////////////////////////////
17   17  
18 //#define sht_data_pin PIN_D0 18 //#define sht_data_pin PIN_D0
19 //#define sht_clk_pin PIN_D1 19 //#define sht_clk_pin PIN_D1
20   20  
-   21 #include <math.h>
-   22  
-   23  
-   24 #define noACK 0
-   25 #define ACK 1
-   26 //adr command r/w
-   27 #define STATUS_REG_W 0x06 //000 0011 0
-   28 #define STATUS_REG_R 0x07 //000 0011 1
-   29 #define MEASURE_TEMP 0x03 //000 0001 1
-   30 #define MEASURE_HUMI 0x05 //000 0010 1
-   31 #define RESET 0x1e //000 1111 0
21   32  
22 //***** Function to alert SHT75 ***** 33 //***** Function to alert SHT75 *****
23 // generates a transmission start 34 // generates a transmission start
24 // _____ ________ 35 // _____ ________
25 // DATA: |_______| 36 // DATA: |_______|
Line 150... Line 161...
150 // communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart 161 // communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart
151 // _____________________________________________________ ________ 162 // _____________________________________________________ ________
152 // DATA: |_______| 163 // DATA: |_______|
153 // _ _ _ _ _ _ _ _ _ ___ ___ 164 // _ _ _ _ _ _ _ _ _ ___ ___
154 // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ 165 // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______
-   166  
155 void sht_comreset (void) 167 void sht_comreset (void)
156 { 168 {
157 int8 i; 169 int8 i;
158   170  
159 output_float(sht_data_pin); //data high 171 output_float(sht_data_pin); //data high
Line 177... Line 189...
177 sht_comreset(); //SHT75 communication reset 189 sht_comreset(); //SHT75 communication reset
178 sht_comwrite(0x1e); //send SHT75 reset command 190 sht_comwrite(0x1e); //send SHT75 reset command
179 delay_ms(15); //pause 15 ms 191 delay_ms(15); //pause 15 ms
180 } 192 }
181   193  
-   194 //----------------------------------------------------------------------------------
-   195 char sht_write_statusreg(unsigned char *p_value)
-   196 //----------------------------------------------------------------------------------
-   197 // writes the status register with checksum (8-bit)
-   198 {
-   199 unsigned char error=0;
-   200 sht_comstart(); //transmission start
-   201 error+=sht_comwrite(STATUS_REG_W);//send command to sensor
-   202 error+=sht_comwrite(*p_value); //send value of status register
-   203 return error; //error>=1 in case of no response form the sensor
-   204 }
182   205  
183 //***** Function to measure SHT75 temperature ***** 206 //***** Function to measure SHT75 temperature *****
184   207  
185 int16 sht_measuretemp (void) 208 int16 sht_measuretemp (void)
186 { 209 {
Line 214... Line 237...
214   237  
215 //***** Function to calculate SHT75 temp & RH ***** 238 //***** Function to calculate SHT75 temp & RH *****
216   239  
217 void calculate_data (int16 temp, int16 humid, float & tc, float & rhlin, float & rhtrue) 240 void calculate_data (int16 temp, int16 humid, float & tc, float & rhlin, float & rhtrue)
218 { 241 {
-   242 const float C1=-2.0468; // for 12 Bit RH
-   243 const float C2=+0.0367; // for 12 Bit RH
-   244 const float C3=-0.0000015955; // for 12 Bit RH
-   245 const float T1=+0.01; // for 12 Bit RH
-   246 const float T2=+0.00008; // for 12 Bit RH
219 float rh; 247 float rh;
220   248  
221 //calculate temperature reading 249 //calculate temperature reading
222 tc = ((float) temp * 0.01) - 40.0; 250 tc = ((float) temp * 0.01) - 40.0;
223   251  
224 //calculate Real RH reading 252 //calculate Real RH reading
225 rh = (float) humid; 253 rh = (float) humid;
226   254  
227 rhlin = (rh * 0.0405) - (rh * rh * 0.0000028) - 4.0; 255 rhlin = C1 + (rh * C2) + (rh * rh * C3);
228   256  
229 //calculate True RH reading 257 //calculate True RH reading
230 rhtrue = ((tc - 25.0) * (0.01 + (0.00008 * rh))) + rhlin; 258 rhtrue = ((tc - 25.0) * (0.01 + (0.00008 * rh))) + rhlin;
-   259
-   260 if(rhtrue>99)rhtrue=100; //cut if the value is outside of
-   261 if(rhtrue<0.1)rhtrue=0.1; //the physical possible range
231 } 262 }
232   263  
233   264  
234 //***** Function to measure & calculate SHT75 temp & RH ***** 265 //***** Function to measure & calculate SHT75 temp & RH *****
235   266  
Line 250... Line 281...
250 void sht_init (void) 281 void sht_init (void)
251 { 282 {
252 sht_comreset(); //reset SHT75 283 sht_comreset(); //reset SHT75
253 delay_ms(20); //delay for power-up 284 delay_ms(20); //delay for power-up
254 } 285 }
-   286  
-   287 //--------------------------------------------------------------------
-   288 float calc_dewpoint(float h,float t)
-   289 //--------------------------------------------------------------------
-   290 // calculates dew point
-   291 // input: humidity [%RH], temperature [K]
-   292 // output: dew point [K]
-   293 { float k,dew_point ;
-   294
-   295 k = (log10(h)-2)/0.4343 + (17.62*t)/(243.12+t);
-   296 dew_point = 243.12*k/(17.62-k);
-   297 return dew_point;
-   298 }
-   299