Autor Tema: Higrómetro/termómetro SHT11...código  (Leído 3450 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado J1M

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 1960
Higrómetro/termómetro SHT11...código
« en: 04 de Junio de 2004, 17:53:00 »
Alguien tiene algún codigo que me sirva de guia para poder mostrar la temperatura y la humedad con este sensor.
El sensor en cuestión es digital, de la casa sensirion, aquí teneis mas info sobre el:
http://www.sensirion.com/en/sensors/humidity/sensors_devices/sensorSHT11.htm

Quiero mostrar la temperatura y humedad en un LCD de 16x2, y bueno, tengo este código, pero ando un pokiiiiiiito perdido

Codigo:

//------------------------------------------------------------------------------
// Module hygrometre-thermometre sensirion sht11
//
// adaptations JYP 2003
//
//------------------------------------------------------------------------------

#include "math.h"

typedef union
{ unsigned int i;
float f;
} value;

enum {TEMP,HUMI};

#define sht_noACK 0
#define sht_ACK 1
//adr command r/w
#define sht_STATUS_REG_W 0x06 //000 0011 0
#define sht_STATUS_REG_R 0x07 //000 0011 1
#define sht_MEASURE_TEMP 0x03 //000 0001 1
#define sht_MEASURE_HUMI 0x05 //000 0010 1
#define sht_RESET 0x1e //000 1111 0

//------------------------------------------------------------------------------
char sht11_write_byte(unsigned char value)
//------------------------------------------------------------------------------
// writes a byte on the Sensibus and checks the acknowledge
{
unsigned char i,error=0;

for (i=0x80;i>0;i/=2) //shift bit for masking
{
if (i & value)
output_high(sht11_data); //masking value with i , write to SENSI-BUS
else
output_low(sht11_data);
output_high(sht11_sck); //clk for SENSI-BUS
delay_us( 5); //pulswith approx. 5 us
output_low(sht11_sck);
}
output_high(sht11_data); //release DATA-line
output_high(sht11_sck); //clk #9 for ack
error=input(sht11_data) ; //check ack (DATA will be pulled down by SHT11)
output_low(sht11_sck);
return error; //error=1 in case of no acknowledge
}

//------------------------------------------------------------------------------
char sht11_read_byte(unsigned char ack)
//------------------------------------------------------------------------------
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
{
unsigned char i,val=0;

output_high(sht11_data); //release DATA-line
for (i=0x80;i>0;i/=2) //shift bit for masking
{
output_high(sht11_sck); //clk for SENSI-BUS
if (input(sht11_data)==1)
val=(val | i); //read bit
output_low(sht11_sck);
}
output_bit(sht11_data,!ack); //in case of "ack==1" pull down DATA-Line
output_high(sht11_sck); //clk #9 for ack
delay_us( 5); //pulswith approx. 5 us
output_low(sht11_sck);
output_high(sht11_data); //release DATA-line
return val;
}

//------------------------------------------------------------------------------
void sht11_transstart(void)
//------------------------------------------------------------------------------
// generates a transmission start
// _____ ________
// DATA: |_______|
// ___ ___
// SCK : ___| |___| |______
{
output_high(sht11_data);
output_low(sht11_sck); //Initial state
delay_us( 1);
output_high(sht11_sck);
delay_us( 1);
output_low(sht11_data);
delay_us( 1);
output_low(sht11_sck);
delay_us( 3);
output_high(sht11_sck);
delay_us( 1);
output_high(sht11_data);
delay_us( 1);
output_low(sht11_sck);
}

//------------------------------------------------------------------------------
void sht11_connectionreset(void)
//------------------------------------------------------------------------------
// communication reset: DATA-line=1 and at least 9 SCK cycles
// followed by transstart
// _____________________________________________________ ________
// DATA: |_______|
// _ _ _ _ _ _ _ _ _ ___ ___
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______
{
unsigned char i;
output_high(sht11_data);
output_low(sht11_sck); //Initial state
for(i=0;i<9;i++) //9 SCK cycles
{
output_high(sht11_sck);
output_low(sht11_sck);
}
sht11_transstart(); //transmission start
}

//------------------------------------------------------------------------------
char sht11_softreset(void)
//------------------------------------------------------------------------------
// resets the sensor by a softreset
{
unsigned char error=0;
sht11_connectionreset(); //reset communication
error+=sht11_write_byte(sht_RESET); //send RESET-command to sensor
return error; //error=1 in case of no response form the sensor
}

//------------------------------------------------------------------------------
char sht11_read_statusreg(unsigned char *p_value, unsigned char *p_checksum)
//------------------------------------------------------------------------------
// reads the status register with checksum (8-bit)
{
unsigned char error=0;
sht11_transstart(); //transmission start
error=sht11_write_byte(sht_STATUS_REG_R); //send command to sensor
*p_value=sht11_read_byte(sht_ACK); //read status register (8-bit)
*p_checksum=sht11_read_byte(sht_noACK); //read checksum (8-bit)
return error; //error=1 in case of no response form the sensor
}

//------------------------------------------------------------------------------
char sht11_write_statusreg(unsigned char *p_value)
//------------------------------------------------------------------------------
// writes the status register with checksum (8-bit)
{
unsigned char error=0;
sht11_transstart(); //transmission start
error+=sht11_write_byte(sht_STATUS_REG_W);//send command to sensor
error+=sht11_write_byte(*p_value); //send value of status register
return error; //error>=1 in case of no response form the sensor
}

//------------------------------------------------------------------------------
char sht11_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
//------------------------------------------------------------------------------
// makes a measurement (humidity/temperature) with checksum
{
unsigned error=0;
unsigned int i;

sht11_transstart(); //transmission start
switch(mode)
{ //send command to sensor
case TEMP : error+=sht11_write_byte(sht_MEASURE_TEMP); break;
case HUMI : error+=sht11_write_byte(sht_MEASURE_HUMI); break;
default : break;
}

for (i=0;i<65535;i++)
if(input(sht11_data)==0)
break; //wait until sensor has finished the measurement
if(input(sht11_data)==1)
error+=1; // or timeout (~2 sec.) is reached

*(p_value+1) =sht11_read_byte(sht_ACK); //read the first byte (MSB)
*(p_value)=sht11_read_byte(sht_ACK); //read the second byte (LSB)
*p_checksum =sht11_read_byte(sht_noACK); //read checksum
return error;
}
char sht11_measure_temp(unsigned char *p_value, unsigned char *p_checksum)
{
return sht11_measure( p_value, p_checksum, TEMP);
}
char sht11_measure_humi(unsigned char *p_value, unsigned char *p_checksum)
{
return sht11_measure( p_value, p_checksum, HUMI);
}

//------------------------------------------------------------------------------
void sth11_calc(float *p_humidity ,float *p_temperature)
//------------------------------------------------------------------------------
// calculates temperature [°C] and humidity [%RH]
// input : humi [Ticks] (12 bit)
// temp [Ticks] (14 bit)
// output: humi [%RH]
// temp [°C]
{ const float C1=-4.0; // for 12 Bit
const float C2=+0.0405; // for 12 Bit
const float C3=-0.0000028; // for 12 Bit
const float T1=+0.01; // for 14 Bit @ 5V
const float T2=+0.00008; // for 14 Bit @ 5V

float rh,t,rh_lin,rh_true,t_C;
// rh_lin: Humidity linear
// rh_true: Temperature compensated humidity
// t_C : Temperature [°C]
rh=*p_humidity; // rh: Humidity [Ticks] 12 Bit
t=*p_temperature; // t: Temperature [Ticks] 14 Bit

t_C=t*0.01 - 40; //calc. temperature from ticks to [°C]
rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH]
rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity [%RH]
if(rh_true>100)rh_true=100; //cut if the value is outside of
if(rh_true<0.1)rh_true=0.1; //the physical possible range

*p_temperature=t_C; //return temperature [°C]
*p_humidity=rh_true; //return humidity[%RH]
}

//--------------------------------------------------------------------
int sht11_calc_humid_int( int16 w_humidity)
//--------------------------------------------------------------------
{
// calcul de l"humidite en entier (sans calcul float)

int32 h1,h2;

h1 = ((int32) w_humidity) * ((int32) w_humidity);
h1 = h1 / (int32)1000;
h1 = h1 * (int32)28;
h2 = ((int32) w_humidity) * (int32)405;
h2 = h2 - h1;
h2 = h2 / (int32)1000;
h2 = h2 - (int32)40;
h2 = h2 / (int32)10;
return (h2);
}

//--------------------------------------------------------------------
int sht11_calc_temp_int( int16 w_temperature)
//--------------------------------------------------------------------
{
// calcul de la temperature en entier (sans calcul float)

int16 temp1;

temp1 = w_temperature / (int16)100;
temp1 = temp1 - (int16)40;
return (temp1);
}

//--------------------------------------------------------------------
int sht11_calc_temp_frac10( int16 w_temperature)
//--------------------------------------------------------------------
{
// calcul de la temperature en fractionnaire 0.X (sans calcul float)
// exemple si t=25.367 ° renvoie 3

int16 temp1;

temp1 = w_temperature / (int16)10;
temp1 = w_temperature - (int16)400;
temp1 = abs(temp1) - ((int16)10 * abs(sht11_calc_temp_int(w_temperature)));
return (temp1);
}

//--------------------------------------------------------------------
int sht11_calc_temp_frac100( int16 w_temperature)
//--------------------------------------------------------------------
{
// calcul de la temperature en fractionnaire 0.XX (sans calcul float)
// exemple si t=25.367 ° renvoie 36

int16 temp1;

temp1 = w_temperature - (int16)4000;
temp1 = abs(temp1) - ((int16)100 * abs(sht11_calc_temp_int(w_temperature)));
return (temp1);
}

//--------------------------------------------------------------------
float sht11_calc_dewpoint(float h,float t)
//--------------------------------------------------------------------
// calculates dew point
// input: humidity [%RH], temperature [°C]
// output: dew point [°C]
{
float logEx,dew_point;

logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
dew_point = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx);
return dew_point;
}



Gracias

Desconectado oshow

  • PIC18
  • ****
  • Mensajes: 321
RE: Higrómetro/termómetro SHT11...código
« Respuesta #1 en: 07 de Junio de 2004, 19:03:00 »
Hola, yo he adaptado el ejemplo de la web al compilador ccs,
http://www.sensirion.com/en/pdf/Sample_Code_SHT11
te lo voy a pegar aqui, pero quiero dejar claro que no lo he probado aún, solo he adaptado el codigo y lo he compilado sin problema, me gustaria probarlo, pero este mes estoy fatal de tiempo a ver si me pongo a probarlo porque tengo el sensor ahora mismo por ahi tirado.....

Me gustaría, que si consigues hacerlo funcionar comentases cual fue tu experiencia, y si no te funciona y consigues retocarlo para que rule, que comentases por aqui los cambios que has realizado para que todos tengamos el codigo.

De todos modos si no quieres usar la libreria que he adaptado, y quieres usar la "tuya", no tienes mas que fijarte en el ejemplo y asi podras adaptar las funciones....

Tambien te recomiendo que te estudies bien el datasheet, para saber muy bien como funciona, ya que puedes elegir las resoluciones de las capturas, puedes usar la funcion calentador, vamos que tiene varias opciones y es recomendable conocerlas...

Buena suerte, y espero comentarios.



Codigo:

#include <16F876A.h>
#use delay(clock=4000000)  //Oscilador de 4Mhz
#fuses XT,NOWDT,NOPROTECT


#include <libreria_sht11_trelles.c>  //funciones de escritura y lectura del registro y medida de Tª y humedad en el sht11
#include <lcd.c> //funciones para gestionar el lcd





   //declaracion de variables para la medicion del sht11
typedef union
   {  unsigned int i;
      float f;
   } valor;

///variables globales
valor humedad,temperatura;   //variables de tipo valor para almacenar tº y humedad

void main(void)
{

   unsigned char error,checksum;
   unsigned int i;

   
         //medida sensor digital
         conexion_al_reset();
         while(1)
         {        

         error=0;
         error+=medicion((unsigned char*) &humedad.i,&checksum,HUMI); //si existe algun error sera almacenado
         error+=medicion((unsigned char*) &temperatura.i,&checksum,TEMP);

         if(error!=0)
            conexion_al_reset();
         else
            {
               humedad.f=(float)humedad.i;       //casting de entero a float para la funcion calculos_sht11
               temperatura.f=(float)temperatura.i;
               calculos_sht11(&humedad.f,&temperatura.f);

               lcd_gotoxy(1,1);
               printf(lcd_putc,"Tª2:%5.1fC humi:%5.1f%%
",temperatura.f,humedad.f);


                delay_ms(600);

            }


         }


}




La liberia

Codigo:

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//       FUNCIONES PARA EL CALCULO DE HUMEDAD Y TEMPERATURA DEL SHT11
//
//       Adaptacion de Oshow del codigo de ejemplo del sensor
//          SHT11 de sensirion, realizado con el compilador KEIL para
//          un microcontrolador 8051.
//
//                   Adaptado para compilador PCW de CCS
//
//
//
//
////////////////////////////////////////////////////////////////////////////////


#bit DATOS = 0x05.2        //definicion de los bits del sht11 datos en RA2
#bit SCK = 0x05.1          //sck en RA1


//Estos defines se pueden simplificar en lugar de tener 3 parejas de defines

#define noACK 0
#define ACK 1
/*
#define CALENTADOR_ON 1
#define CALENTADOR_OFF 0

#define RESOLUCION_14_12_BITS 0
#define RESOLUCION_12_8_BITS 1
*/


//       PROTOTIPOS DE LAS FUNCIONES

char escribir_byte(unsigned char valor);
char leer_byte(unsigned char ack);
void inicializacion(void);
char reset(void);
void conexion_al_reset(void);
char leer_registro_de_estado(unsigned char *p_valor, unsigned char *p_checksum);
char escribir_registro_de_estado(unsigned char *p_valor);
char medicion(unsigned char *p_valor, unsigned char *p_checksum, unsigned char modo);
void calculos_sht11(float *p_humedad ,float *p_temperatura);
//float calculo_rocio(float h,float t);
//char calentador_sht11(byte onoff);
//char resolucion_de_capturas(byte res);


////////////////////////////////////////////////////////////////////////////////
//    Direcciones hexadecimales para escribir y leer en el sensor.
////////////////////////////////////////////////////////////////////////////////

#define STATUS_REG_W 0x06
#define STATUS_REG_R 0x07
#define MEASURE_TEMP 0x03
#define MEASURE_HUMI 0x05
#define RESET 0x1E

enum {TEMP,HUMI}; //tambien podemos hacer defines


////////////////////////////////////////////////////////////////////////////////
//    Escribe un byte en el sensor y chequear si es reconocido
////////////////////////////////////////////////////////////////////////////////
char escribir_byte(unsigned char valor)
{
   unsigned char i,error=0;

      for (i=0x80;i>0;i/=2)
         {
            if (i & valor)
              DATOS=1;
            else
               DATOS=0;
               SCK=1;

            delay_us(5);

            SCK=0;
         }

      DATOS=1;
      SCK=1;
      error=DATOS;
      SCK=0;

   return error;
}


////////////////////////////////////////////////////////////////////////////////
//    Lee un byte en el sensor y da el reconocimeinto si ack es igual a 1
////////////////////////////////////////////////////////////////////////////////
char leer_byte(unsigned char ack)
{
      unsigned char i,valor=0;

         DATOS=1;

         for (i=0x80;i>0;i/=2)
            {
               SCK=1;

               if (DATOS)
                  valor=(valor | i);
                  SCK=0;
              }

         DATOS=!ack;
         SCK=1;

         delay_us(5);

         SCK=0;
         DATOS=1;

   return valor;
}

////////////////////////////////////////////////////////////////////////////////
//Rutina de inicializacion del sensor, utilizar despues del reset.
////////////////////////////////////////////////////////////////////////////////
// Genera un comienzo de trasmision.
//       ______         _______
// DATOS:      |_______|
//            ___     ___
// SCK :  ___|   |___|   |_____
////////////////////////////////////////////////////////////////////////////////

void inicializacion(void)
{
   DATOS=1;
   SCK=0;

   delay_us(2);

   SCK=1;

   delay_us(2);

   DATOS=0;

   delay_us(2);

   SCK=0;

   delay_us(5);

   SCK=1;

   delay_us(2);

   DATOS=1;

   delay_us(2);

   SCK=0;
}

////////////////////////////////////////////////////////////////////////////////
//Reseteo del sensor; linea de datos a 1 seguido de 9 ciclos de reloj y de
//  la funcion inicializacion()
////////////////////////////////////////////////////////////////////////////////
//
//        _____________________________________________________           ________
// DATA:                                                       |_________|
//          _    _    _    _    _    _    _    _    _        _____     _____
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______|     |___|     |___
//
////////////////////////////////////////////////////////////////////////////////

void conexion_al_reset(void)
{
   unsigned char i;

   DATOS=1;
   SCK=0;

      for(i=0;i<9;i++)
         {
            SCK=1;
            delay_us(2);
            SCK=0;
            delay_us(2);
         }

   inicializacion();
}

////////////////////////////////////////////////////////////////////////////////
//       Resetea el sensor
////////////////////////////////////////////////////////////////////////////////
char soft_reset (void)
{
      unsigned char error=0;

         conexion_al_reset();
         error+=escribir_byte(RESET);

      return error;
}

////////////////////////////////////////////////////////////////////////////////
//       Lectura del registro de estado con checksum de 8 bits
////////////////////////////////////////////////////////////////////////////////

char leer_registro_de_estado(unsigned char *p_valor, unsigned char *p_checksum)
{

   unsigned char error=0;

      inicializacion();
      error=escribir_byte(STATUS_REG_R);
      *p_valor=leer_byte(ACK);
      *p_checksum=leer_byte(noACK);


   return error;
}

////////////////////////////////////////////////////////////////////////////////
//Escribimos en el registro de estado con un checksum de 8 bits
////////////////////////////////////////////////////////////////////////////////

char escribir_registro_de_estado(unsigned char *p_valor)
{
   unsigned char error=0;


         inicializacion();

         error+=escribir_byte(STATUS_REG_W);
         error+=escribir_byte(*p_valor);

   return error;
}

////////////////////////////////////////////////////////////////////////////////
// Realiza la medicion de temperatura y humedad con checksum incluido
//    Todavia no es la medicion real, se debe hacer la compensacion
////////////////////////////////////////////////////////////////////////////////

char medicion(unsigned char *p_valor, unsigned char *p_checksum, unsigned char modo)
{
   unsigned error=0;
   unsigned long i;


      inicializacion(); //transmission start


         switch(modo)
         {
            case TEMP : error+=escribir_byte(MEASURE_TEMP); break;
            case HUMI : error+=escribir_byte(MEASURE_HUMI); break;
            default : break;
         }

         for (i=0;i<65535;i++)
            if(DATOS==0)
               break;

            if(DATOS) error+=1;

            *(p_valor) =leer_byte(ACK);
            *(p_valor+1)=leer_byte(ACK);
            *p_checksum =leer_byte(noACK);


   return error;
}

////////////////////////////////////////////////////////////////////////////////
//    Calculo de la temperatura en ºC y humedad en %
//       Entrada proviniente del sensor:
//          Humedad - 12 bits (por defecto)
//          Temperatura - 14 bits (por defecto)
//       Salida hacia el LCD:
//          Humedad - RH%
//          Temperatura - ºC
////////////////////////////////////////////////////////////////////////////////

void calculos_sht11(float *p_humedad ,float *p_temperatura)
{
   const float C1=-4.0;
   const float C2= 0.0405;
   const float C3=-0.0000028;
   const float T1=0.01;
   const float T2=0.00008;
   float rh;
   float t;
   float rh_lin;
   float rh_true;
   float t_C;

   rh=*p_humedad;
   t=*p_temperatura;


      t_C=t*0.01 - 40;
      rh_lin=C3*rh*rh + C2*rh + C1;
      rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;

         if(rh_true>100)
            rh_true=100;

         if(rh_true<0.1)
            rh_true=0.1;

      *p_temperatura=t_C;
      *p_humedad=rh_true;
}



/////////////REVISAR ESTAS FUNCIONES, OJO!!!!ESTAN SIN REVISAR//////////////////
////////////////////////////////////////////////////////////////////////////////
//       Funciones que se pueden utilizar a deseo del usuario
//          Para utilizarlas, quitar los comentarios.
////////////////////////////////////////////////////////////////////////////////
//Funcion para el calculo del rocio. Para utilizarla, incluir libreria matematica
// #include <math.h> debido a que se usa un logaritmo
////////////////////////////////////////////////////////////////////////////////

/*float calculo_rocio(float h,float t)
{
   float logEx,punto_rocio ;


      logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
      punto_rocio = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx) ;

   return punto_rocio;
}


////////////////////////////////////////////////////////////////////////////////
//       Funcion para activar el calentador del sht11
//    Esta funcion activa el calentador del sensor, el sensor
//       se "autocalienta" unos 5ºC
////////////////////////////////////////////////////////////////////////////////

char calentador_sht11(byte onoff)
{
   byte valor, checksum,
   char error=0;


   conexion_al_reset();
   error += leer_registro_de_estado(&valor, &checksum);
   conexion_al_reset();

   if (!error && (((valor>>2) & 0x01) != onoff))
   {
      onoff?bit_set(valor,2):bit_clear(valor,2);
      error += escribir_registro_de_estado(&valor);
   }

   return error;
}

////////////////////////////////////////////////////////////////////////////////
//             Eleccion de resolucion en las medidas
//                Por defecto: 14 bits temepratura y 12 bits humedad
//                   Opcion:  12 bits temperatura y 8 bits humedad
////////////////////////////////////////////////////////////////////////////////

char resolucion_de_capturas(byte res)
{   //eleccion de resolucion

   byte valor, checksum;
   char error=0;

   conexion_al_reset();
   error += escribir_registro_de_estado(&valor, &checksum);
   conexion_al_reset();

   if (!error && ((valor & 0x01) != res))
   {
      res?bit_set(valor,0):bit_clear(valor,0);
      error += escribir_registro_de_estado(&valor);
   }

   return error;
}
*/






Desconectado J1M

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 1960
RE: Higrómetro/termómetro SHT11...código
« Respuesta #2 en: 08 de Junio de 2004, 08:33:00 »


Muchas gracias!!!

Yo ahora ando liado de examenes, y tengo el PFC un poco apartado, en cuanto los akabe (hayá por el 12 d Julio), me pongo de lleno con el, te comentaré resultados.

De nuevo Muchisimas Gracias

Desconectado narcosystem

  • PIC10
  • *
  • Mensajes: 32
RE: Higrómetro/termómetro SHT11...código
« Respuesta #3 en: 08 de Junio de 2004, 17:32:00 »
hola, yo tambien estoy haciendo el PFC con el sensor de sensirion.
Intentare probarlo y se rula ya lo posteo.Saludos

Desconectado narcosystem

  • PIC10
  • *
  • Mensajes: 32
RE: Higrómetro/termómetro SHT11...código
« Respuesta #4 en: 13 de Julio de 2004, 13:56:00 »
Acabo de recibir los sensores, son la caña de pequeños, del tamaño de un So-8 mas o menos. Estoy deseando probarlos.. Si alguien los ha usado me encantaria conocer sus experiencias con ellos.

Desconectado juanmi

  • PIC10
  • *
  • Mensajes: 1
Re: Higrómetro/termómetro SHT11...código
« Respuesta #5 en: 29 de Junio de 2007, 14:06:58 »
Hola
Alguien tiene el codigo para el compilador de hi-tech para el sensor sht11.
sin alguien las tienes que me las pase porfavor. un saludo

Desconectado xmorpheo

  • PIC10
  • *
  • Mensajes: 1
SHT11...código CCS
« Respuesta #6 en: 12 de Marzo de 2012, 03:43:41 »
Que hay estimados programadores, estuve tratando de acoplar el codigo de ejemplo al CCS, pero no tuve excito, asi es que me decidi por leer el datasheet y ya encaminado lo empece todo, espero les sea de utilidad,,    ojo, la humedad es la lineal y no la compensada (se explica en el datasheet), eso les afectara en temperaturas muy diferentes a 25°C, para mi proposito no importaba, imprimo en el serial el temp, humedad y punto de rocio, CRC no lo utilice aunque lo capture en una variable. Cualquier comentario o sugerencia es buena

Codigo:
/////////////////////////////////////////////////////////////////////////////////////////////////
#include <18f2620.h>
#use delay(internal=8M) 
#fuses NOMCLR   
#use rs232(baud=9600, xmit=PIN_b7)


#include <math.h>

#define nop          delay_us(1)
#define STH11_SCK    pin_a0
#define STH11_DATA   pin_a1
#define STH11_SCK_1  output_high(STH11_SCK)
#define STH11_SCK_0  output_low(STH11_SCK)
#define STH11_DATA_1 output_high(STH11_DATA)
#define STH11_DATA_0 output_low(STH11_DATA)
#define temperatura  0b00000011
#define humedad      0b00000101

void inicio_transferencia_STH11(void)
   {
   STH11_SCK_0;
   delay_us(2);
   STH11_SCK_1;
   delay_us(2);
   STH11_DATA_0;
   delay_us(2);
   STH11_SCK_0;
   delay_us(2);
   STH11_SCK_1;
   delay_us(2);
   STH11_DATA_1;
   delay_us(2);
   STH11_SCK_0;
   }

void SCK_pulso(int esperar)
{
STH11_SCK_1;
delay_us(esperar);     
STH11_SCK_0;
delay_us(esperar);
}

float leer_STH11(int modo)      // comandos temperatura o humedad
{
long valor_medido;
float valor_final;
int x, registro_h, registro_l, CRC;
inicio_transferencia_STH11();
STH11_DATA_0;   
delay_us(1);
registro_h=modo;//modo sera utilizado al final de la funcion
for(x=8;x>=1;x--)
   {
   if(shift_left(&registro_h,1,0))
      STH11_DATA_1;
   else
      STH11_DATA_0;
   STH11_SCK_1;
   delay_us(2);   
   if(x==1)
      output_float(STH11_DATA);//detectar ACK y data como entrada 
   STH11_SCK_0;
   delay_us(2);
   }   
SCK_pulso(2);
while(input(STH11_DATA)); //si falla el sensor se estancaria aqui. <-- OJO
//////empieza a lectura de datos 14 bits
SCK_pulso(2);
for(x=7;x>=1;x--)
   {
   shift_left(&registro_h,1,input(STH11_DATA));
   SCK_pulso(2); 
   }
STH11_DATA_0;//pulso ACK
SCK_pulso(2);
output_float(STH11_DATA);
delay_us(2);
for(x=8;x>=1;x--)
   {
   shift_left(&registro_l,1,input(STH11_DATA));
   SCK_pulso(2);
   }
STH11_DATA_0;//pulso ACK
SCK_pulso(2);
output_float(STH11_DATA);
delay_us(2);
//capturar el CRC
for(x=8;x>=1;x--)
   {
   shift_left(&CRC,1,input(STH11_DATA));
   SCK_pulso(2);
   }
SCK_pulso(2);
valor_medido=make16(registro_h,registro_l); 
switch(modo)
   {
   case temperatura:
      valor_final= 0.01*(float)valor_medido-40.1;
      break;
   case humedad:    //valor sin compensacion de temperatura
      valor_final= -2.0468 + 0.0367*valor_medido - 0.0000015955*valor_medido*valor_medido;
   }
return valor_final;
}

/*
float STH11_humdad_compensada( )    //sacar la variable valor medido en la funcion anterior como global para hacer funcionar esta funcion.
{
float temp, hum, humedad_calibrada;
temp = leer_STH11(temperatura);
hum= leer_STH11(humedad);
humedad_calibrada=(temp - 25)*(0.01 + 0.00008* valor_medido )+hum;
return humedad_calibrada;
}*/

float STH11_punto_rocio()
{
float temp, hum, punto_rocio,m,Tn;
temp = leer_STH11(temperatura);
hum= leer_STH11(humedad);
if(temp>=0)
   {
   m=17.62;
   Tn=243.12;
   }
else  //temperaturas bajo cero
   {
   m=22.46;
   Tn=272.62;
   }
punto_rocio= Tn*((LOG (hum/100)+m*temp/(Tn+temp))/(m-LOG(hum/100)-m*temp/(Tn+temp)));
return punto_rocio;
}

main()
{
while(1)
   {   
   printf("\r\nTemp:%f  Humedad:%f  ",leer_STH11(temperatura),leer_STH11(humedad));
   printf("punto rocio:%f  ",STH11_punto_rocio( ));
     delay_ms(1000);
   }
}