• Domingo 31 de Mayo de 2026, 02:37

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - J1M

Páginas: 1 2 [3]
51
Programación en C / Re: Higrómetro/termómetro Sht11
« en: Miércoles 18 de Agosto de 2004, 13:47 »
seriais tan amables de mandarme el codigo???

yo la parte del SHT11 la tengo un poco avandonada, ahora ando intentando visualizar el DS1307 en el LCD...


jim2k2@hotmail.com


Graciasss  :kicking:  :hola:

52
Programación en C / Re: Higrómetro/termómetro Sht11
« en: Martes 6 de Julio de 2004, 19:29 »
wel mirate esto:

http://www.ccsinfo.com/forum/viewtopic.php?t=17108


yo dejo el pfc para agosto q ahora me voy a ponerlos un poco en remojo!! :P

Salu2!

54
Programación en C / Re: Higrómetro/termómetro Sht11
« en: Lunes 14 de Junio de 2004, 23:01 »
aún no lo he probado, el autor tampoco, intenta hacer una simulación paso a paso si no consigues localizar donde está el error. En cuanto lo tenga rulando posteo aki el codigo

Salu2 ;)

55
Programación en C / Re: Higrómetro/termómetro Sht11
« en: Lunes 14 de Junio de 2004, 07:27 »
No me comunico con el PC, sino con un PIC el 16f876a, he conseguido el codigo en C para controlarlo, es de oshow (asias tiu ;))


Código: Text
  1.  
  2.  
  3. Hola, yo he adaptado el ejemplo de la web al compilador ccs,
  4. http://www.sensirion.com/en/pdf/Sample_Code_SHT11
  5. 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.....
  6.  
  7. 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.
  8.  
  9. 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....
  10.  
  11. 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...
  12.  
  13. Buena suerte, y espero comentarios.
  14.  
  15.  
  16.  
  17.  
  18. Codigo:--------------------------------------------------------------------------------
  19. #include <16F876A.h>
  20. #use delay(clock=4000000)  //Oscilador de 4Mhz
  21. #fuses XT,NOWDT,NOPROTECT
  22.  
  23.  
  24. #include <libreria_sht11_trelles.c>  //funciones de escritura y lectura del registro y medida de Tª y humedad en el sht11
  25. #include <lcd.c> //funciones para gestionar el lcd
  26.  
  27.  
  28.  
  29.  
  30.  
  31.    //declaracion de variables para la medicion del sht11
  32. typedef union
  33.    {  unsigned int i;
  34.       float f;
  35.    } valor;
  36.  
  37. ///variables globales
  38. valor humedad,temperatura;   //variables de tipo valor para almacenar tº y humedad
  39.  
  40. void main(void)
  41. {
  42.  
  43.    unsigned char error,checksum;
  44.    unsigned int i;
  45.  
  46.    
  47.          //medida sensor digital
  48.          conexion_al_reset();
  49.          while(1)
  50.          {        
  51.  
  52.          error=0;
  53.          error+=medicion((unsigned char*) &humedad.i,&checksum,HUMI); //si existe algun error sera almacenado
  54.          error+=medicion((unsigned char*) &temperatura.i,&checksum,TEMP);
  55.  
  56.          if(error!=0)
  57.             conexion_al_reset();
  58.          else
  59.             {
  60.                humedad.f=(float)humedad.i;       //casting de entero a float para la funcion calculos_sht11
  61.                temperatura.f=(float)temperatura.i;
  62.                calculos_sht11(&humedad.f,&temperatura.f);
  63.  
  64.                lcd_gotoxy(1,1);
  65.                printf(lcd_putc,"Tª2:%5.1fC humi:%5.1f%%\n",temperatura.f,humedad.f);
  66.  
  67.  
  68.                 delay_ms(600);
  69.  
  70.             }
  71.  
  72.  
  73.          }
  74.  
  75.  
  76. }
  77.  
  78. --------------------------------------------------------------------------------
  79.  
  80.  
  81. La liberia
  82.  
  83.  
  84. Codigo:--------------------------------------------------------------------------------
  85. ////////////////////////////////////////////////////////////////////////////////
  86. ////////////////////////////////////////////////////////////////////////////////
  87. //       FUNCIONES PARA EL CALCULO DE HUMEDAD Y TEMPERATURA DEL SHT11
  88. //
  89. //       Adaptacion de Oshow del codigo de ejemplo del sensor
  90. //          SHT11 de sensirion, realizado con el compilador KEIL para
  91. //          un microcontrolador 8051.
  92. //
  93. //                   Adaptado para compilador PCW de CCS
  94. //
  95. //
  96. //
  97. //
  98. ////////////////////////////////////////////////////////////////////////////////
  99.  
  100.  
  101. #bit DATOS = 0x05.2        //definicion de los bits del sht11 datos en RA2
  102. #bit SCK = 0x05.1          //sck en RA1
  103.  
  104.  
  105. //Estos defines se pueden simplificar en lugar de tener 3 parejas de defines
  106.  
  107. #define noACK 0
  108. #define ACK 1
  109. /*
  110. #define CALENTADOR_ON 1
  111. #define CALENTADOR_OFF 0
  112.  
  113. #define RESOLUCION_14_12_BITS 0
  114. #define RESOLUCION_12_8_BITS 1
  115. */
  116.  
  117.  
  118. //       PROTOTIPOS DE LAS FUNCIONES
  119.  
  120. char escribir_byte(unsigned char valor);
  121. char leer_byte(unsigned char ack);
  122. void inicializacion(void);
  123. char reset(void);
  124. void conexion_al_reset(void);
  125. char leer_registro_de_estado(unsigned char *p_valor, unsigned char *p_checksum);
  126. char escribir_registro_de_estado(unsigned char *p_valor);
  127. char medicion(unsigned char *p_valor, unsigned char *p_checksum, unsigned char modo);
  128. void calculos_sht11(float *p_humedad ,float *p_temperatura);
  129. //float calculo_rocio(float h,float t);
  130. //char calentador_sht11(byte onoff);
  131. //char resolucion_de_capturas(byte res);
  132.  
  133.  
  134. ////////////////////////////////////////////////////////////////////////////////
  135. //    Direcciones hexadecimales para escribir y leer en el sensor.
  136. ////////////////////////////////////////////////////////////////////////////////
  137.  
  138. #define STATUS_REG_W 0x06
  139. #define STATUS_REG_R 0x07
  140. #define MEASURE_TEMP 0x03
  141. #define MEASURE_HUMI 0x05
  142. #define RESET 0x1E
  143.  
  144. enum {TEMP,HUMI}; //tambien podemos hacer defines
  145.  
  146.  
  147. ////////////////////////////////////////////////////////////////////////////////
  148. //    Escribe un byte en el sensor y chequear si es reconocido
  149. ////////////////////////////////////////////////////////////////////////////////
  150. char escribir_byte(unsigned char valor)
  151. {
  152.    unsigned char i,error=0;
  153.  
  154.       for (i=0x80;i>0;i/=2)
  155.          {
  156.             if (i & valor)
  157.               DATOS=1;
  158.             else
  159.                DATOS=0;
  160.                SCK=1;
  161.  
  162.             delay_us(5);
  163.  
  164.             SCK=0;
  165.          }
  166.  
  167.       DATOS=1;
  168.       SCK=1;
  169.       error=DATOS;
  170.       SCK=0;
  171.  
  172.    return error;
  173. }
  174.  
  175.  
  176. ////////////////////////////////////////////////////////////////////////////////
  177. //    Lee un byte en el sensor y da el reconocimeinto si ack es igual a 1
  178. ////////////////////////////////////////////////////////////////////////////////
  179. char leer_byte(unsigned char ack)
  180. {
  181.       unsigned char i,valor=0;
  182.  
  183.          DATOS=1;
  184.  
  185.          for (i=0x80;i>0;i/=2)
  186.             {
  187.                SCK=1;
  188.  
  189.                if (DATOS)
  190.                   valor=(valor | i);
  191.                   SCK=0;
  192.               }
  193.  
  194.          DATOS=!ack;
  195.          SCK=1;
  196.  
  197.          delay_us(5);
  198.  
  199.          SCK=0;
  200.          DATOS=1;
  201.  
  202.    return valor;
  203. }
  204.  
  205. ////////////////////////////////////////////////////////////////////////////////
  206. //Rutina de inicializacion del sensor, utilizar despues del reset.
  207. ////////////////////////////////////////////////////////////////////////////////
  208. // Genera un comienzo de trasmision.
  209. //       ______         _______
  210. // DATOS:      |_______|
  211. //            ___     ___
  212. // SCK :  ___|   |___|   |_____
  213. ////////////////////////////////////////////////////////////////////////////////
  214.  
  215. void inicializacion(void)
  216. {
  217.    DATOS=1;
  218.    SCK=0;
  219.  
  220.    delay_us(2);
  221.  
  222.    SCK=1;
  223.  
  224.    delay_us(2);
  225.  
  226.    DATOS=0;
  227.  
  228.    delay_us(2);
  229.  
  230.    SCK=0;
  231.  
  232.    delay_us(5);
  233.  
  234.    SCK=1;
  235.  
  236.    delay_us(2);
  237.  
  238.    DATOS=1;
  239.  
  240.    delay_us(2);
  241.  
  242.    SCK=0;
  243. }
  244.  
  245. ////////////////////////////////////////////////////////////////////////////////
  246. //Reseteo del sensor; linea de datos a 1 seguido de 9 ciclos de reloj y de
  247. //  la funcion inicializacion()
  248. ////////////////////////////////////////////////////////////////////////////////
  249. //
  250. //        _____________________________________________________           ________
  251. // DATA:                                                       |_________|
  252. //          _    _    _    _    _    _    _    _    _        _____     _____
  253. // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______|     |___|     |___
  254. //
  255. ////////////////////////////////////////////////////////////////////////////////
  256.  
  257. void conexion_al_reset(void)
  258. {
  259.    unsigned char i;
  260.  
  261.    DATOS=1;
  262.    SCK=0;
  263.  
  264.       for(i=0;i<9;i++)
  265.          {
  266.             SCK=1;
  267.             delay_us(2);
  268.             SCK=0;
  269.             delay_us(2);
  270.          }
  271.  
  272.    inicializacion();
  273. }
  274.  
  275. ////////////////////////////////////////////////////////////////////////////////
  276. //       Resetea el sensor
  277. ////////////////////////////////////////////////////////////////////////////////
  278. char soft_reset (void)
  279. {
  280.       unsigned char error=0;
  281.  
  282.          conexion_al_reset();
  283.          error+=escribir_byte(RESET);
  284.  
  285.       return error;
  286. }
  287.  
  288. ////////////////////////////////////////////////////////////////////////////////
  289. //       Lectura del registro de estado con checksum de 8 bits
  290. ////////////////////////////////////////////////////////////////////////////////
  291.  
  292. char leer_registro_de_estado(unsigned char *p_valor, unsigned char *p_checksum)
  293. {
  294.  
  295.    unsigned char error=0;
  296.  
  297.       inicializacion();
  298.       error=escribir_byte(STATUS_REG_R);
  299.       *p_valor=leer_byte(ACK);
  300.       *p_checksum=leer_byte(noACK);
  301.  
  302.  
  303.    return error;
  304. }
  305.  
  306. ////////////////////////////////////////////////////////////////////////////////
  307. //Escribimos en el registro de estado con un checksum de 8 bits
  308. ////////////////////////////////////////////////////////////////////////////////
  309.  
  310. char escribir_registro_de_estado(unsigned char *p_valor)
  311. {
  312.    unsigned char error=0;
  313.  
  314.  
  315.          inicializacion();
  316.  
  317.          error+=escribir_byte(STATUS_REG_W);
  318.          error+=escribir_byte(*p_valor);
  319.  
  320.    return error;
  321. }
  322.  
  323. ////////////////////////////////////////////////////////////////////////////////
  324. // Realiza la medicion de temperatura y humedad con checksum incluido
  325. //    Todavia no es la medicion real, se debe hacer la compensacion
  326. ////////////////////////////////////////////////////////////////////////////////
  327.  
  328. char medicion(unsigned char *p_valor, unsigned char *p_checksum, unsigned char modo)
  329. {
  330.    unsigned error=0;
  331.    unsigned long i;
  332.  
  333.  
  334.       inicializacion(); //transmission start
  335.  
  336.  
  337.          switch(modo)
  338.          {
  339.             case TEMP : error+=escribir_byte(MEASURE_TEMP); break;
  340.             case HUMI : error+=escribir_byte(MEASURE_HUMI); break;
  341.             default : break;
  342.          }
  343.  
  344.          for (i=0;i<65535;i++)
  345.             if(DATOS==0)
  346.                break;
  347.  
  348.             if(DATOS) error+=1;
  349.  
  350.             *(p_valor) =leer_byte(ACK);
  351.             *(p_valor+1)=leer_byte(ACK);
  352.             *p_checksum =leer_byte(noACK);
  353.  
  354.  
  355.    return error;
  356. }
  357.  
  358. ////////////////////////////////////////////////////////////////////////////////
  359. //    Calculo de la temperatura en ºC y humedad en %
  360. //       Entrada proviniente del sensor:
  361. //          Humedad - 12 bits (por defecto)
  362. //          Temperatura - 14 bits (por defecto)
  363. //       Salida hacia el LCD:
  364. //          Humedad - RH%
  365. //          Temperatura - ºC
  366. ////////////////////////////////////////////////////////////////////////////////
  367.  
  368. void calculos_sht11(float *p_humedad ,float *p_temperatura)
  369. {
  370.    const float C1=-4.0;
  371.    const float C2= 0.0405;
  372.    const float C3=-0.0000028;
  373.    const float T1=0.01;
  374.    const float T2=0.00008;
  375.    float rh;
  376.    float t;
  377.    float rh_lin;
  378.    float rh_true;
  379.    float t_C;
  380.  
  381.    rh=*p_humedad;
  382.    t=*p_temperatura;
  383.  
  384.  
  385.       t_C=t*0.01 - 40;
  386.       rh_lin=C3*rh*rh + C2*rh + C1;
  387.       rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;
  388.  
  389.          if(rh_true>100)
  390.             rh_true=100;
  391.  
  392.          if(rh_true<0.1)
  393.             rh_true=0.1;
  394.  
  395.       *p_temperatura=t_C;
  396.       *p_humedad=rh_true;
  397. }
  398.  
  399.  
  400.  
  401. /////////////REVISAR ESTAS FUNCIONES, OJO!!!!ESTAN SIN REVISAR//////////////////
  402. ////////////////////////////////////////////////////////////////////////////////
  403. //       Funciones que se pueden utilizar a deseo del usuario
  404. //          Para utilizarlas, quitar los comentarios.
  405. ////////////////////////////////////////////////////////////////////////////////
  406. //Funcion para el calculo del rocio. Para utilizarla, incluir libreria matematica
  407. // #include <math.h> debido a que se usa un logaritmo
  408. ////////////////////////////////////////////////////////////////////////////////
  409.  
  410. /*float calculo_rocio(float h,float t)
  411. {
  412.    float logEx,punto_rocio&#59;
  413.  
  414.  
  415.       logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
  416.       punto_rocio = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx)&#59;
  417.  
  418.    return punto_rocio;
  419. }
  420.  
  421.  
  422. ////////////////////////////////////////////////////////////////////////////////
  423. //       Funcion para activar el calentador del sht11
  424. //    Esta funcion activa el calentador del sensor, el sensor
  425. //       se "autocalienta" unos 5ºC
  426. ////////////////////////////////////////////////////////////////////////////////
  427.  
  428. char calentador_sht11(byte onoff)
  429. {
  430.   byte valor, checksum,
  431.    char error=0;
  432.  
  433.  
  434.   conexion_al_reset();
  435.   error += leer_registro_de_estado(&valor, &checksum);
  436.   conexion_al_reset();
  437.  
  438.   if (!error && (((valor>>2) & 0x01) != onoff))
  439.    {
  440.     onoff?bit_set(valor,2):bit_clear(valor,2);
  441.     error += escribir_registro_de_estado(&valor);
  442.   }
  443.  
  444.   return error;
  445. }
  446.  
  447. ////////////////////////////////////////////////////////////////////////////////
  448. //             Eleccion de resolucion en las medidas
  449. //                Por defecto: 14 bits temepratura y 12 bits humedad
  450. //                   Opcion:  12 bits temperatura y 8 bits humedad
  451. ////////////////////////////////////////////////////////////////////////////////
  452.  
  453. char resolucion_de_capturas(byte res)
  454. {  //eleccion de resolucion
  455.  
  456.   byte valor, checksum;
  457.    char error=0;
  458.  
  459.   conexion_al_reset();
  460.   error += escribir_registro_de_estado(&valor, &checksum);
  461.   conexion_al_reset();
  462.  
  463.   if (!error && ((valor & 0x01) != res))
  464.    {
  465.     res?bit_set(valor,0):bit_clear(valor,0);
  466.     error += escribir_registro_de_estado(&valor);
  467.   }
  468.  
  469.   return error;
  470. }
  471. */
  472.  
  473. --------------------------------------------------------------------------------
  474.  
  475.  
  476.  
  477.  

56
Programación en C / Re: Higrómetro/termómetro Sht11
« en: Sábado 5 de Junio de 2004, 15:53 »
El tema es que aún no me he puesto a programarlo, quería saber si ya alguien habia hecho algo similar con este sensor y tenia x ahí el codigo, espero poder empezar a programarlo en unos dias.

Salu2! :beer:

57
Programación en C / Higrómetro/termómetro Sht11
« en: Sábado 5 de Junio de 2004, 13:31 »
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/humidi...sensorSHT11.htm

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

Código: Text
  1.  
  2. //------------------------------------------------------------------------------
  3. // Module hygrometre-thermometre sensirion sht11
  4. //
  5. // adaptations JYP 2003
  6. //
  7. //------------------------------------------------------------------------------
  8.  
  9. #include "math.h"
  10.  
  11. typedef union
  12. { unsigned int i;
  13. float f;
  14. } value;
  15.  
  16. enum {TEMP,HUMI};
  17.  
  18. #define sht_noACK 0
  19. #define sht_ACK 1
  20. //adr command r/w
  21. #define sht_STATUS_REG_W 0x06 //000 0011 0
  22. #define sht_STATUS_REG_R 0x07 //000 0011 1
  23. #define sht_MEASURE_TEMP 0x03 //000 0001 1
  24. #define sht_MEASURE_HUMI 0x05 //000 0010 1
  25. #define sht_RESET 0x1e //000 1111 0
  26.  
  27. //------------------------------------------------------------------------------
  28. char sht11_write_byte(unsigned char value)
  29. //------------------------------------------------------------------------------
  30. // writes a byte on the Sensibus and checks the acknowledge
  31. {
  32. unsigned char i,error=0;
  33.  
  34. for (i=0x80;i>0;i/=2) //shift bit for masking
  35. {
  36. if (i & value)
  37. output_high(sht11_data); //masking value with i , write to SENSI-BUS
  38. else
  39. output_low(sht11_data);
  40. output_high(sht11_sck); //clk for SENSI-BUS
  41. delay_us( 5); //pulswith approx. 5 us
  42. output_low(sht11_sck);
  43. }
  44. output_high(sht11_data); //release DATA-line
  45. output_high(sht11_sck); //clk #9 for ack
  46. error=input(sht11_data)&#59; //check ack (DATA will be pulled down by SHT11)
  47. output_low(sht11_sck);
  48. return error; //error=1 in case of no acknowledge
  49. }
  50.  
  51. //------------------------------------------------------------------------------
  52. char sht11_read_byte(unsigned char ack)
  53. //------------------------------------------------------------------------------
  54. // reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
  55. {
  56. unsigned char i,val=0;
  57.  
  58. output_high(sht11_data); //release DATA-line
  59. for (i=0x80;i>0;i/=2) //shift bit for masking
  60. {
  61. output_high(sht11_sck); //clk for SENSI-BUS
  62. if (input(sht11_data)==1)
  63. val=(val | i); //read bit
  64. output_low(sht11_sck);
  65. }
  66. output_bit(sht11_data,!ack); //in case of "ack==1" pull down DATA-Line
  67. output_high(sht11_sck); //clk #9 for ack
  68. delay_us( 5); //pulswith approx. 5 us
  69. output_low(sht11_sck);
  70. output_high(sht11_data); //release DATA-line
  71. return val;
  72. }
  73.  
  74. //------------------------------------------------------------------------------
  75. void sht11_transstart(void)
  76. //------------------------------------------------------------------------------
  77. // generates a transmission start
  78. // _____ ________
  79. // DATA: |_______|
  80. // ___ ___
  81. // SCK : ___| |___| |______
  82. {
  83. output_high(sht11_data);
  84. output_low(sht11_sck); //Initial state
  85. delay_us( 1);
  86. output_high(sht11_sck);
  87. delay_us( 1);
  88. output_low(sht11_data);
  89. delay_us( 1);
  90. output_low(sht11_sck);
  91. delay_us( 3);
  92. output_high(sht11_sck);
  93. delay_us( 1);
  94. output_high(sht11_data);
  95. delay_us( 1);
  96. output_low(sht11_sck);
  97. }
  98.  
  99. //------------------------------------------------------------------------------
  100. void sht11_connectionreset(void)
  101. //------------------------------------------------------------------------------
  102. // communication reset: DATA-line=1 and at least 9 SCK cycles
  103. // followed by transstart
  104. // _____________________________________________________ ________
  105. // DATA: |_______|
  106. // _ _ _ _ _ _ _ _ _ ___ ___
  107. // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______
  108. {
  109. unsigned char i;
  110. output_high(sht11_data);
  111. output_low(sht11_sck); //Initial state
  112. for(i=0;i<9;i++) //9 SCK cycles
  113. {
  114. output_high(sht11_sck);
  115. output_low(sht11_sck);
  116. }
  117. sht11_transstart(); //transmission start
  118. }
  119.  
  120. //------------------------------------------------------------------------------
  121. char sht11_softreset(void)
  122. //------------------------------------------------------------------------------
  123. // resets the sensor by a softreset
  124. {
  125. unsigned char error=0;
  126. sht11_connectionreset(); //reset communication
  127. error+=sht11_write_byte(sht_RESET); //send RESET-command to sensor
  128. return error; //error=1 in case of no response form the sensor
  129. }
  130.  
  131. //------------------------------------------------------------------------------
  132. char sht11_read_statusreg(unsigned char *p_value, unsigned char *p_checksum)
  133. //------------------------------------------------------------------------------
  134. // reads the status register with checksum (8-bit)
  135. {
  136. unsigned char error=0;
  137. sht11_transstart(); //transmission start
  138. error=sht11_write_byte(sht_STATUS_REG_R); //send command to sensor
  139. *p_value=sht11_read_byte(sht_ACK); //read status register (8-bit)
  140. *p_checksum=sht11_read_byte(sht_noACK); //read checksum (8-bit)
  141. return error; //error=1 in case of no response form the sensor
  142. }
  143.  
  144. //------------------------------------------------------------------------------
  145. char sht11_write_statusreg(unsigned char *p_value)
  146. //------------------------------------------------------------------------------
  147. // writes the status register with checksum (8-bit)
  148. {
  149. unsigned char error=0;
  150. sht11_transstart(); //transmission start
  151. error+=sht11_write_byte(sht_STATUS_REG_W);//send command to sensor
  152. error+=sht11_write_byte(*p_value); //send value of status register
  153. return error; //error>=1 in case of no response form the sensor
  154. }
  155.  
  156. //------------------------------------------------------------------------------
  157. char sht11_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
  158. //------------------------------------------------------------------------------
  159. // makes a measurement (humidity/temperature) with checksum
  160. {
  161. unsigned error=0;
  162. unsigned int i;
  163.  
  164. sht11_transstart(); //transmission start
  165. switch(mode)
  166. { //send command to sensor
  167. case TEMP : error+=sht11_write_byte(sht_MEASURE_TEMP); break;
  168. case HUMI : error+=sht11_write_byte(sht_MEASURE_HUMI); break;
  169. default : break;
  170. }
  171.  
  172. for (i=0;i<65535;i++)
  173. if(input(sht11_data)==0)
  174. break; //wait until sensor has finished the measurement
  175. if(input(sht11_data)==1)
  176. error+=1; // or timeout (~2 sec.) is reached
  177.  
  178. *(p_value+1) =sht11_read_byte(sht_ACK); //read the first byte (MSB)
  179. *(p_value)=sht11_read_byte(sht_ACK); //read the second byte (LSB)
  180. *p_checksum =sht11_read_byte(sht_noACK); //read checksum
  181. return error;
  182. }
  183. char sht11_measure_temp(unsigned char *p_value, unsigned char *p_checksum)
  184. {
  185. return sht11_measure( p_value, p_checksum, TEMP);
  186. }
  187. char sht11_measure_humi(unsigned char *p_value, unsigned char *p_checksum)
  188. {
  189. return sht11_measure( p_value, p_checksum, HUMI);
  190. }
  191.  
  192. //------------------------------------------------------------------------------
  193. void sth11_calc(float *p_humidity ,float *p_temperature)
  194. //------------------------------------------------------------------------------
  195. // calculates temperature [°C] and humidity [%RH]
  196. // input : humi [Ticks] (12 bit)
  197. // temp [Ticks] (14 bit)
  198. // output: humi [%RH]
  199. // temp [°C]
  200. { const float C1=-4.0; // for 12 Bit
  201. const float C2=+0.0405; // for 12 Bit
  202. const float C3=-0.0000028; // for 12 Bit
  203. const float T1=+0.01; // for 14 Bit @ 5V
  204. const float T2=+0.00008; // for 14 Bit @ 5V
  205.  
  206. float rh,t,rh_lin,rh_true,t_C;
  207. // rh_lin: Humidity linear
  208. // rh_true: Temperature compensated humidity
  209. // t_C : Temperature [°C]
  210. rh=*p_humidity; // rh: Humidity [Ticks] 12 Bit
  211. t=*p_temperature; // t: Temperature [Ticks] 14 Bit
  212.  
  213. t_C=t*0.01 - 40; //calc. temperature from ticks to [°C]
  214. rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH]
  215. rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity [%RH]
  216. if(rh_true>100)rh_true=100; //cut if the value is outside of
  217. if(rh_true<0.1)rh_true=0.1; //the physical possible range
  218.  
  219. *p_temperature=t_C; //return temperature [°C]
  220. *p_humidity=rh_true; //return humidity[%RH]
  221. }
  222.  
  223. //--------------------------------------------------------------------
  224. int sht11_calc_humid_int( int16 w_humidity)
  225. //--------------------------------------------------------------------
  226. {
  227. // calcul de l'humidite en entier (sans calcul float)
  228.  
  229. int32 h1,h2;
  230.  
  231. h1 = ((int32) w_humidity) * ((int32) w_humidity);
  232. h1 = h1 / (int32)1000;
  233. h1 = h1 * (int32)28;
  234. h2 = ((int32) w_humidity) * (int32)405;
  235. h2 = h2 - h1;
  236. h2 = h2 / (int32)1000;
  237. h2 = h2 - (int32)40;
  238. h2 = h2 / (int32)10;
  239. return (h2);
  240. }
  241.  
  242. //--------------------------------------------------------------------
  243. int sht11_calc_temp_int( int16 w_temperature)
  244. //--------------------------------------------------------------------
  245. {
  246. // calcul de la temperature en entier (sans calcul float)
  247.  
  248. int16 temp1;
  249.  
  250. temp1 = w_temperature / (int16)100;
  251. temp1 = temp1 - (int16)40;
  252. return (temp1);
  253. }
  254.  
  255. //--------------------------------------------------------------------
  256. int sht11_calc_temp_frac10( int16 w_temperature)
  257. //--------------------------------------------------------------------
  258. {
  259. // calcul de la temperature en fractionnaire 0.X (sans calcul float)
  260. // exemple si t=25.367 ° renvoie 3
  261.  
  262. int16 temp1;
  263.  
  264. temp1 = w_temperature / (int16)10;
  265. temp1 = w_temperature - (int16)400;
  266. temp1 = abs(temp1) - ((int16)10 * abs(sht11_calc_temp_int(w_temperature)));
  267. return (temp1);
  268. }
  269.  
  270. //--------------------------------------------------------------------
  271. int sht11_calc_temp_frac100( int16 w_temperature)
  272. //--------------------------------------------------------------------
  273. {
  274. // calcul de la temperature en fractionnaire 0.XX (sans calcul float)
  275. // exemple si t=25.367 ° renvoie 36
  276.  
  277. int16 temp1;
  278.  
  279. temp1 = w_temperature - (int16)4000;
  280. temp1 = abs(temp1) - ((int16)100 * abs(sht11_calc_temp_int(w_temperature)));
  281. return (temp1);
  282. }
  283.  
  284. //--------------------------------------------------------------------
  285. float sht11_calc_dewpoint(float h,float t)
  286. //--------------------------------------------------------------------
  287. // calculates dew point
  288. // input: humidity [%RH], temperature [°C]
  289. // output: dew point [°C]
  290. {
  291. float logEx,dew_point;
  292.  
  293. logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
  294. dew_point = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx);
  295. return dew_point;
  296. }
  297.  
  298.  

Gracias ;)

58
Microcontroladores / Re: Realizacion De Un Frecuencimetro
« en: Sábado 5 de Junio de 2004, 13:29 »
jr. eres de la politécnica de cartagena?? pq la practica final es la misma. te dejo aki la mia, sirvió para un 10 asiq estará bien :P

te adjunto tb el .asm que he visto que esto sale deformado, para q lo abras con el mplab

Salu2!

Código: Text
  1.  
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ;;;;;                                            &#59;;;;;
  5. ;;;;;                    FRECUENCÍMETRO                  &#59;;;;;
  6. ;;;;;                       POR                    &#59;;;;;
  7. ;;;;;                JAIME FERNÁNDEZ-CARO BELMONTE              &#59;;;;;
  8. ;;;;;                                            &#59;;;;;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ;;;;;;;;;                                        &#59;;;;;;;;;
  12. ;;;;;;;;;  Realizado con MPLAB IDE 6.32                        &#59;;;;;;;;;
  13. ;;;;;;;;;  Simulado con Proteus Pro 6.2 SP5                      &#59;;;;;;;;;
  14. ;;;;;;;;;  Montaje en MicroPicTrainer 1.1                        &#59;;;;;;;;;
  15. ;;;;;;;;;                                        &#59;;;;;;;;;
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18.  
  19.         LIST P=16F84    &#59;Tipo de PIC usado
  20.  
  21.     ORG    00      &#59;Directiva inicio de programa en la posición 00
  22.  
  23. INICIO  BSF     0x03,5    &#59;Ponemos a '1' el bit 5(6ª posición) del registro de Estado
  24.         CLRF    0x06    &#59;Ahora estamos en el banco 1, ponemos a '0'(Salida) TrisB
  25.         MOVLW   0xFF    &#59;Copiamos el literal 'FF'H a W, todo 1 (Entrada)
  26.         MOVWF   0x05    &#59;Copiamos de W al registro TrisA, quedando como entrada
  27.     MOVLW   B'11101000'  &#59;Copiamos el literal de configuración del registro Option a W
  28.     MOVWF   0x01    &#59;Copiamos el contenido de W a Option
  29.         BCF     0x03,5    &#59;Ponemos a '0' el bit 5 del registro de Estado,estamos en el Banco 0
  30.     CLRF  0x06    &#59;Borramos el contenido del registro PortB
  31.     CLRF  0x01    &#59;Borramos el contenido del registro TMR0
  32.  
  33. ;Retrasamos acontinuación la ejecución
  34. ;del programa durante 1 segundo
  35.  
  36.     MOVLW  D'40'    &#59;Copiamos el literal (decimal) a W
  37.         MOVWF   0x0C    &#59;Copiamos el contenido de W a la 1ª posición de memoria libre
  38. LOOP1  MOVLW  D'80'    &#59;Copiamos el literal (decimal) a W
  39.         MOVWF   0x0D    &#59;Copiamos el contenido de W a la 2ª posición de memoria libre
  40. LOOP2  MOVLW  D'103'    &#59;Copiamos el literal (decimal) a W
  41.         MOVWF   0x0E    &#59;Copiamos el contenido de W a la 3ª posición de memoria libre
  42. LOOP3  DECFSZ  0x0E,1    &#59;Decrementamos 0x0E,y se almacena en 0x0E,si es 0 brincamos
  43.         GOTO    LOOP3    &#59;Como no es 0,hacemos un salto incondicional a LOOP3
  44.         DECFSZ  0x0D,1    &#59;Decrementamos 0x0D,y se almacena en 0x0D,si es 0 brincamos
  45.         GOTO    LOOP2    &#59;Como no es 0,hacemos un salto incondicional a LOOP2
  46.         DECFSZ  0x0C,1    &#59;Decrementamos 0x0C,y se almacena en 0x0C,si es 0 brincamos
  47.         GOTO    LOOP1    &#59;Como no es 0,hacemos un salto incondicional a LOOP1
  48.  
  49. ;Movemos el valor del registro TMR0 a una variable
  50. ;para poder operar con él
  51.  
  52.     MOVF    0x01,0    &#59;Copiamos el contenido del registro TMR0 en W
  53.         MOVWF   0x0C    &#59;Movemos el valor de W a la posicion 0x0C
  54.  
  55. ;Descomposición de un número en centenas,decenas y unidades
  56. ;Explicación del algoritmo en la memoria de la practica
  57.  
  58. CENTEN  MOVLW  D'100'    &#59;Movemos el literal (decimal) a W
  59.     SUBWF  0x0C,0    &#59;Restamos W a 0x0C y guardamos el resultado en W
  60.     BTFSS  0x03,0    &#59;Miramos el bit 0 del registro de Estado, si es 1 brincamos
  61.     GOTO  DECEN    &#59;Salto incondicional a DECEN, ya que hay acarreo
  62.     MOVWF  0x0C    &#59;Guardamos el resto para seguir restando
  63.     INCF  0x0E,1    &#59;Incrementamos la variable 0x0E,y guardamos el resultado en ella
  64.     GOTO  CENTEN    &#59;Salto incondicional a CENTEN
  65.  
  66. DECEN  MOVLW  D'10'    &#59;Movemos el literal (decimal) a W
  67.     SUBWF  0x0C,0    &#59;Restamos W a 0x0C y guardamos el resultado en W
  68.     BTFSS  0x03,0    &#59;Miramos el bit 0 del registro de Estado, si es 1 brincamos
  69.     GOTO  WAIT    &#59;Salto incondicional a WAIT, ya que hay acarreo
  70.     MOVWF  0x0C    &#59;Guardamos el resto para seguir restando
  71.     INCF  0x0D,1    &#59;Incrementamos la variable 0x0D,y guardamos el resultado en ella
  72.     GOTO  DECEN    &#59;Salto incondicional a DECEN
  73.  
  74. ;Esperamos a que se active cualquiera
  75. ;de los pulsadores
  76.  
  77. WAIT  BTFSC  0x05,0    &#59;Miramos el bit 0 del registro PortA, y si (RA0) es 0 brinca
  78.     CALL  MUE_CEN    &#59;Llamada a Subrutina MUE_CEN ya que RA0 es 1
  79.     BTFSC  0x05,1    &#59;Miramos el bit 1 del registro PortA, y si (RA1) es 0 brinca
  80.     CALL  MUE_DEC    &#59;Llamada a Subrutina MUE_DEC ya que RA1 es 1
  81.     BTFSC  0x05,2    &#59;Miramos el bit 2 del registro PortA, y si (RA2) es 0 brinca
  82.     CALL  MUE_UNI    &#59;Llamada a Subrutina MUE_UNI ya que RA2 es 1
  83.     BTFSC  0x05,3    &#59;Miramos el bit 3 del registro PortA, y si (RA3) es 0 brinca
  84.     GOTO  INICIO    &#59;Salto incondicional a INICIO ya que RA3 es 1
  85.     GOTO  WAIT    &#59;Salto incondicional a WAIT ya que RA3 es 0
  86.    
  87. ;Rutina encargada de mostrar en el display
  88. ;centenas,decenas ó unidades
  89.  
  90. MUE_CEN  MOVF  0x0E,0    &#59;Copio el valor de la posicion de memoria 0x0E en W
  91.     CALL  MUESTRA    &#59;Llamo a la subrutina MUESTRA
  92.     RETURN        &#59;Retorno a WAIT desde esta subrutina
  93.  
  94. MUE_DEC  MOVF  0x0D,0    &#59;Copio el valor de la posicion de memoria 0x0D en W
  95.     CALL  MUESTRA    &#59;Llamo a la subrutina MUESTRA
  96.     RETURN        &#59;Retorno a WAIT desde esta subrutina
  97.  
  98. MUE_UNI  MOVF  0x0C,0    &#59;Copio el valor de la posicion de memoria 0x0C en W
  99.     CALL  MUESTRA    &#59;Llamo a la subrutina MUESTRA
  100.     RETURN        &#59;Retorno a WAIT desde esta subrutina
  101.  
  102. MUESTRA CALL  N_7SEG    &#59;Llamo a la subrutina N_7SEG
  103.     MOVWF  0x06    &#59;Copio el contenido de W en PortB
  104.     RETURN        &#59;Retorno desde subrutina
  105.  
  106. ;Rutina encargada de dar
  107. ;el equivalente en 7 segmentos de un numero
  108.  
  109. N_7SEG  ADDWF  0x02,1    &#59;Sumo el valor de W con el del PCL,y lo almaceno en PCL
  110.     RETLW  B'00111111'  &#59;Retorno desde subrutina y W=Valor del 0 en 7 segmentos
  111.     RETLW  B'00000110'  &#59;Retorno desde subrutina y W=Valor del 1 en 7 segmentos
  112.     RETLW  B'01011011'  &#59;Retorno desde subrutina y W=Valor del 2 en 7 segmentos
  113.     RETLW  B'01001111'  &#59;Retorno desde subrutina y W=Valor del 3 en 7 segmentos
  114.     RETLW  B'01100110'  &#59;Retorno desde subrutina y W=Valor del 4 en 7 segmentos
  115.     RETLW  B'01101101'  &#59;Retorno desde subrutina y W=Valor del 5 en 7 segmentos
  116.     RETLW  B'01111101'  &#59;Retorno desde subrutina y W=Valor del 6 en 7 segmentos
  117.     RETLW  B'00000111'  &#59;Retorno desde subrutina y W=Valor del 7 en 7 segmentos
  118.     RETLW  B'01111111'  &#59;Retorno desde subrutina y W=Valor del 8 en 7 segmentos
  119.     RETLW  B'01100111'  &#59;Retorno desde subrutina y W=Valor del 9 en 7 segmentos
  120.  
  121.         END          &#59;Directiva fin de programa
  122.  
  123. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  124. ;;            &#59;;
  125. ;;  Total: 68 Instrucciones&#59;;
  126. ;;            &#59;;
  127. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  128.  
  129.  

Páginas: 1 2 [3]