📄 ds18b20lll.lst
字号:
203 *----------------------------------------------------*/
204 bit tmrbit(void)
205 {
206 1 int i=0;
207 1 bit dat;
208 1 TMDAT=0;
209 1 _nop_();
210 1 _nop_();
211 1 _nop_();
212 1
213 1 _nop_();
214 1 _nop_();
215 1 _nop_();
216 1
217 1 _nop_();
218 1 _nop_();
219 1 _nop_();
220 1
221 1 _nop_();
222 1 _nop_();
223 1 _nop_();
224 1 TMDAT=1;
225 1 _nop_();
226 1
227 1 _nop_();
228 1
229 1 _nop_();
230 1
231 1 _nop_();
232 1 dat = TMDAT;
233 1 Delay_Count(30);
234 1
235 1 Delay_Count(30);
236 1
237 1 Delay_Count(30);
238 1
239 1 Delay_Count(30);
240 1 TMDAT=1;
C51 COMPILER V7.06 DS18B20LLL 11/01/2007 15:36:36 PAGE 5
241 1 return dat;
242 1 }
243 /*----------------------------------------------------
244 * Read a byte from 1820
245 *----------------------------------------------------*/
246 unsigned char tmrbyte()
247 {
248 1 unsigned char i,j,dat=0;
249 1 for(i=1;i<=8;i++)
250 1 {
251 2 j=tmrbit();
252 2 dat=(j<<7)|(dat>>1);
253 2 }
254 1 return dat;
255 1 }
256 /*----------------------------------------------------
257 * Write a byte from 1820
258 *----------------------------------------------------*/
259 void tmwbyte(unsigned char dat)
260 {
261 1 unsigned char i;
262 1 for(i=0;i<8;i++)
263 1 {
264 2 TMDAT=0;
265 2 _nop_();
266 2 _nop_();
267 2 _nop_();
268 2 _nop_();
269 2
270 2 _nop_();
271 2 _nop_();
272 2 _nop_();
273 2 _nop_();
274 2
275 2 _nop_();
276 2 _nop_();
277 2 _nop_();
278 2 _nop_();
279 2
280 2 _nop_();
281 2 _nop_();
282 2 _nop_();
283 2 _nop_();
284 2 TMDAT=dat&0x01;
285 2 Delay_Count(20);
286 2 _nop_();
287 2 _nop_();
288 2
289 2 Delay_Count(20);
290 2 _nop_();
291 2 _nop_();
292 2
293 2 Delay_Count(20);
294 2 _nop_();
295 2 _nop_();
296 2
297 2 Delay_Count(20);
298 2 _nop_();
299 2 _nop_();
300 2
301 2 TMDAT=1;
302 2 _nop_();
C51 COMPILER V7.06 DS18B20LLL 11/01/2007 15:36:36 PAGE 6
303 2 _nop_();
304 2
305 2 _nop_();
306 2 _nop_();
307 2
308 2 _nop_();
309 2 _nop_();
310 2
311 2 _nop_();
312 2 _nop_();
313 2 dat>>=1;
314 2 }
315 1 }
316 /*----------------------------------------------------
317 * Main
318 *----------------------------------------------------*/
319 unsigned char main1(unsigned char num)
320 {
321 1 unsigned char a,b,a2,b2,i,j,cha[4];
322 1 unsigned int w1,w2;
323 1 unsigned int da1,da2;
324 1 float fa1,fa2,fa3;
325 1 //unsigned char chinese4[];
326 1 //autobaud();
327 1
328 1 //while(1)
329 1 // {
330 1 tmreset();
331 1 tmwbyte(0x0CC);
332 1 tmwbyte(0x044);
333 1
334 1 tmreset();
335 1 tmwbyte(0x0CC);
336 1 tmwbyte(0x0BE);
337 1
338 1 a=tmrbyte(); //低8位
339 1 b=tmrbyte(); //高8位
340 1
341 1 a2=a&0x0F;
342 1 w1=hextobcd1(a2); //小数(整型)
343 1
344 1 fa1=inttofloat(w1);
345 1 printf("%f\n",fa1);
346 1 printf("%d\n",w1);
347 1
348 1 a2=a&0x0F0;
349 1 a2=a2>>4;
350 1 b2=b&0x00F;
351 1 b2=b2<<4;
352 1 a2=a2|b2;
353 1 w2=hextobcd(a2); //整数
354 1
355 1 printf("%d\n",w2);
356 1
357 1 da1=w2/10; //整数部分十位
358 1 da2=w2%10; //整数部分个位
359 1
360 1 cha[0]=inttochar(da1);
361 1 cha[1]=inttochar(da2);
362 1 cha[2]='.';
363 1 cha[3]=inttochar(w1);
364 1 cha[4]='\0';
C51 COMPILER V7.06 DS18B20LLL 11/01/2007 15:36:36 PAGE 7
365 1
366 1 //fa2=atof(cha);
367 1
368 1 //printf("%f\n",fa2);
369 1 fa2=inttofloat(cha[0]);
370 1 fa3=inttofloat(cha[1]);
371 1
372 1 printf("%s\n",cha);
373 1
374 1 fa3=12.3; //+fa1/10;
375 1
376 1
377 1 //printf("%f\n",fa3);
378 1 for(j=1;j<=10;j++)
379 1 {
380 2 for(i=1;i<=200;i++)
381 2 Delay_Count(255);
382 2 }
383 1
384 1
385 1 //unsigned char code chinese4[] = {"T"};
386 1 // }
387 1 if (num==0)
388 1 return cha[0];
389 1 else if(num==1)
390 1 return cha[1];
391 1 else if(num==2)
392 1 return cha[2];
393 1 else if(num==3)
394 1 return cha[3];
395 1 else if(num==4)
396 1 return cha[4];
397 1
398 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1370 ----
CONSTANT SIZE = 12 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 27
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 + -