Rev 2910 Rev 2911
Line 6... Line 6...
6 i2c_write(0x80); // Device address 6 i2c_write(0x80); // Device address
7 i2c_write(0xFE); // Device command 7 i2c_write(0xFE); // Device command
8 i2c_stop(); // Stop condition 8 i2c_stop(); // Stop condition
9 } 9 }
10   10  
-   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
11 SHT_ 15 #define SHT25_RH8_T12 0x01
-   16 #define SHT25_RH10_T13 0x80
-   17 #define SHT25_RH11_T11 0x81
12   18  
13 unsigned int8 SHT25_setup() 19 #define SHT25_ADDR 0x80
-   20  
-   21 unsigned int8 SHT25_setup(unsigned int8 setup_reg ) // writes to status register and returns its value
14 { 22 {
15 unsigned int8 reg; 23 unsigned int8 reg;
16   24  
17 i2c_start(); // Start condition 25 i2c_start(); // Start condition
18 i2c_write(0x80); // Device address 26 i2c_write(SHT25_ADDR); // Device address
19 i2c_write(0xE7); // Device command 27 i2c_write(0xE7); // Device command
20   28  
21 i2c_start(); // Start condition 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
22 i2c_write(0x81); // Device address 36 i2c_write(SHT25_ADDR); // Device address
-   37 i2c_write(0xE7); // Write to status register
23 reg=i2c_read(0); // Device command 38 i2c_write(reg); // Device command
24 i2c_stop(); // Stop condition 39 i2c_stop(); // Stop condition
25 40  
26 return (reg); 41 return (reg);
27 } 42 }
28   43  
-   44  
29 float SHT25_get_temp() 45 float SHT25_get_temp()
30 { 46 {
31 unsigned int8 MSB, LSB, Check; 47 unsigned int8 MSB, LSB, Check;
32 unsigned int16 data; 48 unsigned int16 data;
33   49  
34 i2c_start(); 50 i2c_start();
35 I2C_Write(0x80); 51 I2C_Write(SHT25_ADDR);
36 I2C_write(0xE3); 52 I2C_write(0xE3);
37 i2c_stop(); 53 i2c_stop();
38 54
39 delay_ms(100); 55 delay_ms(100);
40 56
41 i2c_start(); 57 i2c_start();
42 I2C_Write(0x81); 58 I2C_Write(SHT25_ADDR+1);
43 MSB=i2c_read(1); 59 MSB=i2c_read(1);
44 LSB=i2c_read(1); 60 LSB=i2c_read(1);
45 Check=i2c_read(0); 61 Check=i2c_read(0);
46 i2c_stop(); 62 i2c_stop();
47 63
Line 55... Line 71...
55 { 71 {
56 unsigned int8 MSB, LSB, Check; 72 unsigned int8 MSB, LSB, Check;
57 unsigned int16 data; 73 unsigned int16 data;
58   74  
59 i2c_start(); //RH 75 i2c_start(); //RH
60 I2C_Write(0x80); 76 I2C_Write(SHT25_ADDR);
61 I2C_write(0xE5); 77 I2C_write(0xE5);
62 // i2c_stop(); 78 // i2c_stop();
63   79  
64 delay_ms(100); 80 delay_ms(100);
65   81  
66 i2c_start(); 82 i2c_start();
67 I2C_Write(0x81); 83 I2C_Write(SHT25_ADDR+1);
68 MSB=i2c_read(1); 84 MSB=i2c_read(1);
69 LSB=i2c_read(1); 85 LSB=i2c_read(1);
70 Check=i2c_read(0); 86 Check=i2c_read(0);
71 i2c_stop(); 87 i2c_stop();
72   88  
Line 79... Line 95...
79 } 95 }
80   96  
81   97  
82 void main() 98 void main()
83 { 99 {
-   100 unsigned int8 i=0;
84   101  
85 setup_adc_ports(NO_ANALOGS|VSS_VDD); 102 setup_adc_ports(NO_ANALOGS|VSS_VDD);
86 setup_adc(ADC_CLOCK_DIV_2); 103 setup_adc(ADC_CLOCK_DIV_2);
87 setup_spi(SPI_SS_DISABLED); 104 setup_spi(SPI_SS_DISABLED);
88 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); 105 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
89 setup_timer_1(T1_DISABLED); 106 setup_timer_1(T1_DISABLED);
90 setup_timer_2(T2_DISABLED,0,1); 107 setup_timer_2(T2_DISABLED,0,1);
91 setup_ccp1(CCP_OFF); 108 setup_ccp1(CCP_OFF);
92 setup_comparator(NC_NC_NC_NC); 109 setup_comparator(NC_NC_NC_NC);
93   110  
94 void SHT25_soft_reset(); 111 SHT25_soft_reset();
95 printf("SHT25 humidity and temperature sensor example \r\n",); 112 printf("SHT25 humidity and temperature sensor example \r\n",);
96 delay_ms (500); 113 delay_ms (500);
97   114  
98 while(TRUE) 115 while(TRUE)
99 { 116 {
-   117 if (i<10)
-   118 printf("setup: %X \r\n",SHT25_setup(SHT25_RH12_T14 | SHT25_HEATER_OFF));
-   119 else
-   120 {
100 printf("setup: %X \r\n",SHT25_setup()); 121 printf("setup: %X \r\n",SHT25_setup(SHT25_RH12_T14 | SHT25_HEATER_ON));
-   122 i = 0;
-   123 }
101 delay_ms (500); 124 delay_ms (500);
102 printf("Temp: %f \r\n",SHT25_get_temp()); 125 printf("Temp: %f \r\n",SHT25_get_temp());
103 delay_ms (500); 126 delay_ms (500);
104 printf("Hum: %f \r\n",SHT25_get_hum()); 127 printf("Hum: %f \r\n",SHT25_get_hum());
105 delay_ms (1000); 128 delay_ms (1000);
-   129 i++;
106 } 130 }
107 } 131 }
108   132