📄 tx-1bds18b20.lst
字号:
C51 COMPILER V6.12 TX_1BDS18B20 12/01/2006 19:30:57 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE TX_1BDS18B20
OBJECT MODULE PLACED IN C:\DOCUME~1\LD9149~1.XC-\桌面\51\手册程序\八BA6B~1.DS1\TX-1BDS18B20.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE C:\DOCUME~1\LD9149~1.XC-\桌面\51\手册程序\八BA6B~1.DS1\TX-1BDS18B20.C DB SB
- OE
stmt level source
1 //安装目录下的EXE文件打开后可在电脑上显示当前温度值
2 #include <reg52.h>
3 #define uchar unsigned char
4 #define uint unsigned int
5 sbit DS=P2^2; //define interface
6 uint temp; // variable of temperature
7 uchar flag1; // sign of the result positive or negative
8 sbit dula=P2^6;
9 sbit wela=P2^7;
10 unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
11 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
12 unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
13 0x87,0xff,0xef};
14
15 void delay(uint count) //delay
16 {
17 1 uint i;
18 1 while(count)
19 1 {
20 2 i=200;
21 2 while(i>0)
22 2 i--;
23 2 count--;
24 2 }
25 1 }
26 ///////功能:串口初始化,波特率9600,方式1///////
27 void Init_Com(void)
28 {
29 1 TMOD = 0x20;
30 1 PCON = 0x00;
31 1 SCON = 0x50;
32 1 TH1 = 0xFd;
33 1 TL1 = 0xFd;
34 1 TR1 = 1;
35 1 }
36
37 void dsreset(void) //send reset and initialization command
38 {
39 1 uint i;
40 1 DS=0;
41 1 i=103;
42 1 while(i>0)i--;
43 1 DS=1;
44 1 i=4;
45 1 while(i>0)i--;
46 1 }
47
48 bit tmpreadbit(void) //read a bit
49 {
50 1 uint i;
51 1 bit dat;
52 1 DS=0;i++; //i++ for delay
53 1 DS=1;i++;i++;
54 1 dat=DS;
C51 COMPILER V6.12 TX_1BDS18B20 12/01/2006 19:30:57 PAGE 2
55 1 i=8;while(i>0)i--;
56 1 return (dat);
57 1 }
58
59 uchar tmpread(void) //read a byte date
60 {
61 1 uchar i,j,dat;
62 1 dat=0;
63 1 for(i=1;i<=8;i++)
64 1 {
65 2 j=tmpreadbit();
66 2 dat=(j<<7)|(dat>>1); //读出的数据最低位在最前面,这样刚好一个字节在DAT里
67 2 }
68 1 return(dat);
69 1 }
70
71 void tmpwritebyte(uchar dat) //write a byte to ds18b20
72 {
73 1 uint i;
74 1 uchar j;
75 1 bit testb;
76 1 for(j=1;j<=8;j++)
77 1 {
78 2 testb=dat&0x01;
79 2 dat=dat>>1;
80 2 if(testb) //write 1
81 2 {
82 3 DS=0;
83 3 i++;i++;
84 3 DS=1;
85 3 i=8;while(i>0)i--;
86 3 }
87 2 else
88 2 {
89 3 DS=0; //write 0
90 3 i=8;while(i>0)i--;
91 3 DS=1;
92 3 i++;i++;
93 3 }
94 2
95 2 }
96 1 }
97
98 void tmpchange(void) //DS18B20 begin change
99 {
100 1 dsreset();
101 1 delay(1);
102 1 tmpwritebyte(0xcc); // address all drivers on bus
103 1 tmpwritebyte(0x44); // initiates a single temperature conversion
104 1 }
105
106 uint tmp() //get the temperature
107 {
108 1 float tt;
109 1 uchar a,b;
110 1 dsreset();
111 1 delay(1);
112 1 tmpwritebyte(0xcc);
113 1 tmpwritebyte(0xbe);
114 1 a=tmpread();
115 1 b=tmpread();
116 1 temp=b;
C51 COMPILER V6.12 TX_1BDS18B20 12/01/2006 19:30:57 PAGE 3
117 1 temp<<=8; //two byte compose a int variable
118 1 temp=temp|a;
119 1 tt=temp*0.0625;
120 1 temp=tt*10+0.5;
121 1 return temp;
122 1 }
123
124 void readrom() //read the serial
125 {
126 1 uchar sn1,sn2;
127 1 dsreset();
128 1 delay(1);
129 1 tmpwritebyte(0x33);
130 1 sn1=tmpread();
131 1 sn2=tmpread();
132 1 }
133
134
135 void delay10ms() //delay
136 {
137 1 uchar a,b;
138 1 for(a=10;a>0;a--)
139 1 for(b=60;b>0;b--);
140 1 }
141
142 void display(uint temp) //显示程序
143 {
144 1 uchar A1,A2,A2t,A3,ser;
145 1 ser=temp/10;
146 1 SBUF=ser;
147 1 A1=temp/100;
148 1 A2t=temp%100;
149 1 A2=A2t/10;
150 1 A3=A2t%10;
151 1 dula=0;
152 1 P0=table[A1]; //显示百位
153 1 dula=1;
154 1 dula=0;
155 1
156 1 wela=0;
157 1 P0=0x7e;
158 1 wela=1;
159 1 wela=0;
160 1 delay(1);
161 1
162 1 dula=0;
163 1 P0=table1[A2]; //显示十位
164 1 dula=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -