?? xiyiji.lst
字號(hào):
486 { P2=P3=0;
487 1 dingshi();
488 1 while(~pkey())
489 1 {
C51 COMPILER V7.07 XIYIJI 09/11/2005 16:35:01 PAGE 9
490 2 if(sflagg)P2_7=1;
491 2 else P2_7=0;
492 2 pkey();
493 2 if(flag)TR1=0;
494 2 }
495 1 while(1)
496 1 { getkey();
497 2 if((biao==3)||(biao==4)||(biao==5))disp();
498 2 if(biao==6)display();
499 2 }
500 1 }
501 //LCD顯示***************************************************************************
502 unsigned char LCD_Wait(void)
503 {
504 1 LcdRs=0;
505 1 LcdRw=1; //_nop_();
506 1 LcdEn=1; //_nop_();
507 1 LcdEn=0;
508 1 return DBPort;
509 1 }
510 //向LCD寫(xiě)入命令或數(shù)據(jù)************************************************************
511 void LCD_Write(bit style, unsigned char input)
512 {
513 1 LcdEn=0;
514 1 LcdRs=style;
515 1 LcdRw=0; //_nop_();
516 1 DBPort=input; //_nop_();//注意順序
517 1 LcdEn=1; //_nop_();//注意順序
518 1 LcdEn=0; //_nop_();
519 1 LCD_Wait();
520 1 }
521 //初始化LCD*****************************************************************
522 void LCD_Initial()
523 {
524 1 LcdEn=0;
525 1 LCD_Write(LCD_COMMAND,0x38); //8位數(shù)據(jù)端口,2行顯示,5*7點(diǎn)陣
526 1 LCD_Write(LCD_COMMAND,0x38);
527 1 LCD_Write(LCD_COMMAND,0x0c); //開(kāi)啟顯示, 無(wú)光標(biāo)
528 1 LCD_Write(LCD_COMMAND,0x01); //清屏
529 1 LCD_Write(LCD_COMMAND,0x06); //AC遞增, 畫(huà)面不動(dòng)
530 1 }
531 void GotoXY(unsigned char x, unsigned char y)
532 {
533 1 if(y==0)
534 1 LCD_Write(LCD_COMMAND,0x80|x);
535 1 if(y==1)
536 1 LCD_Write(LCD_COMMAND,0x80|(x-0x40));
537 1 }
538 void Print(unsigned char *str)
539 {
540 1 while(*str!='\0')
541 1 {
542 2 LCD_Write(LCD_DATA,*str);
543 2 str++;
544 2 }
545 1 }
546 unsigned char TempBuffer[10];
547 void IntToStr( unsigned char *str)
548 {
549 1 unsigned char a[5]; char i;
550 1 a[0]=minite/10 ; //取得整數(shù)值到數(shù)組
551 1 a[1]=minite%10 ;
C51 COMPILER V7.07 XIYIJI 09/11/2005 16:35:01 PAGE 10
552 1 a[2]=':' ;
553 1 a[3]=second/10;
554 1 a[4]=second%10;
555 1 for(i=0; i<5; i++) //轉(zhuǎn)成ASCII碼
556 1 {if (i!=2) a[i]=a[i]+'0'; }
557 1 for(i=0; i<5; i++)
558 1 { *str=a[i]; str++; } //加入有效的數(shù)字
559 1 *str='\0';
560 1 }
561 unsigned char tep[10];
562 void charToStr( unsigned char *str)
563 {
564 1 unsigned char a[5]; char i, t;
565 1 t= ReadTemperature() ;
566 1 a[0]=' '; //取得整數(shù)值到數(shù)組
567 1 a[1]=(t%100)/10;
568 1 a[2]=(t%100)%10;
569 1 a[3]=0xdf;
570 1 a[4]='c';
571 1 for(i=1; i<3; i++) //轉(zhuǎn)成ASCII碼
572 1 a[i]=a[i]+'0';
573 1 for(i=0; i<5; i++)
574 1 { *str=a[i]; str++; } //加入有效的數(shù)字
575 1 *str='\0';
576 1 }
577 unsigned char wdsz[10];
578 void wdszStr( unsigned char *str)
579 {
580 1 unsigned char a[5]; char i;
581 1 a[0]=' '; //取得整數(shù)值到數(shù)組
582 1 a[1]=(wdz%100)/10;
583 1 a[2]=(wdz%100)%10;
584 1 a[3]=0xdf;
585 1 a[4]='c';
586 1 for(i=1; i<3; i++) //轉(zhuǎn)成ASCII碼
587 1 a[i]=a[i]+'0';
588 1 for(i=0; i<5; i++)
589 1 { *str=a[i]; str++; } //加入有效的數(shù)字
590 1 *str='\0';
591 1 }
592 //顯示當(dāng)前溫度溫度和要達(dá)到的的溫度********************************
593 void display(void)
594 {
595 1 wdszStr(&wdsz[0]);
596 1 GotoXY(8,1);
597 1 Print(&wdsz[0]);
598 1 Delay1ms(100);
599 1 charToStr(&tep[0]);
600 1 GotoXY(8,0);
601 1 Print(&tep[0]);
602 1 Delay1ms(100);
603 1 }
604 //只有時(shí)間的顯示****************************************************
605 void disp(void)
606 {
607 1 IntToStr(&TempBuffer[0]);
608 1 GotoXY(8,1);
609 1 Print(&TempBuffer[0]);
610 1 Delay1ms(100);
611 1 }
612 //定時(shí)器0的使用 實(shí)現(xiàn)倒計(jì)時(shí) 和慢洗衣服時(shí) PWM 比值******************************
613 void daojishi(void)
C51 COMPILER V7.07 XIYIJI 09/11/2005 16:35:01 PAGE 11
614 {
615 1 TMOD=0x02;
616 1 TH0=0x06;
617 1 TL0=0x06;
618 1 TR0=1;
619 1 ET0=1;
620 1 EA=1;
621 1 }
622 void t0(void) interrupt 1 using 0
623 {
624 1 unsigned int tcnt,pwm;
625 1 tcnt++;
626 1 if(tcnt==4000)
627 1 {
628 2 pwm++;
629 2 if(pwm==3)sflag=1;
630 2 if(pwm==9) {sflag=0;pwm=0;}
631 2 tcnt=0;
632 2 second--;
633 2 if(second==0)
634 2 {
635 3 second=59;
636 3 minite--;
637 3 if(minite<=0)
638 3 {
639 4 minite=0;
640 4 }
641 3 }
642 2 }
643 1 }
644 //DS18B20讀取溫度的全部函數(shù)如下***************************************************
645 Init_DS18B20(void)//初始化函數(shù)
646 {
647 1 unsigned char x=0;
648 1 DQ = 1; //DQ復(fù)位
649 1 delay(8); //稍做延時(shí)
650 1 DQ = 0; //單片機(jī)將DQ拉低
651 1 delay(80); //精確延時(shí) 大于 480us
652 1 DQ = 1; //拉高總線
653 1 delay(14);
654 1 x=DQ; //稍做延時(shí)后 如果x=0則初始化成功 x=1則初始化失敗
655 1 delay(20);
656 1 }
657 //讀一個(gè)字節(jié)**********************************************************
658 ReadOneChar(void)
659 {
660 1 unsigned char i=0,dat = 0;
661 1 for (i=8;i>0;i--)
662 1 {
663 2 DQ = 0; // 給脈沖信號(hào)
664 2 dat>>=1;
665 2 DQ = 1; // 給脈沖信號(hào)
666 2 if(DQ)
667 2 dat|=0x80;
668 2 delay(4);
669 2 }
670 1 return(dat);
671 1 }
672 //寫(xiě)入一個(gè)字節(jié)***********************************************************
673 WriteOneChar(unsigned char dat)
674 {
675 1 unsigned char i=0;
C51 COMPILER V7.07 XIYIJI 09/11/2005 16:35:01 PAGE 12
676 1 for (i=8; i>0; i--)
677 1 {
678 2 DQ = 0;
679 2 DQ = dat&0x01;
680 2 delay(5);
681 2 DQ = 1;
682 2 dat>>=1;
683 2 }
684 1 }
685 //讀溫度值*****************************************************************
686 unsigned int ReadTemperature(void)//讀取溫度
687 {
688 1 unsigned char a=0;
689 1 unsigned char b=0;
690 1 unsigned int t=0;
691 1 Init_DS18B20();//初始化
692 1 WriteOneChar(0xCC); // 跳過(guò)讀序號(hào)列號(hào)的操作
693 1 WriteOneChar(0x44); // 啟動(dòng)溫度轉(zhuǎn)換
694 1 Init_DS18B20();//初始化
695 1 WriteOneChar(0xCC); //跳過(guò)讀序號(hào)列號(hào)的操作
696 1 WriteOneChar(0xBE); //讀取溫度寄存器等(共可讀9個(gè)寄存器) 前兩個(gè)就是溫度
697 1 a=ReadOneChar();//讀取低字節(jié)
698 1 b=ReadOneChar();//讀取高字節(jié)
699 1 if((b& 0xf8)!=0x00) //如果是負(fù)數(shù) 則取反加一
700 1 {
701 2 b=~b;
702 2 a=~a;
703 2 a=a+1;
704 2 if(a>255)
705 2 b++;
706 2 }
707 1 b=b<<4;// 高字節(jié)的低4位與低字節(jié)的高4位 組合為溫度值
708 1 b=b & 0x70;
709 1 a=a>>4;
710 1 a=a & 0x0f;
711 1 t=a | b;
712 1 return(t);
713 1 }
714 //**************************************************************************
715
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2483 ----
CONSTANT SIZE = 367 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 39 37
IDATA SIZE = ---- ----
BIT SIZE = 3 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -