📄 ds18b20_pwm.lst
字号:
173 1 disdata[3]=tvalue%10+0x30;//小数位
174 1
175 1 if(tflag==0)
176 1 flagdat=0x20;//正温度不显示符号
177 1 else
178 1 flagdat=0x2d;//负温度显示负号:-
179 1
C51 COMPILER V8.02 DS18B20_PWM 06/25/2010 17:30:16 PAGE 4
180 1 if(disdata[0]==0x30)
181 1 {disdata[0]=0x20;//如果百位为0,不显示
182 2 if(disdata[1]==0x30)
183 2 {disdata[1]=0x20;//如果百位为0,十位为0也不显示
184 3 }
185 2 }
186 1
187 1 Write_Com(0x8a);
188 1 Write_Dat(Tset/2000+0x30);//显示周期百位 Tset/20/100+0x30
189 1
190 1 Write_Com(0x8b);
191 1 Write_Dat(Tset/200%10+0x30);//显示周期十位 Tset/20/10%10+0x30
192 1
193 1 Write_Com(0x8c);
194 1 Write_Dat(Tset/20%10+0x30);//显示周期个位 Tset/20%10+0x30
195 1
196 1 Write_Com(0xc1);
197 1 Write_Dat(flagdat);//显示符号位
198 1 Write_Com(0xc2);
199 1 Write_Dat(disdata[0]);//显示百位
200 1 Write_Com(0xc3);
201 1 Write_Dat(disdata[1]);//显示十位
202 1 Write_Com(0xc4);
203 1 Write_Dat(disdata[2]);//显示个位
204 1 Write_Com(0xc5);
205 1 Write_Dat(0x2e);//显示小数点
206 1 Write_Com(0xc6);
207 1 Write_Dat(disdata[3]);//显示小数位
208 1
209 1
210 1 Write_Com(0xcd);
211 1 Write_Dat(SetTemp/10+0x30); //显示设置温度十位
212 1 Write_Com(0xce);
213 1 Write_Dat(SetTemp%10+0x30); //显示设置温度各位
214 1 Write_Com(0xcf);
215 1 Write_Dat('C');
216 1
217 1
218 1 }
219
220
221 void TO_Service (void) interrupt 1 using 3
222 {
223 1 TH0 = 0x3C;
224 1 TL0 = 0x0B0;
225 1 if(count==Tset) {count = 0;}
226 1 count++;
227 1 if(count<=Tset/20*(SetTemp-temp)) Light=1;
228 1 else Light=0;
229 1
230 1
231 1 }
232 void initTO(void)
233 {
234 1 TMOD=0X11;
235 1 EA=1;
236 1 ET0=0;
237 1 TH0 = 0x3C;
238 1 TL0 = 0x0B0;
239 1 TH1 = 0x3C;
240 1 TL1 = 0x0B0;
241 1 ET1 = 1;
C51 COMPILER V8.02 DS18B20_PWM 06/25/2010 17:30:16 PAGE 5
242 1 TR1 = 1;
243 1 TR0=0;
244 1
245 1 }
246
247
248
249 void Timer1Interrupt(void) interrupt 3
250 {
251 1 TH1 = 0x3C;
252 1 TL1 = 0x0B0;
253 1 if(count1==10) {count1=0;read_temp();} //0.5S读一次温度
254 1 count1++;
255 1 // keyscan();
256 1
257 1
258 1 }
259
260 void delay20ms(void) //误差 0us
261 {
262 1 unsigned char a,b;
263 1 for(b=215;b>0;b--)
264 1 for(a=45;a>0;a--);
265 1 _nop_; //if Keil,require use intrins.h
*** WARNING C275 IN LINE 265 OF DS18B20_PWM.C: expression with possibly no effect
266 1 _nop_; //if Keil,require use intrins.h
*** WARNING C275 IN LINE 266 OF DS18B20_PWM.C: expression with possibly no effect
267 1 }
268 void keyscan()
269 {
270 1 if(key==0||key2==0||key3==0)
271 1 delay20ms();
272 1 {
273 2 if(key==0)
274 2 {SetTemp++;
275 3 ds1820disp();
276 3 if(SetTemp==100) SetTemp=0;
277 3 }
278 2 if(key2==0)
279 2 {SetTemp--;
280 3 ds1820disp();
281 3 if(SetTemp==-1) SetTemp=99;
282 3
283 3 }
284 2 if(key3==0)
285 2 {
286 3 Tset+=20;count=0;//count必须清零,否则中断里的count不知道加到多少,造成紊乱
287 3 ds1820disp();
288 3 if(Tset==20000) Tset=20;
289 3 }
290 2 if(key4==0)
291 2 {
292 3 if(Tset==20) Tset=20000;
293 3 Tset-=20;count=0;//count必须清零,否则中断里的count不知道加到多少,造成紊乱
294 3 ds1820disp();
295 3
296 3
297 3 }
298 2 }
299 1 }
300
301 /********************主程序***********************************/
C51 COMPILER V8.02 DS18B20_PWM 06/25/2010 17:30:16 PAGE 6
302 void main()
303 { init_play();//初始化显示
304 1
305 1 initTO(); //TO初始化
306 1 while(1)
307 1 { keyscan();
308 2 ds1820disp();//显示
309 2 if((SetTemp-20)>0){
310 3 if(temp>=SetTemp) {ET0=0;Light=0;
311 4 Write_Com(0x84);Write_Dat('0');
312 4 Write_Com(0x85);Write_Dat('0');
313 4 Write_Com(0x86);Write_Dat('*');
314 4 } //如果温度值大于等于50度,灯灭
315 3 if(temp>=(SetTemp-20)&&temp<SetTemp) {TR0=1;ET0=1;
316 4 Write_Com(0x84);Write_Dat(((SetTemp-temp)*100/20)/10+0x30);
317 4 Write_Com(0x85);Write_Dat(((SetTemp-temp)*100/20)%10+0x30);
318 4 Write_Com(0x86);Write_Dat('%');} //如果温度值在30和50度之间,开中断,输出PWM波,显示占空比
319 3 if(temp<SetTemp-20) {ET0=0;Light=1;
320 4 Write_Com(0x84);Write_Dat('0');
321 4 Write_Com(0x85);Write_Dat('1');
322 4 Write_Com(0x86);Write_Dat('*');}// 如果温度值小于30度,关中断,灯亮
323 3 }
324 2 if ((SetTemp-20)<=0){ET0=0;Light=0;
325 3 Write_Com(0x84);Write_Dat('0');
326 3 Write_Com(0x85);Write_Dat('0');
327 3 Write_Com(0x86);Write_Dat('*');}//如果设置温度小于当前温度,占空比显示00*
328 2 }
329 1 }
330
331
332
333
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1510 ----
CONSTANT SIZE = 34 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 22 5
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 2 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -