📄 led.lst
字号:
279 1 }
280 //=============================================
281 void lcd_reset(void) small
282 {
283 1 P0 = 0xdf; // lcd_rs/wr/rd/cs1/cs2 normal - skeep high. //上电复位
284 1 delay1(4000); // delay 120ms 等待上电复位
285 1 P0 = 0xff; // lcd_rs/wr/rd/cs1/cs2 normal - skeep high. //上电复位
286 1 delay1(100); // delay 120ms 等待上电复位
287 1
288 1 }
289 //.............................................
290 //.............................................
291 void lcd_initial(void) small
292 { //初始化
293 1 uchar i;
294 1 for(i=0;i<39;i++)
295 1 {
296 2 lcd_regwrite(inittab1[i],inittab2[i]);
297 2 }
298 1 }
299 //.............................................
300 void lcd_clear(void) small
301 { //清屏
302 1 uchar reg_rddata;
303 1 lcd_regwrite(0xe0,0x00);
C51 COMPILER V8.08 LED 08/20/2008 16:06:02 PAGE 6
304 1 reg_rddata = lcd_regread(0xf0);
305 1 reg_rddata |= 0x08;
306 1 lcd_regwrite(0xf0,reg_rddata);
307 1 }
308 //.............................................
309 void lcd_photo(uchar code *pho) small
310 { //显示图形
311 1 uchar i,j,k;
312 1 uchar code *pp;
313 1 gotoxy(0,0);
314 1 for(k=0;k<2;k++)
315 1 {
316 2 pp=pho;
317 2 for(j=0;j<64;j++)
318 2 {
319 3 for(i=0;i<30;i++)
320 3 {
321 4 lcd_datawrite(*pp);
322 4 // delay(50);
323 4 ++pp;
324 4 }
325 3 }
326 2 }
327 1 }
328 //.............................................
329 void lcd_lattice(uchar data1,uchar data2) small
330 { //显示点阵
331 1 uchar i,j;
332 1 gotoxy(0,0);
333 1 for(j=0;j<32;j++)
334 1 {
335 2 for(i=0;i<60;i++)
336 2 {
337 3 lcd_datawrite(data1);
338 3 }
339 2 for(i=0;i<60;i++)
340 2 {
341 3 lcd_datawrite(data2);
342 3 }
343 2 }
344 1 }
345 //.............................................
346 void lcd_character(uchar code *cha,int count) small
347 { //显示中文或字符
348 1 int i;
349 1 for(i=0;i<count;i++)
350 1 {
351 2 lcd_datawrite(*cha);
352 2 ++cha;
353 2 }
354 1 }
355 //.............................................
356 extern void gotoxy(uchar x,uchar y) small
357 { //定坐标
358 1 lcd_regwrite(0x60,x); // active window top register(awtr)
359 1 lcd_regwrite(0x70,y); // active window top register(awtr)
360 1 }
361 //=============================================
362
363
364
365
C51 COMPILER V8.08 LED 08/20/2008 16:06:02 PAGE 7
366
367
368 void gettemp(void)
369 {
370 1 unsigned int tp,i;
371 1 init1820();
372 1 write1820(0xcc);
373 1 write1820(0x44);
374 1 init1820();
375 1 write1820(0xcc);
376 1 write1820(0xbe);
377 1 show[0]=read1820();
378 1 show[1]=read1820();
379 1 init1820();
380 1 tp=show[1]*256+show[0];
381 1
382 1 // tp=tmp_real;
383 1 tp=tp>>4;
384 1 // tp=(tp*18+320)/10;
385 1 show[0]=(unsigned char)(tp/10);
386 1 show[1]=(unsigned char)(tp%10);
387 1 if(lcd_page==2)
388 1 {
389 2 gotoxy(0x0a,0x10);
390 2 for(i=0;i<2;i++)
391 2 {
392 3 lcd_regwrite(0x12,0x91);
393 3 lcd_datawrite(show[i]+0x30);
394 3 lcd_regwrite(0x12,0x90);
395 3 }
396 2 }
397 1 }
398
399 void init1820()
400 {
401 1 DQ = 1; _nop_();
402 1 DQ = 0; //?????,??Reset OneWire Bus;
403 1 delay_us(125); //??510us,Reset One-Wire Bus.
404 1 delay_us(125);
405 1
406 1 DQ = 1; //?????;
407 1 delay_us(15); //??35us;
408 1
409 1 while(DQ) //??Slave ??Ack ??;
410 1 { _nop_(); }
411 1 delay_us(60); //??125us;
412 1 DQ = 1; //?????,??????;
413 1 }
414
415 //******write********
416 void write1820(uchar a)
417 {
418 1 uchar i;
419 1 for(i=0;i<8;i++)
420 1 {
421 2 if(a & 0x01) //????;
422 2 {
423 3 DQ = 0; //??Recovery time;
424 3 _nop_();_nop_();_nop_();
425 3 DQ = 1;
426 3 } //????;
427 2 else
C51 COMPILER V8.08 LED 08/20/2008 16:06:02 PAGE 8
428 2 DQ = 0; //??Rec time;
429 2 _nop_();_nop_();_nop_();
430 2 //DQ = 0; } //????;
431 2 delay_us(30); //??Slave Device??;
432 2 DQ = 1; //Recovery;
433 2 _nop_(); //Recovery Time Start;
434 2 a >>= 1;
435 2 }
436 1
437 1 }
438
439 //*******read************
440 unsigned char read1820(void)
441 {
442 1 unsigned char i;
443 1 unsigned char tmp=0;
444 1 DQ = 1; _nop_(); //???;
445 1 for(i=0;i<8;i++)
446 1 {
447 2 tmp >>= 1; //????;
448 2 DQ = 0; //Read init;
449 2 _nop_(); //2ms;
450 2 DQ = 1; //???1,??????????????;
451 2 delay_us(2); //?9us;
452 2 _nop_();
453 2 if(DQ) //?12us?????;
454 2 tmp |= 0x80;
455 2 delay_us(30); //??55us;
456 2 DQ = 1;
457 2 _nop_(); //??One Wire Bus;
458 2 }
459 1 return tmp;
460 1 }
461
462 //**************************????,???1us???????1ms??? **************
463
464 //=============================================
465 uchar touch_test(void) small
466 {
467 1 uchar reg_rddata,reg_rddata1;
468 1
469 1 reg_rddata = lcd_regread(0xc0);
470 1 reg_rddata &= 0xf8;
471 1 reg_rddata |= 0x08;
472 1 lcd_regwrite(0xc0,reg_rddata);
473 1 delay1 (6);
474 1
475 1 reg_rddata1 = lcd_regread(0xc1);
476 1 reg_rddata &= 0xf7;
477 1 lcd_regwrite(0xc0,reg_rddata);
478 1 return(reg_rddata1);
479 1 }
480 //.............................................
481 uint touch_x(void) small
482 {
483 1 uchar reg_rddata,touchxl;
484 1 uint touchx;
485 1
486 1 reg_rddata = lcd_regread(0xc0);
487 1 reg_rddata &= 0xf3;
488 1 reg_rddata |= 0x03;
489 1 lcd_regwrite(0xc0,reg_rddata);
C51 COMPILER V8.08 LED 08/20/2008 16:06:02 PAGE 9
490 1 delay1 (60);
491 1
492 1 touchx = lcd_regread(0xc8); //TPXR
493 1 touchxl = (lcd_regread(0xca)&0xc0); //TPZR
494 1 touchx = (touchx<<2)|(touchxl>>6);
495 1 return(touchx);
496 1 }
497 //.............................................
498 uint touch_y(void) small
499 {
500 1 uchar reg_rddata,touchyl;
501 1 uint touchy;
502 1
503 1 reg_rddata = lcd_regread(0xc0);
504 1 reg_rddata &= 0xfc;
505 1 reg_rddata |= 0x0c;
506 1 lcd_regwrite(0xc0,reg_rddata);
507 1 delay1 (60);
508 1
509 1 touchy = lcd_regread(0xc9); //TPYR
510 1 touchyl = (lcd_regread(0xca)&0x0c); //TPZR
511 1 touchy = (touchy<<2)|(touchyl>>2);
512 1 return(touchy);
513 1 }
514
515 void auto_perform_control()
516 {
517 1 real_temp=show[0]*10+show[1];
518 1 real_humidity=humidity[0]*10+humidity[1];
519 1 real_out_temp=temp[0]*10+temp[1];
520 1 real_out_humidity=out_humidity[0]*10+out_humidity[1];
521 1 // funPMV(It,IRh,change,real_temp,real_humidity,real_out_temp,real_out_humidity);
522 1 // gotoxy(0x02,0x70);
523 1 // lcd_regwrite(0x12,0x91);
524 1 // lcd_datawrite(*It+0x30);
525 1 // lcd_datawrite(*IRh+0x30);
526 1 // lcd_datawrite(*change+0x30);
527 1 // lcd_regwrite(0x12,0x90);
528 1 //status_control(*It,*IRh,*change);
529 1 }
530 void auto_perform()
531 {
532 1 uint i;
533 1
534 1 delay1(10);
535 1 gotoxy(0x00,0x00);
536 1 lcd_regwrite(0x12,0x91); // memory access mode register(awrr)
537 1 lcd_character(tab2,240);
538 1 lcd_regwrite(0x12,0x90); // memory access mode register(awrr)
539 1 gotoxy(0x0a,0x50);
540 1 for(i=0;i<2;i++)
541 1 {
542 2 lcd_regwrite(0x12,0x91);
543 2 lcd_datawrite(dest_tem[i]+0x30);
544 2 lcd_regwrite(0x12,0x90);
545 2 }
546 1 gotoxy(0x0a,0x50);
547 1 for(i=0;i<2;i++)
548 1 {
549 2 lcd_regwrite(0x12,0x91);
550 2 lcd_datawrite(dest_tem[i]+0x30);
551 2 lcd_regwrite(0x12,0x90);
C51 COMPILER V8.08 LED 08/20/2008 16:06:02 PAGE 10
552 2 }
553 1 gotoxy(0x11,0x50);
554 1 for(i=0;i<2;i++)
555 1 {
556 2 lcd_regwrite(0x12,0x91);
557 2 lcd_datawrite(dest_humid[i]+0x30);
558 2 lcd_regwrite(0x12,0x90);
559 2 }
560 1
561 1 function=1;
562 1 lcd_page=2;
563 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -