📄 ds18b20.lst
字号:
160 3 }
161 2 else //读到的是1
162 2 {
163 3 readdata=readdata|0x80;
164 3 delay60us();
165 3 }
166 2 if(i<7)
167 2
168 2 readdata=_cror_(readdata,1);
169 2 }
170 1 return readdata;
171 1 }
172
173 /*************************************************************
174 **功能:温度处理函数 **
175 **参数:无返回 **
176 *************************************************************/
177 void temperature_process(uchar low,uchar high)
178 {
179 1 uint temp1,temp2,temp3;
C51 COMPILER V8.08 DS18B20 06/04/2007 09:25:15 PAGE 4
180 1 if(high&0x80)//判断正负
181 1 {
182 2 flag=1;
183 2
184 2 temp3=temp3|high;
185 2 temp3=temp3&0x00ff;
186 2 temp3=temp3<<8;
187 2 temp1=temp3;
188 2
189 2 temp1=temp1|low;
190 2
191 2 temp1=(temp1^0xffff);
192 2 temp1=temp1+1; //取反加1
193 2 low=temp1&0x000f;
194 2 high=temp1>>4;
195 2 process(high,low);
196 2 }
197 1 else
198 1 {
199 2
200 2 flag=0; //zhen
201 2 temp1=high;
202 2 temp2=low;
203 2 temp1=temp1<<4;
204 2 temp2=temp2>>4;
205 2 temp3=temp1|temp2;
206 2 high=temp3;
207 2 low=low&0x0f;
208 2 process(high,low);
209 2
210 2 }
211 1 }
212 /*************************************************************
213 **功能:数值处理函数 **
214 **参数:无返回 **
215 *************************************************************/
216 void process(unsigned char high,unsigned char low)
217 {
218 1 uint temp1;
219 1 uchar i;
220 1 temp1=low*625;
221 1 xiaoshu_temp[0]=temp1/1000+'0';
222 1 //xiaoshu_temp[1]=temp1/100%10+'0';
223 1 //xiaoshu_temp[2]=temp1%100/10+'0';
224 1 //xiaoshu_temp[3]=temp1%10+'0';
225 1 xiaoshu_temp[1]='\0';
226 1 dot_dis=1;
227 1 //if(xiaoshu_temp[3]=='0')
228 1 //{
229 1 // xiaoshu_temp[3]='\0';
230 1 // if(xiaoshu_temp[2]=='0')
231 1 // {
232 1 // xiaoshu_temp[2]='\0';
233 1 // if(xiaoshu_temp[1]=='0')
234 1 // {
235 1 // xiaoshu_temp[1]='\0';
236 1 if(xiaoshu_temp[0]=='0')
237 1 {
238 2 xiaoshu_temp[0]='\0';
239 2 dot_dis=0;
240 2 }
241 1 else
C51 COMPILER V8.08 DS18B20 06/04/2007 09:25:15 PAGE 5
242 1 dot_dis=1;
243 1
244 1
245 1 // }
246 1 // }
247 1
248 1 // }
249 1
250 1
251 1 zhen_temp[0]=high/100+'0';
252 1 zhen_temp[1]=high%100/10+'0';
253 1 zhen_temp[2]=high%10+'0';
254 1 zhen_temp[3]='\0';
255 1 for(i=0;i<2;i++)
256 1 if(zhen_temp[0]=='0')
257 1 {
258 2 zhen_temp[0]=zhen_temp[1];
259 2 zhen_temp[1]=zhen_temp[2];
260 2 zhen_temp[2]='\0';
261 2 }
262 1 else
263 1 break;
264 1 }
265 /****************************************/
266 //serial_set func
267 void serial_set(void)
268 {
269 1
270 1 SCON=0x50;
271 1 TMOD=TMOD&0x0f;
272 1 TMOD=TMOD|0x20;
273 1 TH1=0xfd;
274 1 TL1=0xfd;
275 1
276 1 TR1=1;
277 1 TI=1; //用PRINTF时,TI要置1
278 1 }
279 /*************************************************************
280 **功能:读序列号子程序 **
281 **参数:无返回 **
282 *************************************************************/
283 uchar * read_rom(void)
284 {
285 1 uchar rom[8],i;
286 1 ds18b20_init();
287 1 ds18b20_writecommand(0x33);
288 1 for(i=8;i>0;i--)
289 1 {
290 2 rom[i-1]=ds18b20_readdata();
291 2 }
292 1 return &rom[0];
293 1 }
294 /*************************************************************
295 **功能:序列号匹配子程序 **
296 **参数:无返回 **
297 *************************************************************/
298 bit match_rom(uchar *rom)
299 {
300 1 uchar i;
301 1 ds18b20_init();
302 1 ds18b20_writecommand(0x55);
303 1 for(i=8;i>0;i--)
C51 COMPILER V8.08 DS18B20 06/04/2007 09:25:15 PAGE 6
304 1 {
305 2 ds18b20_writecommand(*(rom+i-1));
306 2 // rom++;
307 2 }
308 1 return 1;
309 1 }
310
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 479 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 9 17
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 + -