?? ds18b20.lst
字號(hào):
C51 COMPILER V8.08 DS18B20 06/04/2007 09:25:15 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE DS18B20
OBJECT MODULE PLACED IN ds18b20.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ds18b20.c OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND
line level source
1 /*******************************************************************
2 **函數(shù)功能:ds18b20的驅(qū)動(dòng)函數(shù) **
3 **創(chuàng)建人:xingyuegu **
4 **創(chuàng)建日期:2006-7-12 **
5 **版本:1.0 **
6 **修改日期:2006-10-30 **
7 **版本:2.0 **
8 *******************************************************************/
9 #include <reg51.h>
10 #include <intrins.h>
11 #include <math.h>
12 #include <stdio.h>
13
14 #define uchar unsigned char
15 #define uint unsigned int
16 void serial_set(void);
17 void process(unsigned char,unsigned char);
18 char volatile xiaoshu_temp[5],zhen_temp[4]; //
19 bit flag;
20 bit dot_dis=1;
21 sbit DQ=P1^0;
22 //sbit DQ=P2^3;
23 extern unsigned char temp[5];
24 /*************************************************************
25 **功能:延時(shí)600us **
26 **參數(shù):無(wú) **
27 *************************************************************/
28 void delay600us(void)
29 {
30 1 uchar i;
31 1 for(i=0;i<255;i++);
32 1
33 1 }
34 /*************************************************************
35 **功能:延時(shí)60us **
36 **參數(shù):無(wú) **
37 *************************************************************/
38 void delay60us(void)
39 {
40 1 uchar i;
41 1 for(i=0;i<20;i++);
42 1 }
43 /*************************************************************
44 **功能:延時(shí)240us **
45 **參數(shù):無(wú) **
46 *************************************************************/
47 void delay240us(void)
48 {
49 1 uchar i;
50 1 for(i=0;i<80;i++);
51 1 }
52 /*************************************************************
53 **功能:延時(shí)18us **
54 **參數(shù):無(wú) **
55 *************************************************************/
C51 COMPILER V8.08 DS18B20 06/04/2007 09:25:15 PAGE 2
56 /*void delay15us(void)
57 {
58 uchar i;
59 for(i=0;i<2;i++);
60 }*/
61 /*************************************************************
62 **功能:復(fù)位脈沖 **
63 **參數(shù):bool **
64 *************************************************************/
65 bit resetpulse(void)
66 {
67 1
68 1 DQ=0;
69 1 delay600us(); //延時(shí)500us
70 1 DQ=1;
71 1 delay60us(); // 延時(shí)60us
72 1 return(DQ); //讀取P1.0的狀態(tài)
73 1 }
74 /*************************************************************
75 **功能:ds18b20的初始化 **
76 **參數(shù):無(wú) **
77 *************************************************************/
78 void ds18b20_init(void)
79 {
80 1 while(1)
81 1 {
82 2 if(!resetpulse()) //收到ds18b20的應(yīng)答信號(hào)
83 2 {
84 3 //printf("reset successful!");
85 3
86 3 //delay240us(); //延時(shí)240us
87 3 DQ=1;
88 3 delay600us(); //延時(shí)240us
89 3 break;
90 3 }
91 2 else
92 2 resetpulse(); //否則再發(fā)復(fù)位信號(hào)
93 2 }
94 1 }
95
96 /*************************************************************
97 **功能:向ds18b20寫(xiě)命令 **
98 **參數(shù):無(wú) **
99 *************************************************************/
100 void ds18b20_writecommand(uchar command)
101 {
102 1
103 1 uchar i;
104 1 for(i=0;i<8;i++)
105 1 {
106 2 if((command & 0x01)==0)
107 2 {
108 3 DQ=0; //寫(xiě)0
109 3 delay60us(); //延時(shí)60us
110 3 _nop_();
111 3 _nop_();
112 3 _nop_();
113 3 _nop_();
114 3 _nop_();
115 3 _nop_();
116 3 DQ=1;
117 3 _nop_();
C51 COMPILER V8.08 DS18B20 06/04/2007 09:25:15 PAGE 3
118 3 _nop_();
119 3
120 3 }
121 2
122 2 else //寫(xiě)1
123 2 {
124 3 DQ=0;
125 3 _nop_();
126 3 _nop_(); //延時(shí)2us
127 3 DQ=1;
128 3 delay60us(); //延時(shí)60us
129 3 _nop_();
130 3 _nop_();
131 3 _nop_();
132 3 _nop_();
133 3 }
134 2 command=_cror_(command,1); // 右移1位
135 2 }
136 1
137 1
138 1 }
139
140 /*************************************************************
141 **功能:讀ds18b20數(shù)據(jù) **
142 **參數(shù):返回讀到的數(shù)據(jù) **
143 *************************************************************/
144 uchar ds18b20_readdata(void)
145 {
146 1 uchar readdata;
147 1 uchar i;
148 1 for(i=0;i<8;i++)
149 1 {
150 2 DQ=0;
151 2 _nop_();
152 2 _nop_();
153 2 _nop_();
154 2 DQ=1; //釋放總線
155 2 //delay15us(); 注意不需要
156 2 if(DQ==0) //如果讀到的是0
157 2 {
158 3 readdata=readdata&0x7f;
159 3 delay60us();
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -