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