📄 digthermo.lst
字号:
C51 COMPILER V8.02 DIGTHERMO 01/03/2009 15:42:01 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE DIGTHERMO
OBJECT MODULE PLACED IN DigThermo.OBJ
COMPILER INVOKED BY: D:\keil\C51\BIN\C51.EXE DigThermo.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "DigThermo.h"
2
3 /* 延时t毫秒 */
4 void delay(uchar t)
5 {
*** ERROR C132 IN LINE 5 OF DIGTHERMO.C: '_delay': not in formal parameter list
*** ERROR C141 IN LINE 5 OF DIGTHERMO.C: syntax error near '{'
6 unsigned char m=0;
*** ERROR C136 IN LINE 6 OF DIGTHERMO.C: 'm': 'void' on variable
*** ERROR C244 IN LINE 6 OF DIGTHERMO.C: 'm': can't initialize, bad type or class
*** ERROR C136 IN LINE 6 OF DIGTHERMO.C: 'm': 'void' on variable
*** ERROR C132 IN LINE 6 OF DIGTHERMO.C: 'm': not in formal parameter list
7 while(t--)for(m=0;m<120;m++);
*** ERROR C141 IN LINE 7 OF DIGTHERMO.C: syntax error near 'while'
*** ERROR C141 IN LINE 7 OF DIGTHERMO.C: syntax error near '--', expected ')'
*** ERROR C141 IN LINE 7 OF DIGTHERMO.C: syntax error near '=', expected ')'
*** ERROR C129 IN LINE 7 OF DIGTHERMO.C: missing ';' before '<'
8 }
9
10 /* 产生复位脉冲初始化DS18B20 */
11 void TxReset(void)
12 {
13 uint i;
14 DQ = 0;
15
16 /* 拉低约900us */
17 i = 100;
18 while (i>0) i--;
19
20 DQ = 1; // 产生上升沿
21 i = 4;
22 while (i>0) i--;
23 }
24
25 /* 等待应答脉冲 */
26 void RxWait(void)
27 {
28 uint i;
29 while(DQ);
30 while(~DQ); // 检测到应答脉冲
31 i = 4;
32 while (i>0) i--;
33 }
34
35 /* 读取数据的一位,满足读时隙要求 */
36 bit RdBit(void)
37 {
38 uint i;
39 bit b;
40 DQ = 0;
41 i++;
42 DQ = 1;
43 i++;i++; // 延时15us以上,读时隙下降沿后15us,DS18B20输出数据才有效
44 b = DQ;
45 i = 8;
C51 COMPILER V8.02 DIGTHERMO 01/03/2009 15:42:01 PAGE 2
46 while(i>0) i--;
47 return (b);
48 }
49
50 /* 读取数据的一个字节 */
51 uchar RdByte(void)
52 {
53 uchar i,j,b;
54 b = 0;
55 for (i=1;i<=8;i++)
56 {
57 j = RdBit();
58 b = (j<<7)|(b>>1);
59 }
60 return(b);
61 }
62
63 /* 写数据的一个字节,满足写1和写0的时隙要求 */
64 void WrByte(uchar b)
65 {
66 uint i;
67 uchar j;
68 bit btmp;
69 for(j=1;j<=8;j++)
70 {
71 btmp = b&0x01;
72 b = b>>1; // 取下一位(由低位向高位)
73 if (btmp)
74 {
75 /* 写1 */
76 DQ = 0;
77 i++;i++; // 延时,使得15us以内拉高
78 DQ = 1;
79 i = 8;
80 while(i>0) i--; // 整个写1时隙不低于60us
81 }
82 else
83 {
84 /* 写0 */
85 DQ = 0;
86 i = 8;
87 while(i>0) i--; // 保持低在60us到120us之间
88 DQ = 1;
89 i++;
90 i++;
91 }
92 }
93 }
94
95 /* 启动温度转换 */
96 void convert(void)
97 {
98 TxReset(); // 产生复位脉冲,初始化DS18B20
99 RxWait(); // 等待DS18B20给出应答脉冲
100 delay(1); // 延时
101 WrByte(0xcc); // skip rom 命令
102 WrByte(0x44); // convert T 命令
103 }
104
105 /* 读取温度值 */
106 void RdTemp(void)
107 {
C51 COMPILER V8.02 DIGTHERMO 01/03/2009 15:42:01 PAGE 3
108 TxReset(); // 产生复位脉冲,初始化DS18B20
109 RxWait(); // 等待DS18B20给出应答脉冲
110 delay(1); // 延时
111 WrByte(0xcc); // skip rom 命令
112 WrByte(0xbe); // read scratchpad 命令
113 tplsb = RdByte(); // 温度值低位字节(其中低4位为二进制的“小数”部分)
114 tpmsb = RdByte(); // 高位值高位字节(其中高5位为符号位)
115 }
116
117 uint Get_Temp(void)
118 {
119 uint t = 0;
120 delay(1); // 延时1ms
121 convert(); // 启动温度转换,需要750ms
122 delay(1000); // 延时1s
123 RdTemp(); // 读取温度
124 t = tplsb + tpmsb<<8;
125 return t;
126 }
127
C51 COMPILATION COMPLETE. 0 WARNING(S), 10 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -