⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.lst

📁 89C52单片机12M晶振下DS18B20温度传感器测量温度应用子程序源码
💻 LST
📖 第 1 页 / 共 3 页
字号:
 511   1         minute=DS_minute;
 512   1         hour=DS_hour;
 513   1      
 514   1              buffer[7]=LedCode[hour/10];//小时的十位
 515   1              buffer[6]=LedCode[hour%10];//小时的个位
 516   1              buffer[5]=LedCode[21];
 517   1              buffer[4]=LedCode[minute/10];//分钟的十位
 518   1              buffer[3]=LedCode[minute%10];//分钟的个位
 519   1              buffer[2]=LedCode[21];
 520   1              buffer[1]=LedCode[second/10];//秒钟的十位
 521   1              buffer[0]=LedCode[second%10];//秒钟的个位
 522   1      
 523   1              display();
 524   1              
 525   1      }
 526          /**************************************************
 527          //日期读取、显示函数
 528          **************************************************/
 529          void day_display()
 530          {
 531   1         uchar day,month,year;
 532   1      
 533   1         day=DS_day;
 534   1         month=DS_month;
 535   1         year=DS_year;
 536   1      
 537   1          buffer[7]=LedCode[year/10];//年的第三位
 538   1          buffer[6]=LedCode[year%10];//年的第四位
 539   1          buffer[5]=0x84;
 540   1          buffer[4]=LedCode[month/10];//月份的十位
 541   1          buffer[3]=LedCode[month%10];//月份的个位
 542   1          buffer[2]=0x84;
 543   1          buffer[1]=LedCode[day/10];//日的十位
 544   1          buffer[0]=LedCode[day%10];//日的个位
 545   1      
 546   1              display();
 547   1              }
 548          
 549          /************************************************
 550          //ds12887初实化程序
C51 COMPILER V7.09   MAIN                                                                  05/28/2005 18:15:36 PAGE 10  

 551          ************************************************/
 552          void init_ds12887(void)
 553          {
 554   1              delay(100);
 555   1              DS_A=0x70;              //DV2~DV0=111,分频复位
 556   1              DS_B=0x8e;              //停止更新,允许更新中断,选BCD码,24小时制
 557   1              DS_second=0x00;                 //00秒
 558   1              DS_minute=0x00;                 //00分
 559   1              DS_hour=0x00;                   //00时
 560   1              DS_day=0x00;                    //00号
 561   1              DS_month=0x00;                  //00月
 562   1              DS_year=0x05;                   //2005年
 563   1              DS_A=0x26;              //DV2~DV0=010  RS3~RS0=0110,选周期中断率为976.5625μs,允许方波输出,频率1kHz
 564   1              DS_B=0x1e;              //每秒更新一次,允许方波输出,24小时制,时钟开始运行
 565   1      }
 566          
 567          /****************************************************
 568          //时间修改函数
 569          *****************************************************/
 570          void time_change()
 571          { 
 572   1        uchar j;
 573   1        uchar second,minute,hour; 
 574   1        uchar day,month,year;
 575   1        if(b_times==1)//第一次按下修改健时
 576   1        {
 577   2              if(!flag&&!figure)//第一次运行时取得时间和日期的同步    
 578   2              {
 579   3                      day=DS_day;
 580   3                      month=DS_month;
 581   3                      year=DS_year;
 582   3                      second=DS_second;
 583   3                      minute=DS_minute;
 584   3                      hour=DS_hour;
 585   3      
 586   3         t_chan[9]=day/10;
 587   3         t_chan[8]=day%10;
 588   3         t_chan[10]=21;
 589   3         t_chan[12]=month/10;
 590   3         t_chan[11]=month%10;
 591   3         t_chan[13]=21;
 592   3         t_chan[15]=year/10;
 593   3         t_chan[14]=year%10;
 594   3      
 595   3         t_chan[7]=hour/10;//小时的十位
 596   3         t_chan[6]=hour%10;//小时的个位
 597   3         t_chan[5]=21;
 598   3         t_chan[4]=minute/10;//分钟的十位
 599   3         t_chan[3]=minute%10;//分钟的个位
 600   3         t_chan[2]=21;
 601   3         t_chan[1]=second/10;//秒钟的十位
 602   3         t_chan[0]=second%10;//秒钟的个位
 603   3      
 604   3         }
 605   2      //=============================================   
 606   2         if(flag)
 607   2         {
 608   3         switch(a_move)
 609   3         {
 610   4         case 0:t_chan[0]=status;break;
 611   4         case 1:if(status>=0&&status<6)t_chan[1]=status;break;
 612   4         
C51 COMPILER V7.09   MAIN                                                                  05/28/2005 18:15:36 PAGE 11  

 613   4         case 3:t_chan[3]=status;break;
 614   4         case 4:if(status>=0&&status<6)t_chan[4]=status;break;
 615   4         
 616   4         case 6:t_chan[6]=status;break;
 617   4         case 7:if(status>=0&&status<3)t_chan[7]=status;break;
 618   4         
 619   4         case 8:t_chan[8]=status;break;
 620   4         case 9:if(status>=0&&status<4)t_chan[9]=status;break;
 621   4         
 622   4         case 11:if(t_chan[12]==0)t_chan[11]=status;
 623   4                 else if(status>=0&&status<3)t_chan[11]=status;break;
 624   4         case 12:if(status>=0&&status<2)t_chan[12]=status;break;
 625   4         
 626   4         case 14:t_chan[14]=status;break;
 627   4         case 15:t_chan[15]=status;break;
 628   4         
 629   4         default:;break;
 630   4         }
 631   3         }
 632   2      //============================================================
 633   2          if(a_move<8)
 634   2          {//此时显示时间
 635   3                 for(j=0;j<8;j++)buffer[j]=LedCode[t_chan[j]];//
 636   3                 if(t_half)buffer[a_move]=LedCode[25];
 637   3          }
 638   2          else 
 639   2          {
 640   3              for(j=0;j<8;j++)buffer[j]=LedCode[t_chan[8+j]];//此时显示日期
 641   3              if(t_half)buffer[a_move-8]=LedCode[25];
 642   3          }
 643   2      //========================================   
 644   2         display();
 645   2         
 646   2      }
 647   1      
 648   1         if(b_times==2)//再次按下修改键,修改时间确立
 649   1         {
 650   2          delay(100);
 651   2              DS_A=0x70;              //DV2~DV0=111,分频复位
 652   2              DS_B=0x8e;              //停止更新,允许更新中断,选BCD码,24小时制
 653   2              DS_second=t_chan[1]*10+t_chan[0];                       //25秒
 654   2              DS_minute=t_chan[4]*10+t_chan[3];                       //27分
 655   2              DS_hour=t_chan[7]*10+t_chan[6];                 //00时
 656   2              DS_day=t_chan[9]*10+t_chan[8];                  //23号
 657   2              DS_month=t_chan[12]*10+t_chan[11];                      //4月
 658   2              DS_year=t_chan[15]*10+t_chan[14];                       //2005年
 659   2              DS_A=0x26;              //DV2~DV0=010  RS3~RS0=0110,选周期中断率为976.5625μs,允许方波输出,频率1kHz
 660   2              DS_B=0x1e;              //每秒更新一次,允许方波输出,24小时制,时钟开始运行
 661   2      
 662   2              b_times=0;//把修改键按下的次数定为0
 663   2              f_time=1;//把显示调回到时间
 664   2              a_move=3;//把移动初值移回到第4位
 665   2              b_change=0;//把修改标志位设成
 666   2              figure=0;//
 667   2              }
 668   1      }
 669          
 670          /******************************************************
 671                  显示温度函数
 672          ******************************************************/
 673          void dis_temp(uint i,bit b)
 674          {
C51 COMPILER V7.09   MAIN                                                                  05/28/2005 18:15:36 PAGE 12  

 675   1              uint temp=i;
 676   1              buffer[7]=0xCB;
 677   1              if (e_shift)//放大100倍,显示华氏温度,进行温度转化
 678   1              {
 679   2                      temp=(temp-3200)*5/9;
 680   2                      buffer[7]=0xCE;
 681   2              }
 682   1      
 683   1               buffer[0]=LedCode[temp%100/10];//小数位,写7218B存储器
 684   1                       buffer[1]=0x00;
 685   1                       buffer[2]=LedCode[temp%1000/100];//个位数
 686   1                       buffer[3]=LedCode[temp%10000/1000];//十位数
 687   1                       buffer[4]=LedCode[temp/10000];//求每一位上的数,百位数
 688   1                       if(b)buffer[5]=LedCode[21];//对符号位进行判断
 689   1                       else buffer[5]=LedCode[25];             
 690   1                       
 691   1                       display();
 692   1      }       
 693          /*****************************************************
 694          **********************主函数**************************
 695          *****************************************************/
 696          void main()
 697          {       
 698   1              IP=0x04;
 699   1              IE=0x86;
 700   1              TMOD=0x01;
 701   1          TH0=-2000/256;
 702   1          TL0=-2000%256;
 703   1              TR0=1;
 704   1              IT1=1;
 705   1              init_ds12887();
 706   1              DS1820_system_Init();
 707   1          
 708   1      
 709   1              while(1)
 710   1              {
 711   2              if(c_temp)
 712   2              {
 713   3                      if(c_shift)
 714   3                      {
 715   4                              buffer[6]=LedCode[1];
 716   4                              dis_temp(temp1,mark_0);
 717   4                      }
 718   3                      else
 719   3                      {
 720   4                              buffer[6]=LedCode[2];
 721   4                              dis_temp(temp2,mark_1);
 722   4                      }
 723   3              }
 724   2                              
 725   2                             
 726   2              if(d_temp)
 727   2              {
 728   3                      if(d_shift)
 729   3                      {
 730   4                              buffer[6]=LedCode[1];
 731   4                              dis_temp(t_set1,mark_2);//显示温度2函数       
 732   4                      }
 733   3                      else
 734   3                      {
 735   4                              buffer[6]=LedCode[2];
 736   4                              dis_temp(t_set1,mark_2);//显示温度2函数
C51 COMPILER V7.09   MAIN                                                                  05/28/2005 18:15:36 PAGE 13  

 737   4                      }
 738   3              }
 739   2              if(f_time)//显示时间、日期函数
 740   2              {
 741   3                     if(choose)time_display();
 742   3                     else day_display();
 743   3              }
 744   2      
 745   2              if(b_change)time_change();//时间修改函数
 746   2              
 747   2              get_temperature_0_DS1820();
 748   2              get_temperature_1_DS1820();        
 749   2          //两个温度的读取函数
 750   2      
 751   2          
 752   2              delay(2000);
 753   2          }
 754   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1923    ----
   CONSTANT SIZE    =     40    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     51       5
   IDATA SIZE       =   ----    ----
   BIT SIZE         =     19       3
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -