📄 sensorlib.lst
字号:
C51 COMPILER V8.08 SENSORLIB 12/13/2007 14:04:03 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE SENSORLIB
OBJECT MODULE PLACED IN SensorLib.OBJ
COMPILER INVOKED BY: C:\Keil_c51\C51\BIN\C51.EXE SensorLib.c BROWSE
line level source
1 //this file contain the method to operate the sensor
2 //Author;Decell.Zhou
3
4
5 #include "SensorLib.h"
6 #include "ledLib.h"
7
8
9 void delay15(){//delay for 15us
10 1 unsigned char i;
11 1 for(i = 0;i < 8;i++);
12 1 }
13
14
15
16 //============[write1TS]==============
17 //Description:generate a write 1 Time Slot to DS18B20
18 //Author:Decell.Zhou
19 //Version
20 //Arg:none
21 //Return:none
22 //====================================
23 void write1TS(void){
24 1
25 1
26 1 sensorDQ = 1;//pull up the bus
27 1 sensorDQ = 0;//generate a time slot
28 1 _nop_ ();//wait for 7us
29 1 _nop_ ();
30 1 _nop_ ();
31 1 _nop_ ();
32 1 _nop_ ();
33 1 _nop_ ();
34 1 _nop_ ();
35 1 sensorDQ = 1;//pull up the bus
36 1 _nop_ ();
37 1 _nop_ ();
38 1 _nop_ ();
39 1 _nop_ ();
40 1 _nop_ ();
41 1 _nop_ ();
42 1 _nop_ ();
43 1 delay15();
44 1 delay15();
45 1 delay15();
46 1
47 1 }
48
49
50 //============[write0TS]==============
51 //Description:generate a write 0 Time Slot to DS18B20
52 //Author:Decell.Zhou
53 //Version
54 //Arg:none
55 //Return:none
C51 COMPILER V8.08 SENSORLIB 12/13/2007 14:04:03 PAGE 2
56 //====================================
57 void write0TS(void){
58 1
59 1 sensorDQ = 1;;
60 1 sensorDQ = 0;
61 1 delay15();
62 1 delay15();
63 1 delay15();
64 1 delay15();
65 1 sensorDQ = 1;
66 1 _nop_ ();
67 1 _nop_ ();
68 1
69 1
70 1 }
71
72
73 //===========[readTS]=================
74 //Description:generate a read Time Slot to DS18B20
75 //Author:Decell.Zhou
76 //Version
77 //Arg:none
78 //Return:none
79 //====================================
80 bit readTS(void){
81 1
82 1 bit b;
83 1
84 1 sensorDQ = 1;//generate a read time slot
85 1 sensorDQ = 0;
86 1 _nop_ ();
87 1 _nop_ ();
88 1 _nop_ ();
89 1 _nop_ ();
90 1 _nop_ ();
91 1 _nop_ ();
92 1 sensorDQ = 1;//release the bus
93 1 _nop_ ();
94 1 _nop_ ();
95 1 _nop_ ();
96 1 _nop_ ();
97 1 _nop_ ();
98 1 b = sensorDQ;
99 1 delay15();
100 1 delay15();
101 1 delay15();
102 1 _nop_ ();
103 1 _nop_ ();
104 1 return b;
105 1
106 1
107 1 }
108
109
110 //===========[writeSensor]============
111 //Description:write a byte to the DS18B20
112 //Author:Decell.Zhou
113 //Version:
114 //Arg: value | unsigned char | the vaule you want to send to DS18B20
115 //Return:none
116 //==================================
117 void writeSensor(unsigned char value){
C51 COMPILER V8.08 SENSORLIB 12/13/2007 14:04:03 PAGE 3
118 1 unsigned char bitCount;
119 1
120 1 for(bitCount = 0;bitCount < 8;bitCount++){
121 2
122 2 if((value & 0x1) == 1){
123 3 write1TS();
124 3 }else{
125 3 write0TS();
126 3 }
127 2 value = value >> 1;
128 2 }
129 1
130 1
131 1 }
132
133 //==========[readSensor]==============
134 //Description:read a value from the DS18B20
135 //Author:Decell.Zhou
136 //Version:
137 //Arg:none
138 //Return:the byte read read from the sensor | unsigned char
139 //===================================
140 unsigned char readSensor(void){
141 1 unsigned char bitCount;
142 1 bit tmpBit;
143 1 unsigned char value;
144 1 unsigned char valueMsk;
145 1
146 1 valueMsk = 0x0;
147 1
148 1 for(bitCount = 0,value = 0;bitCount < 8;bitCount++){
149 2 tmpBit = readTS();
150 2 //for(i = 0;i < 1000;i++){
151 2 // ledSetDigit(tmpBit,0,0);
152 2 //}
153 2 valueMsk |= tmpBit;
154 2 value = value + ((valueMsk & 0x1)<< bitCount);
155 2 valueMsk = 0x0;
156 2 tmpBit = 0;
157 2 }
158 1
159 1 return value;
160 1 }
161
162 //==========[resetSensor]=============
163 //Description:generate a reset signal to the Sensor
164 //Author:Decell.Zhou
165 //Version;
166 //Arg:none
167 //Return:none
168 //====================================
169 void resetSensor(void){
170 1 int i;
171 1
172 1 sensorDQ = 1;
173 1 sensorDQ = 0;
174 1 for(i = 0;i < 300;i++);//delay for 500us
175 1 sensorDQ = 1;//release the bus
176 1 while(sensorDQ);//wait for the DS18B20 to pull low the bus
177 1 _nop_ ();
178 1 while(!sensorDQ);
179 1 for(i = 0;i < 300;i++);//delay for 500us;
C51 COMPILER V8.08 SENSORLIB 12/13/2007 14:04:03 PAGE 4
180 1
181 1 }
182
183
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 194 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -