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

📄 1602.lst

📁 单片机项目19-电子日历(1602显示)
💻 LST
📖 第 1 页 / 共 4 页
字号:
 402   1              delay_18B20(100);
 403   1      
 404   1              a=ReadOneChar();        //读取温度值低位
 405   1              b=ReadOneChar();                //读取温度值高位
 406   1              temp_value=b<<4;
 407   1              temp_value+=(a&0xf0)>>4;               
 408   1      }
 409          void temp_to_str()   //温度数据转换成液晶字符显示
 410          {
 411   1        TempBuffer[0]=temp_value/10+'0';  //十位
 412   1        TempBuffer[1]=temp_value%10+'0';  //个位
 413   1        TempBuffer[2]=0xdf;   //温度符号
 414   1        TempBuffer[3]='C';
 415   1        TempBuffer[4]='\0';
 416   1      }
 417          void Delay1ms(unsigned int count)
 418          {
 419   1              unsigned int i,j;
 420   1              for(i=0;i<count;i++)
 421   1              for(j=0;j<120;j++);
 422   1      }
 423          
 424          /*延时子程序*/
 425          void mdelay(uint delay)
C51 COMPILER V8.02   1602                                                                  04/07/2012 10:23:53 PAGE 8   

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

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

 548   3                                                 case 5:
 549   3                                        temp=Read1302(DS1302_DAY);  //读取日数
 550   3                                                                        temp=temp-1;  //日数减1
 551   3                                        down_flag=1;
 552   3                                                                        if(temp==0)
 553   3                                                                        temp=31;
 554   3                                                                        break;
 555   3                                                 case 6:
 556   3                                        temp=Read1302(DS1302_MONTH);  //读取月数
 557   3                                                                        temp=temp-1;  //月数减1
 558   3                                        down_flag=1;
 559   3                                                                        if(temp==0)
 560   3                                                                        temp=12;
 561   3                                                                        break;
 562   3                                                 case 7:
 563   3                                        temp=Read1302(DS1302_YEAR);  //读取年数
 564   3                                                                        temp=temp-1;  //年数减1
 565   3                                        down_flag=1;
 566   3                                                                        if(temp==-1)
 567   3                                                                        temp=0x85;
 568   3                                                                        break;
 569   3                                                    default:break;
 570   3                                               }
 571   2                                               
 572   2                                         while(Down==0);
 573   2                                        }
 574   1      }
 575          
 576          void Setkey()//模式选择按键
 577          {
 578   1                      Set=1;
 579   1                      if(Set==0)
 580   1                  {
 581   2                 mdelay(8);
 582   2                 count=count+1;        //Setkey按一次,count就加1
 583   2                         done=1;                       //进入调整模式
 584   2                 while(Set==0);
 585   2                       }
 586   1      
 587   1      }
 588          
 589          void keydone()//按键功能执行
 590          {        uchar Second;
 591   1                       if(flag==0)    //关闭时钟,停止计时
 592   1               { Write1302(0x8e,0x00); //写入允许
 593   2                 temp=Read1302(0x80);
 594   2                 Write1302(0x80,temp|0x80);
 595   2                     Write1302(0x8e,0x80); //禁止写入
 596   2                 flag=1;
 597   2               }
 598   1               Setkey();                                          //扫描模式切换按键
 599   1                       switch(count)
 600   1                       {case 1:do                                             //count=1,调整秒
 601   2                                {
 602   3                         outkey();                       //扫描跳出按钮
 603   3                                         Upkey();                //扫描加按钮
 604   3                                         Downkey();              //扫描减按钮
 605   3                                         if(up_flag==1||down_flag==1)  //数据更新,重新写入新的数据

⌨️ 快捷键说明

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