📄 sht10.lst
字号:
146 */
147 //---------------------------------------------------------------
148 //filename : read_temp()
149 //功 能 : 向SHT10发送1个字节的数据, 发送是高位在前,低位在后
150 // 在发送完最低位后等待SHT10的应答信号,如果SHT10正确
151 // 收到命令,会把数据线拉低
152 //
153 // 在CPU发出第8个sclk时钟的下降沿之后,SHT10将sdat下拉
154 // 为低电平,在CPU发出第9个sclk时钟的下降沿之后,SHT10
155 // 将释放sdat(恢复高电平)
156 //
157 //返回数据 : 0 无应答
158 // 1 有应答
159 //---------------------------------------------------------------
160 //
161 //=1, 下一周期准备启动温度采集
162 //=2, 等待温度转换结束
163 //=3, 下一周期准备启动湿度采集
164 //=4, 等待湿度转换结束
165
166 void temp_order()
167 {
168 1 uchar i=10;
169 1 read_sht_flag=0;
170 1 LED = 1;
171 1
172 1 while(i)
173 1 { sht10_statr();
174 2 if(write_sht10(0x03)){wait_code=2;return;}//等待温度转换结束
175 2 else --i;
176 2 }
177 1 wait_code=3; //温度转换命令失败,准备启动湿度转换
178 1 }
179
C51 COMPILER V7.50 SHT10 02/20/2009 14:03:13 PAGE 4
180 void rh_order()
181 {
182 1 uchar i=10;
183 1 read_sht_flag=0;
184 1 LED = 1;
185 1 while(i)
186 1 { sht10_statr();
187 2 if(write_sht10(0x05)){wait_code=4;return;}//等待湿度转换结束
188 2 else --i;
189 2 }
190 1 wait_code=1; //湿度转换命令失败,准备启动温度转换
191 1 }
192
193 void sht10_samp()
194 {
195 1 //uint k;
196 1 if(wait_code==0||wait_code>4)wait_code=1;
197 1 if(wait_code==1){if(read_sht_flag)temp_order();}
198 1 else if(wait_code==3){if(read_sht_flag)rh_order();}
199 1 else
200 1 { if(!sdat)
201 2 { read_sht10();
202 3 if(wait_code==2)
203 3 { /*temp[0]=uint_rht/1000 + 0X30; //原值
204 4 temp[1]=uint_rht/100%10 + 0X30;
205 4 temp[2]=uint_rht/10%10 + 0X30;
206 4 temp[3]=uint_rht%10 + 0X30;
207 4 uart_send1(temp,5);*/
208 4 out_temp=uint_rht/10-400;//温度在-20度-70度有效
209 4 mach_t();
210 4 wait_code=3;
211 4
212 4 /*temp[0]=out_temp/100%10 + 0X30; //温度值
213 4 temp[1]=out_temp/10%10 + 0X30;
214 4 temp[2]= 0x2e;
215 4 temp[3]=out_temp%10 + 0X30;
216 4 uart_send1(temp,5);*/
217 4
218 4 /*tempp = (out_temp + 200)*32/75 + 96; //电压值
219 4 temp[0]=tempp/100 + 0X30;
220 4 temp[1]= 0x2e;
221 4 temp[2]=tempp/10%10 + 0X30;
222 4 temp[3]=tempp%10 + 0X30;
223 4 uart_send1(temp,5);*/
224 4 /*temp[0]=out_temp/1000 + 0X30;
225 4 temp[1]=out_temp/100%10 + 0X30;
226 4 temp[2]=out_temp/10%10 + 0X30;
227 4 temp[3]=out_temp%10 + 0X30;
228 4 uart_send1(temp,4);*/
229 4 }
230 3 else
231 3 { /*temp[0]=uint_rht/1000 + 0X30; //原值
232 4 temp[1]=uint_rht/100%10 + 0X30;
233 4 temp[2]=uint_rht/10%10 + 0X30;
234 4 temp[3]=uint_rht%10 + 0X30;
235 4 uart_send1(temp,5);*/
236 4 out_rh=(ulong)uint_rht*81/200-(ulong)uint_rht*(ulong)uint_rht*7/250000-40;
237 4 mach_rh();
238 4 /*k=uint_rht/125+1;
239 4 if(out_temp>250)k=(k*(out_temp-250))/1000+out_rh;
240 4 else wb_rh=out_rh-(k*(250-out_temp))/1000;*/
241 4 wait_code=1;
C51 COMPILER V7.50 SHT10 02/20/2009 14:03:13 PAGE 5
242 4
243 4 /*rh[0]=out_rh/100%10 + 0X30; //湿度值
244 4 rh[1]=out_rh/10%10 + 0X30;
245 4 rh[2]= 0x2e;
246 4 rh[3]=out_rh%10 + 0X30;
247 4 uart_send1(rh,5);*/
248 4 /*rh[0]=out_rh/1000 + 0X30;
249 4 rh[1]=out_rh/100%10 + 0X30;
250 4 rh[2]=out_rh/10%10 + 0X30;
251 4 rh[3]=out_rh%10 + 0X30;
252 4 uart_send1(rh,4);*/
253 4 }
254 3 }
255 2 }
256 1 }
257 /*******************************************************************************
258 函数名称:uart_send_byte()
259 功能:串口发送函数
260 函数参数:data:发送的数据
261 ******************************************************************************
262 void uart_send_byte(uchar udata)
263 {
264 TI = 0; // 清零串口发送中断标志
265 SBUF = udata;
266 while (TI == 0);
267 TI = 0; // 清零串口发送中断标志
268 }*/
269 /*******************************************************************************
270 函数名称:uart_send()
271 功能:串口发送函数
272 函数参数:*send_buf:发送的数据
273 n:数据个数
274 ******************************************************************************
275 void uart_send1(uchar *send_buf,uchar n)
276 {
277 while (n--)
278 {
279 uart_send_byte(*send_buf);
280 send_buf++;
281 }
282 }*/
283
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 517 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 29 ----
IDATA SIZE = ---- ----
BIT SIZE = 3 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -