📄 stc5410_ad.lst
字号:
186 *Modify:
187 *************************************************************/
188 void TempDelay (uchar us)
189 {
190 1 uchar uss=us;
191 1 uint i;
192 1 for(i=0;i<10;i++)
193 1 {
194 2 while(--us);
195 2 us=uss;
196 2 }
197 1 }
198
199
200 /************************************************************
201 *Function:18B20初始化
202 *parameter:
203 *Return:
204 *Modify:
205 *************************************************************/
206 void Init18b20_A ()
207 {
208 1
209 1 tem_A=1;
210 1 TempDelay(1);
211 1 tem_A=0;
212 1 TempDelay(242); //delay 530 uS//80
213 1
214 1 tem_A=1;
215 1 TempDelay(42); //delay 49 uS//7
216 1
217 1 if(tem_A==0)
218 1 flag = 1; //detect 1820 success!
219 1 else
220 1 flag = 0; //detect 1820 fail!
221 1 TempDelay(20); //20
222 1 tem_A = 1;
223 1
224 1 }
225
226 /************************************************************
227 *Function:向18B20写入一个字节
228 *parameter:
229 *Return:
230 *Modify:
231 *************************************************************/
232 void WriteByte_A (uchar wr) //单字节写入
233 {
234 1
235 1 uchar i;
236 1 for (i=0;i<8;i++)
237 1 {
238 2 tem_A = 0;
C51 COMPILER V8.05a STC5410_AD 03/17/2009 20:35:48 PAGE 5
239 2 TempDelay(1);
240 2 tem_A=wr&0x01;
241 2 TempDelay(8); //delay 45 uS //5
242 2 tem_A=1;
243 2 wr >>= 1;
244 2
245 2 }
246 1 }
247 /************************************************************
248 *Function:读18B20的一个字节
249 *parameter:
250 *Return:
251 *Modify:
252 *************************************************************/
253 uchar ReadByte_A () //读取单字节
254 {
255 1
256 1 uchar i,u=0;
257 1 for(i=0;i<8;i++)
258 1 {
259 2 tem_A = 0;
260 2 TempDelay(1);
261 2 u >>= 1;
262 2 tem_A = 1;
263 2 if(tem_A==1)
264 2 u |= 0x80;
265 2 TempDelay (6);
266 2
267 2 tem_A = 1;
268 2 }
269 1 return(u);
270 1
271 1 }
272 /************************************************************
273 *Function:读18B20
274 *parameter:
275 *Return:
276 *Modify:
277 *************************************************************/
278 void read_bytes_A (uchar j)
279 {
280 1
281 1 uchar i;
282 1 for(i=0;i<j;i++)
283 1 {
284 2 *p = ReadByte_A();
285 2 p++;
286 2 }
287 1
288 1 }
289
-
290 /************************************************************
291 *Function:读取温度
292 *parameter:
293 *Return:
294 *Modify:
295 *************************************************************/
296 void GemTemp_A ()
297 {
298 1 read_bytes_A (2);
299 1 Temperature = temp_buff[1]*0x100 + temp_buff[0];
C51 COMPILER V8.05a STC5410_AD 03/17/2009 20:35:48 PAGE 6
300 1 //Temperature *= 0.625;
301 1 Temperature /= 16;
302 1 TempDelay(1);
303 1 }
304
305
306 /************************************************************
307 *Function:18B20ID全处理
308 *parameter:
309 *Return:
310 *Modify:
311 *************************************************************/
312 void TemperatuerResult_A()
313 {
314 1 Init18b20_A ();
315 1 WriteByte_A(0xCC); //skip rom
316 1 WriteByte_A(0x44); //Temperature convert
317 1 Init18b20_A ();
318 1 TempDelay(30);
319 1 WriteByte_A(0xCC); //skip rom
320 1 WriteByte_A(0xBE); //read Temperature
321 1 p = temp_buff;
322 1 GemTemp_A();
323 1 }
324
325 //****************************************************************************************
326
327 Temperature_js()
328 {
329 1 //*******************************************************
330 1 tem10=Temperature/10;
331 1 tem1=Temperature-tem10*10;
332 1 Temperature-=(tem10*10+tem1);
333 1 Temperature*=10;
334 1 tem_1=Temperature;
335 1 //**********************************************************
336 1 }
337
338 main()
339 {
340 1 delay( 50000);
341 1 delay( 50000);
342 1 delay( 50000);
343 1 delay( 50000);
344 1 delay( 50000);
345 1 delay( 50000);
346 1 serialset ();
347 1
348 1 while (1)
349 1 {
350 2 TemperatuerResult_A();
351 2 Temperature_js();
352 2 sendchar(tem10);
353 2 sendchar(tem1);
354 2 sendchar(85);
355 2 Temp_display();
356 2 delay( 50000);
357 2 delay( 50000);
358 2 delay( 50000);
359 2 delay( 50000);
360 2 delay( 50000);
361 2 delay( 50000);
C51 COMPILER V8.05a STC5410_AD 03/17/2009 20:35:48 PAGE 7
362 2 delay( 50000);
363 2 }
364 1
365 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 802 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 47 2
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -