18,7 → 18,18 |
//#define sht_data_pin PIN_D0 |
//#define sht_clk_pin PIN_D1 |
|
#include <math.h> |
|
|
#define noACK 0 |
#define ACK 1 |
//adr command r/w |
#define STATUS_REG_W 0x06 //000 0011 0 |
#define STATUS_REG_R 0x07 //000 0011 1 |
#define MEASURE_TEMP 0x03 //000 0001 1 |
#define MEASURE_HUMI 0x05 //000 0010 1 |
#define RESET 0x1e //000 1111 0 |
|
//***** Function to alert SHT75 ***** |
// generates a transmission start |
// _____ ________ |
152,6 → 163,7 |
// DATA: |_______| |
// _ _ _ _ _ _ _ _ _ ___ ___ |
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ |
|
void sht_comreset (void) |
{ |
int8 i; |
179,6 → 191,17 |
delay_ms(15); //pause 15 ms |
} |
|
//---------------------------------------------------------------------------------- |
char sht_write_statusreg(unsigned char *p_value) |
//---------------------------------------------------------------------------------- |
// writes the status register with checksum (8-bit) |
{ |
unsigned char error=0; |
sht_comstart(); //transmission start |
error+=sht_comwrite(STATUS_REG_W);//send command to sensor |
error+=sht_comwrite(*p_value); //send value of status register |
return error; //error>=1 in case of no response form the sensor |
} |
|
//***** Function to measure SHT75 temperature ***** |
|
216,6 → 239,11 |
|
void calculate_data (int16 temp, int16 humid, float & tc, float & rhlin, float & rhtrue) |
{ |
const float C1=-2.0468; // for 12 Bit RH |
const float C2=+0.0367; // for 12 Bit RH |
const float C3=-0.0000015955; // for 12 Bit RH |
const float T1=+0.01; // for 12 Bit RH |
const float T2=+0.00008; // for 12 Bit RH |
float rh; |
|
//calculate temperature reading |
224,10 → 252,13 |
//calculate Real RH reading |
rh = (float) humid; |
|
rhlin = (rh * 0.0405) - (rh * rh * 0.0000028) - 4.0; |
rhlin = C1 + (rh * C2) + (rh * rh * C3); |
|
//calculate True RH reading |
rhtrue = ((tc - 25.0) * (0.01 + (0.00008 * rh))) + rhlin; |
|
if(rhtrue>99)rhtrue=100; //cut if the value is outside of |
if(rhtrue<0.1)rhtrue=0.1; //the physical possible range |
} |
|
|
252,3 → 283,17 |
sht_comreset(); //reset SHT75 |
delay_ms(20); //delay for power-up |
} |
|
//-------------------------------------------------------------------- |
float calc_dewpoint(float h,float t) |
//-------------------------------------------------------------------- |
// calculates dew point |
// input: humidity [%RH], temperature [K] |
// output: dew point [K] |
{ float k,dew_point ; |
|
k = (log10(h)-2)/0.4343 + (17.62*t)/(243.12+t); |
dew_point = 243.12*k/(17.62-k); |
return dew_point; |
} |
|