o: ActiveSupport::Cache::Entry :@compressedF: @value"gJ"aJ
main.bak
1 1
#include "main.h"
2
#include "SHT25.h"
2 3

  
3
void SHT25_soft_reset()
4
{
5
  i2c_start();     // Start condition
6
  i2c_write(0x80); // Device address
7
  i2c_write(0xFE);    // Device command
8
  i2c_stop();      // Stop condition
9
}
10 4

  
11
#define SHT25_HEATER_ON   0x04 
12
#define SHT25_HEATER_OFF   0x00
13
#define SHT25_OTP_reload_off  0x02
14
#define SHT25_RH12_T14  0x00
15
#define SHT25_RH8_T12  0x01
16
#define SHT25_RH10_T13  0x80
17
#define SHT25_RH11_T11  0x81
18

  
19
#define SHT25_ADDR  0x80
20

  
21
unsigned int8 SHT25_setup(unsigned int8 setup_reg )  // writes to status register and returns its value
22
{
23
unsigned int8 reg;
24

  
25
  i2c_start();     // Start condition
26
  i2c_write(SHT25_ADDR); // Device address
27
  i2c_write(0xE7);    // Device command
28

  
29
  i2c_start();     // Start condition
30
  i2c_write(SHT25_ADDR+1); // Device address
31
  reg=i2c_read(0);    // Read status actual status register
32

  
33
  reg = (reg & 0x3A) | setup_reg;
34

  
35
  i2c_start();     // Start condition
36
  i2c_write(SHT25_ADDR); // Device address
37
  i2c_write(0xE7);    // Write to status register
38
  i2c_write(reg);    // Device command
39
  i2c_stop();      // Stop condition
40

  
41
  return (reg);
42
}
43

  
44

  
45
float SHT25_get_temp()
46
{
47
unsigned int8 MSB, LSB, Check;
48
unsigned int16 data;
49

  
50
   i2c_start();
51
   I2C_Write(SHT25_ADDR);
52
   I2C_write(0xE3);
53
   i2c_stop();
54
  
55
   delay_ms(100);
56
   
57
   i2c_start();
58
   I2C_Write(SHT25_ADDR+1);
59
   MSB=i2c_read(1);
60
   LSB=i2c_read(1);
61
   Check=i2c_read(0);
62
   i2c_stop();
63
      
64
   LSB = LSB >> 2; // trow out status bits
65

  
66
   data = (((unsigned int16) MSB << 8) + (LSB << 4));
67
   return(-46.85 + 175.72*((float)data/0xFFFF));
68
}
69

  
70
float SHT25_get_hum()
71
{
72
unsigned int8 MSB, LSB, Check;
73
unsigned int16 data;
74

  
75
   i2c_start();   //RH
76
   I2C_Write(SHT25_ADDR);
77
   I2C_write(0xE5);
78
//   i2c_stop();
79

  
80
   delay_ms(100);
81

  
82
   i2c_start();
83
   I2C_Write(SHT25_ADDR+1);
84
   MSB=i2c_read(1);
85
   LSB=i2c_read(1);
86
   Check=i2c_read(0);
87
   i2c_stop(); 
88

  
89
//   printf("%X %X  %X\r\n",MSB, LSB, Check);   
90

  
91
   LSB = LSB >> 2; // trow out status bits
92

  
93
   data = (((unsigned int16) MSB << 8) + (LSB << 4) );
94
   return( -6.0 + 125.0*((float)data/0xFFFF));
95
}      
96

  
97

  
98 5
void main()
99 6
{
100
unsigned int8 i=0;
7
unsigned int8 i=0, sht_config;
101 8

  
102 9
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
103 10
   setup_adc(ADC_CLOCK_DIV_2);
......
114 21

  
115 22
  while(TRUE)
116 23
  { 
117
   if (TRUE) 
118
   printf("setup: %X \r\n",SHT25_setup(SHT25_RH12_T14 | SHT25_HEATER_OFF));
24
   if (i<10) sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; // loop alters on chip heater on and off to check correct function
119 25
   else
120 26
   {
121
      printf("setup: %X \r\n",SHT25_setup(SHT25_RH12_T14 | SHT25_HEATER_ON));
122
      i = 0;
27
      sht_config = SHT25_RH12_T14 | SHT25_HEATER_ON;
28
      if (i > 20) i = 0;
123 29
   }
30
      printf("setup: %X %X \r\n",SHT25_setup(sht_config),sht_config);
124 31
      delay_ms (500);
125 32
      printf("Temp: %f \r\n",SHT25_get_temp());      
126 33
      delay_ms (500);
:@created_atf1442617125.0789621 ·:@expires_in0