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

📄 51

📁 51单片机大量源码
💻
📖 第 1 页 / 共 3 页
字号:
 340   3              }
 341   2         while(P1_5==0);
 342   2        }
 343   1       if(P1_4==0)
 344   1        {
 345   2         Delay5Ms();
 346   2         if(P1_4==0)
 347   2          {
 348   3               tl--;
 349   3               if(tl<-55) tl=125;
 350   3              }
 351   2        }
 352   1      }
 353          
 354          //设置温度上限
 355          void Set_TH_Temp(void)
 356          {
 357   1       if(P1_5==0)
 358   1        {
 359   2         Delay5Ms();
 360   2         if(P1_5==0)
 361   2          {
 362   3               th++;
 363   3               if(th>125) th=-55;
 364   3               //if(tl<-55) tl=155;
 365   3              }
C51 COMPILER V8.02   CLOCK                                                                 07/24/2009 14:39:44 PAGE 7   

 366   2         while(P1_5==0);
 367   2        }
 368   1       if(P1_4==0)
 369   1        {
 370   2         Delay5Ms();
 371   2         if(P1_4==0)
 372   2          {
 373   3               th--;
 374   3               if(th<-55) th=125;
 375   3              }
 376   2        }
 377   1      }
 378          
 379          void Compare_Temp(signed char l,signed char h)     //比较温度
 380          {
 381   1        unsigned char tl_temp;
 382   1        unsigned char y,s;
 383   1        //unsigned int  x;
 384   1        //unsigned char ct[8];
 385   1        union{byte c[2]; int x;}temp;
 386   1        
 387   1        ow_reset();
 388   1        write_byte(0xCC); // Skip ROM
 389   1        write_byte(0x44); // 转换温度
 390   1        ow_reset();
 391   1        write_byte(0xCC); //Skip ROM
 392   1        write_byte(0xbe); // 读取寄存器
 393   1        temp.c[1]=read_byte();//读出温度低8位
 394   1        temp.c[0]=read_byte();//读出温度高8位
 395   1       
 396   1        // 零下温度判断
 397   1        sflag=0; //温度零下标志 0:零上,1:零下
 398   1        if((temp.c[0]&0xf8)!=0x00)
 399   1         {
 400   2          sflag=1; //零下标志位置1
 401   2          temp.c[1]=~temp.c[1]; //低8位取反
 402   2          temp.c[0]=~temp.c[0]; //高8位取反
 403   2          tl_temp=temp.c[1]+1;  //低8位加1 
 404   2          temp.c[1]=tl_temp;    //计算后重新存入数组
 405   2          if(tl_temp>255) temp.c[0]++;  //如果低8位大于255,向高8位进1
 406   2         }
 407   1        y=0;
 408   1        s=0;
 409   1        y=temp.c[0]<<4;  
 410   1        s=temp.c[1]>>4;
 411   1        y=s|y;
 412   1        //x=((temp.c[0]&0x07)*256+temp.c[1])*.625;
 413   1        if(y<l)
 414   1         
 415   1          tl_flag=1;
 416   1         
 417   1        else
 418   1         
 419   1          tl_flag=0;
 420   1         
 421   1        if(y>h)
 422   1         
 423   1          th_flag=1;
 424   1         
 425   1        else
 426   1         
 427   1          th_flag=0;
C51 COMPILER V8.02   CLOCK                                                                 07/24/2009 14:39:44 PAGE 8   

 428   1         
 429   1      }
 430          
 431          void Tl_Al(void)         //下限越限报?
 432          {
 433   1       if(tl_flag==1)
 434   1        {
 435   2         if(flag==1)
 436   2          {    
 437   3           DisplayOneChar(9,0,'A'); 
 438   3           DisplayOneChar(10,0,'L');        
 439   3          }
 440   2         else
 441   2          {
 442   3           DisplayOneChar(9,0,0x20); 
 443   3           DisplayOneChar(10,0,0x20);    
 444   3          }
 445   2        } 
 446   1       else
 447   1        {
 448   2         DisplayOneChar(9,0,0x20); 
 449   2         DisplayOneChar(10,0,0x20);         
 450   2        }
 451   1      }
 452          
 453          void Th_Al(void)         //上限越限报警
 454          {
 455   1       if(th_flag==1)
 456   1        {
 457   2         if(flag==1)
 458   2          {    
 459   3           DisplayOneChar(13,0,'A'); 
 460   3           DisplayOneChar(14,0,'H');        
 461   3          }
 462   2         else
 463   2          {
 464   3           DisplayOneChar(13,0,0x20); 
 465   3           DisplayOneChar(14,0,0x20);    
 466   3          }
 467   2        } 
 468   1       else
 469   1        {
 470   2         DisplayOneChar(13,0,0x20); 
 471   2         DisplayOneChar(14,0,0x20);         
 472   2        }
 473   1      }
 474          
 475          
 476          
 477          //中断入口,冒号闪烁
 478          void t0(void) interrupt 1 using 0
 479          {
 480   1        TH0=(65535-50000)/256; //50ms定时
 481   1        TL0=(65535-50000)%256;  
 482   1        timecount++;
 483   1        if(timecount>9)
 484   1         {
 485   2          timecount=0;    
 486   2          flag=~flag;             
 487   2         }  
 488   1      }
 489          //id为1时的下一级选择
C51 COMPILER V8.02   CLOCK                                                                 07/24/2009 14:39:44 PAGE 9   

 490          void id_case1_key()
 491          {
 492   1        if (P1_5==0) //增加
 493   1            {
 494   2             Delay5Ms();
 495   2             if(P1_5==0) Set(id,0);  
 496   2             if(id!=7)  while(P1_5==0);    
 497   2            }
 498   1         if (P1_4==0)  //减少
 499   1            {
 500   2             Delay5Ms();
 501   2             if(P1_4==0) Set(id,1);          
 502   2             if(id!=7) while(P1_4==0);    
 503   2            }
 504   1      }
 505          
 506          //根据选择调整相应项目并写入DS1302
 507          void Set(uchar sel,uchar sel_1) 
 508          {
 509   1        signed char address,item;
 510   1        signed char max,mini;
 511   1        if(sel==7)  {address=0x80; max=0;mini=0;}     //秒
 512   1        if(sel==6)  {address=0x82; max=59;mini=0;}    //分钟
 513   1        if(sel==5)  {address=0x84; max=23;mini=0;}    //小时
 514   1        if(sel==3)  {address=0x86; max=31;mini=1;}    //日
 515   1        if(sel==2)  {address=0x88; max=12;mini=1;}    //月
 516   1        if(sel==1)  {address=0x8c; max=99;mini=0;}    //年
 517   1        if(sel==4)  {address=0x8a; max=7; mini=1;}    //星期
 518   1        
 519   1        item=R1302(address+1)/16*10+R1302(address+1)%16;
 520   1        if (sel_1==0) item++;  else item--;
 521   1        if(item>max) item=mini;   
 522   1        if(item<mini) item=max;
 523   1                 
 524   1        W1302(0x8e,0x00);//允许写操作
 525   1        W1302(address,item/10*16+item%10);
 526   1        W1302(0x8e,0x80);//写保护,禁止写操作  
 527   1      }
 528          
 529          //屏幕显示第一行 时间和温度
 530          void Disp_line1(void) 
 531          {  
 532   1        Read_Temperature(10,0); //温度显示
 533   1        //冒号闪烁     
 534   1        if(flag==0)
 535   1          {DisplayOneChar(3,0,0x3a); DisplayOneChar(6,0,0x3a);}
 536   1        else
 537   1          {DisplayOneChar(3,0,0x20); DisplayOneChar(6,0,0x20);}
 538   1      
 539   1        if(sec==1)  //秒闪烁标志位
 540   1          {
 541   2           if(flag==1)
 542   2             {    
 543   3              DisplayOneChar(7,0,R1302(0x81)/16+0x30); //显示秒
 544   3              DisplayOneChar(8,0,R1302(0x81)%16+0x30);        
 545   3             }
 546   2           else
 547   2             {
 548   3              DisplayOneChar(7,0,0x20); //显示秒
 549   3              DisplayOneChar(8,0,0x20);    
 550   3             }
 551   2          } 
C51 COMPILER V8.02   CLOCK                                                                 07/24/2009 14:39:44 PAGE 10  

 552   1        else
 553   1          {
 554   2           DisplayOneChar(7,0,R1302(0x81)/16+0x30); //显示秒
 555   2           DisplayOneChar(8,0,R1302(0x81)%16+0x30);         
 556   2          }    
 557   1         
 558   1        if(min==1)  //分钟闪烁标志位
 559   1          {
 560   2           if(flag==1)
 561   2             {    
 562   3              DisplayOneChar(4,0,R1302(0x83)/16+0x30); //显示分钟
 563   3              DisplayOneChar(5,0,R1302(0x83)%16+0x30);        
 564   3             }
 565   2           else
 566   2             {
 567   3              DisplayOneChar(4,0,0x20); //显示分钟
 568   3              DisplayOneChar(5,0,0x20);    
 569   3             }
 570   2          } 
 571   1        else
 572   1          {
 573   2           DisplayOneChar(4,0,R1302(0x83)/16+0x30); //显示分钟
 574   2           DisplayOneChar(5,0,R1302(0x83)%16+0x30);         
 575   2          } 
 576   1      
 577   1        if(hour==1)  //小时闪烁标志位
 578   1          {
 579   2           if(flag==1)
 580   2             {    
 581   3              DisplayOneChar(1,0,R1302(0x85)/16+0x30);//显示小时
 582   3              DisplayOneChar(2,0,R1302(0x85)%16+0x30); 
 583   3             }
 584   2           else
 585   2             {
 586   3              DisplayOneChar(1,0,0x20); //显示小时
 587   3              DisplayOneChar(2,0,0x20);    
 588   3             }
 589   2          } 
 590   1        else
 591   1         { 
 592   2          DisplayOneChar(1,0,R1302(0x85)/16+0x30);//显示小时
 593   2          DisplayOneChar(2,0,R1302(0x85)%16+0x30);
 594   2         }
 595   1      }
 596          
 597          // 屏幕显示第二行  日期和星期   
 598          void Disp_line2(void)
 599          {
 600   1        DisplayOneChar(3,1,0x2f); //显示固定字符
 601   1        DisplayOneChar(6,1,0x2f);
 602   1        DisplayListChar(10,1,week);
 603   1          
 604   1        if(year==1)  //年闪烁标志位
 605   1          {
 606   2           if(flag==1)
 607   2             {    
 608   3              DisplayOneChar(1,1,R1302(0x8d)/16+0x30);//显示年
 609   3              DisplayOneChar(2,1,R1302(0x8d)%16+0x30);
 610   3             }
 611   2           else
 612   2             {
 613   3              DisplayOneChar(1,1,0x20); //显示年
C51 COMPILER V8.02   CLOCK                                                                 07/24/2009 14:39:44 PAGE 11  

 614   3              DisplayOneChar(2,1,0x20);    
 615   3             }
 616   2          } 
 617   1        else
 618   1          { 
 619   2            DisplayOneChar(1,1,R1302(0x8d)/16+0x30);//显示年
 620   2            DisplayOneChar(2,1,R1302(0x8d)%16+0x30);
 621   2          }
 622   1           
 623   1        if(mon==1)  //月闪烁标志位
 624   1          {
 625   2           if(flag==1)
 626   2             {    
 627   3              DisplayOneChar(4,1,R1302(0x89)/16+0x30);//显示月 
 628   3              DisplayOneChar(5,1,R1302(0x89)%16+0x30);
 629   3             }
 630   2           else
 631   2             {
 632   3              DisplayOneChar(4,1,0x20); //显示月
 633   3              DisplayOneChar(5,1,0x20);    
 634   3             }
 635   2          } 
 636   1        else
 637   1          { 
 638   2            DisplayOneChar(4,1,R1302(0x89)/16+0x30);//显示月 
 639   2            DisplayOneChar(5,1,R1302(0x89)%16+0x30);
 640   2          }   
 641   1      
 642   1        if(day==1)  //日闪烁标志位
 643   1          {
 644   2           if(flag==1)
 645   2             {    
 646   3               DisplayOneChar(7,1,R1302(0x87)/16+0x30);//显示日
 647   3               DisplayOneChar(8,1,R1302(0x87)%16+0x30);
 648   3             }
 649   2           else
 650   2             {
 651   3              DisplayOneChar(7,1,0x20); //显示日
 652   3              DisplayOneChar(8,1,0x20);    
 653   3             }
 654   2          } 
 655   1        else
 656   1          { 
 657   2            DisplayOneChar(7,1,R1302(0x87)/16+0x30);//显示日
 658   2            DisplayOneChar(8,1,R1302(0x87)%16+0x30);
 659   2          }
 660   1          
 661   1         if(weekk==1)  //星期闪烁标志位
 662   1          {
 663   2           if(flag==1)
 664   2             {    
 665   3               DisplayOneChar(15,1,R1302(0x8b)%16+0x30);//显示星期
 666   3             }
 667   2           else
 668   2             {
 669   3              DisplayOneChar(15,1,0x20); //显示星期          
 670   3             }
 671   2          } 
 672   1        else
 673   1          { 
 674   2            DisplayOneChar(15,1,R1302(0x8b)%16+0x30);//显示星期
 675   2          }     
C51 COMPILER V8.02   CLOCK                                                                 07/24/2009 14:39:44 PAGE 12  

 676   1      }
 677          
 678          //********* LCM1602驱动程序 ***************
 679          //写数据
 680          void WriteDataLCM(unsigned char WDLCM)
 681          {
 682   1        ReadStatusLCM(); //检测忙
 683   1        LCM_Data = WDLCM;
 684   1        LCM_RS = 1;
 685   1        LCM_RW = 0;

⌨️ 快捷键说明

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