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

📄 ds1302.lst

📁 DS1302时钟+DS18B20程序 LCD1602显示 51单片机 keil 环境 和大家分享共同学习
💻 LST
📖 第 1 页 / 共 4 页
字号:
 412   1      
 413   1              a=ReadOneChar();        //读取温度值低位
 414   1              b=ReadOneChar();                //读取温度值高位
 415   1              temp_value=b<<4;
 416   1              temp_value+=(a&0xf0)>>4;               
 417   1      }
 418          void temp_to_str()   //温度数据转换成液晶字符显示
 419          {
 420   1        TempBuffer[0]=temp_value/10+'0';  //十位
 421   1        TempBuffer[1]=temp_value%10+'0';  //个位
 422   1        TempBuffer[2]=0xdf;   //温度符号
 423   1        TempBuffer[3]='C';
 424   1        TempBuffer[4]='\0';
 425   1      }
C51 COMPILER V8.02   DS1302                                                                05/12/2008 20:13:04 PAGE 8   

 426          void Delay1ms(unsigned int count)
 427          {
 428   1              unsigned int i,j;
 429   1              for(i=0;i<count;i++)
 430   1              for(j=0;j<120;j++);
 431   1      }
 432          
 433          /*延时子程序*/
 434          void mdelay(uint delay)
 435          {       uint i;
 436   1              for(;delay>0;delay--)
 437   1                      {for(i=0;i<62;i++) //1ms延时.
 438   2                      {;}
 439   2                      }
 440   1      }
 441          
 442          
 443          void outkey()                    //跳出调整模式,返回默认显示
 444          { uchar Second;
 445   1        if(out==0)//||wireless_1==1)         
 446   1        { mdelay(8); 
 447   2              count=0;
 448   2              hide_sec=0,hide_min=0,hide_hour=0,hide_day=0,hide_week=0,hide_month=0,hide_year=0;
 449   2              Second=Read1302(DS1302_SECOND);
 450   2          Write1302(0x8e,0x00); //写入允许
 451   2              Write1302(0x80,Second&0x7f);
 452   2              Write1302(0x8E,0x80);          //禁止写入
 453   2              done=0;           
 454   2              while(out==0);
 455   2              //while(wireless_1==1);
 456   2        }
 457   1      }
 458          //////////////////////////////////////////////////////////////////////////////////////////////////////////
             -//
 459          void Upkey()//升序按键
 460          {          
 461   1                      Up=1;
 462   1                      if(Up==0)//||wireless_2==1)
 463   1                                {
 464   2                                         mdelay(8);
 465   2                                             switch(count)
 466   2                                                {case 1:
 467   3                                        temp=Read1302(DS1302_SECOND);  //读取秒数
 468   3                                                                        temp=temp+1;  //秒数加1
 469   3                                        up_flag=1;    //数据调整后更新标志
 470   3                                                                        if((temp&0x7f)>0x59)   //超过59秒,清零
 471   3                                        temp=0;                                                                 
 472   3                                                                        break;
 473   3                                                 case 2:
 474   3                                        temp=Read1302(DS1302_MINUTE);  //读取分数
 475   3                                                                        temp=temp+1;  //分数加1
 476   3                                        up_flag=1;
 477   3                                                                        if(temp>0x59)          //超过59分,清零
 478   3                                                                        temp=0;
 479   3                                                                        break;
 480   3                                                 case 3:
 481   3                                        temp=Read1302(DS1302_HOUR);  //读取小时数
 482   3                                                                        temp=temp+1;  //小时数加1
 483   3                                        up_flag=1;
 484   3                                                                        if(temp>0x23)   //超过23小时,清零
 485   3                                                                        temp=0;
 486   3                                                                        break;
C51 COMPILER V8.02   DS1302                                                                05/12/2008 20:13:04 PAGE 9   

 487   3                                                 case 4:
 488   3                                        temp=Read1302(DS1302_WEEK);  //读取星期数
 489   3                                                                        temp=temp+1;  //星期数加1
 490   3                                        up_flag=1;
 491   3                                                                        if(temp>0x7)  
 492   3                                                                        temp=1;
 493   3                                                                        break;
 494   3                                                 case 5:
 495   3                                        temp=Read1302(DS1302_DAY);  //读取日数
 496   3                                                                        temp=temp+1;  //日数加1
 497   3                                        up_flag=1;
 498   3                                                                        if(temp>0x31)
 499   3                                                                        temp=1;
 500   3                                                                        break;
 501   3                                                 case 6:
 502   3                                        temp=Read1302(DS1302_MONTH);  //读取月数
 503   3                                                                        temp=temp+1;  //月数加1
 504   3                                        up_flag=1;
 505   3                                                                        if(temp>0x12)
 506   3                                                                        temp=1;
 507   3                                                                        break;
 508   3                                                 case 7:
 509   3                                        temp=Read1302(DS1302_YEAR);  //读取年数
 510   3                                                                        temp=temp+1;  //年数加1
 511   3                                        up_flag=1;
 512   3                                                                        if(temp>0x85)
 513   3                                                                        temp=0;
 514   3                                                                        break;
 515   3                                                     default:break;
 516   3                                                }
 517   2                                                
 518   2                                         while(Up==0);
 519   2                             //while(wireless_2==1);
 520   2                                        }
 521   1      }
 522          
 523          //////////////////////////////////////////////////////////////////////////////////////////////////////////
             -//
 524          void Downkey()//降序按键
 525          {           
 526   1                      Down=1;
 527   1                  if(Down==0)//||wireless_3==1)
 528   1                                {
 529   2                                         mdelay(8);
 530   2                                           switch(count)
 531   2                                                {case 1:
 532   3                                        temp=Read1302(DS1302_SECOND);  //读取秒数
 533   3                                                                        temp=temp-1;                                              //秒数减1
 534   3                                        down_flag=1;       //数据调整后更新标志
 535   3                                                                        if(temp==0x7f)     //小于0秒,返回59秒
 536   3                                                                        temp=0x59;
 537   3                                                                        break;
 538   3                                                 case 2:
 539   3                                        temp=Read1302(DS1302_MINUTE);  //读取分数
 540   3                                                                        temp=temp-1;  //分数减1
 541   3                                        down_flag=1;
 542   3                                                                        if(temp==-1)
 543   3                                                                        temp=0x59;      //小于0秒,返回59秒
 544   3                                                                        break;
 545   3                                                 case 3:
 546   3                                        temp=Read1302(DS1302_HOUR);  //读取小时数
 547   3                                                                        temp=temp-1;  //小时数减1
C51 COMPILER V8.02   DS1302                                                                05/12/2008 20:13:04 PAGE 10  

 548   3                                        down_flag=1;
 549   3                                                                        if(temp==-1)
 550   3                                                                        temp=0x23;
 551   3                                                                        break;
 552   3                                                 case 4:
 553   3                                        temp=Read1302(DS1302_WEEK);  //读取星期数
 554   3                                                                        temp=temp-1;  //星期数减1
 555   3                                        down_flag=1;
 556   3                                                                        if(temp==0)
 557   3                                                                        temp=0x7;;
 558   3                                                                        break;
 559   3                                                 case 5:
 560   3                                        temp=Read1302(DS1302_DAY);  //读取日数
 561   3                                                                        temp=temp-1;  //日数减1
 562   3                                        down_flag=1;
 563   3                                                                        if(temp==0)
 564   3                                                                        temp=31;
 565   3                                                                        break;
 566   3                                                 case 6:
 567   3                                        temp=Read1302(DS1302_MONTH);  //读取月数
 568   3                                                                        temp=temp-1;  //月数减1
 569   3                                        down_flag=1;
 570   3                                                                        if(temp==0)
 571   3                                                                        temp=12;
 572   3                                                                        break;
 573   3                                                 case 7:
 574   3                                        temp=Read1302(DS1302_YEAR);  //读取年数
 575   3                                                                        temp=temp-1;  //年数减1
 576   3                                        down_flag=1;
 577   3                                                                        if(temp==-1)
 578   3                                                                        temp=0x85;
 579   3                                                                        break;
 580   3                                                    default:break;
 581   3                                               }
 582   2                                               
 583   2                                         while(Down==0);
 584   2                                        // while(wireless_3==1);
 585   2                                        }
 586   1      } 
 587          
 588          void Setkey()//模式选择按键
 589          {
 590   1                      Set=1;
 591   1                      if(Set==0)//||wireless_4==1)
 592   1                  {
 593   2                 mdelay(8);
 594   2                 count=count+1;        //Setkey按一次,count就加1
 595   2                         done=1;                       //进入调整模式
 596   2                 while(Set==0);
 597   2                // while(wireless_4==1);
 598   2                       }
 599   1      
 600   1      }
 601          
 602          void keydone()//按键功能执行
 603          {        uchar Second;
 604   1                       if(flag==0)    //关闭时钟,停止计时
 605   1               { Write1302(0x8e,0x00); //写入允许
 606   2                 temp=Read1302(0x80);
 607   2                 Write1302(0x80,temp|0x80);
 608   2                     Write1302(0x8e,0x80); //禁止写入
 609   2                 flag=1;
C51 COMPILER V8.02   DS1302                                                                05/12/2008 20:13:04 PAGE 11  

 610   2               }
 611   1               Setkey();                                          //扫描模式切换按键
 612   1                       switch(count)
 613   1                       {case 1:do                                             //count=1,调整秒
 614   2                                {
 615   3                         outkey();                       //扫描跳出按钮
 616   3                                         Upkey();                //扫描加按钮
 617   3                                         Downkey();              //扫描减按钮
 618   3                                         if(up_flag==1||down_flag==1)  //数据更新,重新写入新的数据

⌨️ 快捷键说明

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