?? 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 + -