📄 miin.lst
字号:
C51 COMPILER V8.06 MIIN 11/20/2011 20:24:19 PAGE 1
C51 COMPILER V8.06, COMPILATION OF MODULE MIIN
OBJECT MODULE PLACED IN miin.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE miin.c BROWSE DEBUG OBJECTEXTEND
line level source
1 //实验平台:HL-1 V6.1+Keil U3
2 //开发公司:慧净电子WWW.HLMCU.COM
3 //淘宝店铺:http://shop37031453.taobao.com
4 //接上18B20温度传感器(另购)后数码管显示出当前温度
5 #include <reg52.h>
6 #define uchar unsigned char
7 #define uint unsigned int
8 sbit DS=P2^2; //define interface
9 uint temp; // variable of temperature
10 uchar flag1; // sign of the result positive or negative
11 sbit dula=P2^6;
12 sbit wela=P2^7;
13 unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
14 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
15 unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
16 0x87,0xff,0xef};
17
18 void delay(uint count) //delay
19 {
20 1 uint i;
21 1 while(count)
22 1 {
23 2 i=200;
24 2 while(i>0)
25 2 i--;
26 2 count--;
27 2 }
28 1 }
29 ///////功能:串口初始化,波特率9600,方式1///////
30 void Init_Com(void)
31 {
32 1 TMOD = 0x20;
33 1 PCON = 0x00;
34 1 SCON = 0x50;
35 1 TH1 = 0xFd;
36 1 TL1 = 0xFd;
37 1 TR1 = 1;
38 1 }
39
40 void dsreset(void) //send reset and initialization command
41 {
42 1 uint i;
43 1 DS=0;
44 1 i=103;
45 1 while(i>0)i--;
46 1 DS=1;
47 1 i=4;
48 1 while(i>0)i--;
49 1 }
50
51 bit tmpreadbit(void) //read a bit
52 {
53 1 uint i;
54 1 bit dat;
55 1 DS=0;i++; //i++ for delay
C51 COMPILER V8.06 MIIN 11/20/2011 20:24:19 PAGE 2
56 1 DS=1;i++;i++;
57 1 dat=DS;
58 1 i=8;while(i>0)i--;
59 1 return (dat);
60 1 }
61
62 uchar tmpread(void) //read a byte date
63 {
64 1 uchar i,j,dat;
65 1 dat=0;
66 1 for(i=1;i<=8;i++)
67 1 {
68 2 j=tmpreadbit();
69 2 dat=(j<<7)|(dat>>1); //读出的数据最低位在最前面,这样刚好一个字节在DAT里
70 2 }
71 1 return(dat);
72 1 }
73
74 void tmpwritebyte(uchar dat) //write a byte to ds18b20
75 {
76 1 uint i;
77 1 uchar j;
78 1 bit testb;
79 1 for(j=1;j<=8;j++)
80 1 {
81 2 testb=dat&0x01;
82 2 dat=dat>>1;
83 2 if(testb) //write 1
84 2 {
85 3 DS=0;
86 3 i++;i++;
87 3 DS=1;
88 3 i=8;while(i>0)i--;
89 3 }
90 2 else
91 2 {
92 3 DS=0; //write 0
93 3 i=8;while(i>0)i--;
94 3 DS=1;
95 3 i++;i++;
96 3 }
97 2
98 2 }
99 1 }
100
101 void tmpchange(void) //DS18B20 begin change
102 {
103 1 dsreset();
104 1 delay(1);
105 1 tmpwritebyte(0xcc); // address all drivers on bus
106 1 tmpwritebyte(0x44); // initiates a single temperature conversion
107 1 }
108
109 uint tmp() //get the temperature
110 {
111 1 float tt;
112 1 uchar a,b;
113 1 dsreset();
114 1 delay(1);
115 1 tmpwritebyte(0xcc);
116 1 tmpwritebyte(0xbe);
117 1 a=tmpread();
C51 COMPILER V8.06 MIIN 11/20/2011 20:24:19 PAGE 3
118 1 b=tmpread();
119 1 temp=b;
120 1 temp<<=8; //two byte compose a int variable
121 1 temp=temp|a;
122 1 tt=temp*0.0625;
123 1 temp=tt*10+0.5;
124 1 return temp;
125 1 }
126
127 void readrom() //read the serial
128 {
129 1 uchar sn1,sn2;
130 1 dsreset();
131 1 delay(1);
132 1 tmpwritebyte(0x33);
133 1 sn1=tmpread();
134 1 sn2=tmpread();
135 1 }
136
137
138 void delay10ms() //delay
139 {
140 1 uchar a,b;
141 1 for(a=10;a>0;a--)
142 1 for(b=60;b>0;b--);
143 1 }
144
145 void display(uint temp) //显示程序
146 {
147 1 uchar A1,A2,A2t,A3,ser;
148 1 ser=temp/10;
149 1 SBUF=ser;
150 1 A1=temp/100;
151 1 A2t=temp%100;
152 1 A2=A2t/10;
153 1 A3=A2t%10;
154 1 dula=0;
155 1 P0=table[A1]; //显示百位
156 1 dula=1;
157 1 dula=0;
158 1
159 1 wela=0;
160 1 P0=0x7e;
161 1 wela=1;
162 1 wela=0;
163 1 delay(1);
164 1
165 1 dula=0;
166 1 P0=table1[A2]; //显示十位
167 1 dula=1;
168 1 dula=0;
169 1
170 1 wela=0;
171 1 P0=0x7d;
172 1 wela=1;
173 1 wela=0;
174 1 delay(1);
175 1
176 1 P0=table[A3]; //显示个位
177 1 dula=1;
178 1 dula=0;
179 1
C51 COMPILER V8.06 MIIN 11/20/2011 20:24:19 PAGE 4
180 1 P0=0x7b;
181 1 wela=1;
182 1 wela=0;
183 1 delay(1);
184 1 }
185
186
187 void main()
188 {
189 1 uchar a;
190 1 Init_Com();
191 1 do
192 1 {
193 2 tmpchange();
194 2 // delay(200);
195 2 for(a=10;a>0;a--)
196 2 { display(tmp());
197 3 }
198 2 } while(1);
199 1 }
200
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 516 ----
CONSTANT SIZE = 26 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 8
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 + -