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

📄 da1302.lst

📁 利用实时时钟芯片DS1302设计的实时时钟
💻 LST
📖 第 1 页 / 共 4 页
字号:
 230   2          {KeySound();                            //蜂鸣声
 231   3               if(id++==5)                        //1..5为年月日星期 exit
 232   3                id=1;
 233   3               }
 234   2       id_case1_key();                        //日期调整
 235   2       Out_LCM();                     //显示输出
 236   2       } 
 237   1      }
 238          void alarmclockset(void)            //闹铃调整
 239          {id=12;
 240   1       while(model==3)                            //进入闹铃设置
 241   1        {b=1;
C51 COMPILER V8.08   DA1302                                                                09/16/2008 21:50:25 PAGE 5   

 242   2         Modset();                                //模式键是否动作
 243   2         if(b==0)                                       
 244   2          {KeySound();                            //蜂鸣声
 245   3               if(R1302(0xc3)%16==0)
 246   3                 {id=0;model++;}          //0xc2为闹铃开关寄存器。当为关时按下模式键时将退出闹铃设置,当开时进入闹铃时
             -间设置
 247   3              
 248   3               else if(id++==15)                  //12..15为闹铃开关和时间设置 exit
 249   3                    id=12;
 250   3          }
 251   2        id_case1_key();                       //调整
 252   2        Out_LCM();                    //显示输出
 253   2        }
 254   1      } 
 255             
 256          void lampsetup(void)            //背光灯时间设置
 257          {id=10;                                                 //背光灯存储空间DS1302(0xc0)
 258   1        while(model==4)                               //model为3时进入背光灯调整
 259   1        {b=1;
 260   2         Modset();                                    //模式键是否动作
 261   2         if(b==0)
 262   2          {KeySound();                            //蜂鸣声
 263   3               if(id++==11)                       //10为背光灯 exit
 264   3                id=10;
 265   3               }
 266   2       id_case1_key();                        
 267   2       Out_LCM();                     //显示输出                    
 268   2       }
 269   1      
 270   1      }
 271          void  timereset()               //时间清零
 272          {
 273   1        Set1302(inittime);                //清时间
 274   1        W1302(0x90,0xa5);             //打开充电二级管  一个二级管串联一个2K电阻
 275   1        model++; 
 276   1      }
 277          //对相应的项目进行加、减调整。
 278          void id_case1_key()                             //按键处理
 279          {
 280   1        if (TimerUp==0)        //增加
 281   1            {
 282   2             Delay5Ms();
 283   2             if(TimerUp==0)
 284   2                  {a=0;msec=0;KeySound();                     //蜂鸣声
 285   3                       if((id==9)||(id==5)||(id==11)||(id==15))       //当ID为9、5时按下加、减键将退出调整
 286   3                        { model++;                        //退出时间、日期设置
 287   4                          id=0;
 288   4                        }
 289   3                       else
 290   3                     Set(id,1);
 291   3                      }  
 292   2            while(TimerUp==0);    
 293   2           }
 294   1        if (TimerDown==0)  //减少
 295   1           {
 296   2             Delay5Ms();
 297   2             if(TimerDown==0) 
 298   2                  {a=0;msec=0;KeySound();                      //蜂鸣声
 299   3                       if((id==9)||(id==5)||(id==11)||(id==15))  //当ID为9、5时按下加、减键将退出调整
 300   3                        { model++;                         //退出时间、日期设置
 301   4                          id=0;
 302   4                        }
C51 COMPILER V8.08   DA1302                                                                09/16/2008 21:50:25 PAGE 6   

 303   3                 else
 304   3                         Set(id,0);             //调用DS1302写入函数
 305   3                 }          
 306   2            while(TimerDown==0);    
 307   2           }
 308   1      }
 309                           
 310          void timer_1(void) interrupt 1  //中断入口,闪烁
 311          {
 312   1        TH0=0x3c;            //50ms定时
 313   1        TL0=0xb0;
 314   1        if(msec++==10)           //500ms
 315   1         {msec=0;a=~a;       //闪烁标志反转 
 316   2              if(a==0)                   //1秒后背光时间减一秒。
 317   2               LedTime--;
 318   2         }  
 319   1      }
 320          
 321          //根据选择调整相应项目并写入DS1302
 322          void Set(uchar sel,uchar sel_1) 
 323          {
 324   1        uchar address,item;
 325   1        uchar max,min;
 326   1        if(sel==1)  {address=0x8c; max=99;min=0;}    //年
 327   1        if(sel==2)  {address=0x88; max=12;min=1;}    //月
 328   1        if(sel==3)  {address=0x86; max=31;min=1;}    //日
 329   1        if(sel==4)  {address=0x8a; max=7; min=1;}    //星期
 330   1        if(sel==6)  {address=0x84; max=23;min=0;}    //小时
 331   1        if(sel==7)  {address=0x82; max=59;min=0;}    //分钟
 332   1        if(sel==8)  {address=0x80; max=59;min=0;}    //秒
 333   1        if(sel==10) {address=0xc0; max=59;min=0;}    //背光时间,最长1分钟
 334   1        if(sel==12) {address=0xc2; max=1;min=0;}     //闹铃开关寄存器
 335   1        if(sel==13) {address=0xc4; max=23;min=0;}    //闹铃时寄存器
 336   1        if(sel==14) {address=0xc6; max=59;min=0;}    //闹铃分寄存器
 337   1      
 338   1      
 339   1        item=R1302(address+1)/16*10+R1302(address+1)%16;
 340   1        if (sel_1==0) item++;  else item--;
 341   1        if(item>max) item=min;   
 342   1        if(item<min) item=max;
 343   1                 
 344   1        W1302(0x8e,0x00);                   //允许写操作
 345   1        W1302(address,item/10*16+item%10);  //写入DS1302 //转成BCD码
 346   1        W1302(0x8e,0x80);                   //写保护,禁止写操作  
 347   1      }
 348          
 349          //屏幕显示
 350          void Out_LCM(void) 
 351          { switch(model)
 352   1         {
 353   2          case 0: model0(); break;
 354   2              case 1: model1(); break;
 355   2              case 2: model2(); break;                   //在不同的条件下显示不同的字符
 356   2              case 3: model3(); break;
 357   2              case 4: model4(); break;
 358   2              case 5: model5(); break;
 359   2              case 6: model6(); break;
 360   2         }       
 361   1      }
 362          
 363          /***********************model为零时第一行显示时间,不为零时显示system setup******/
 364          void model0()
C51 COMPILER V8.08   DA1302                                                                09/16/2008 21:50:25 PAGE 7   

 365            {                                                                                                                             
 366   1         DisplayListChar(0,0,TIMER);   //显示固定字符串(Time)                                                
 367   1         OutputInformation(13,0,0x20); //不显示
 368   1         OutputInformation(4,0,0x20);  //不显示
 369   1         OutputInformation(4,1,0x20);  //不显示
 370   1         OutputInformation(15,1,0x20); //不显示
 371   1         OutputInformation(7,1,0x2f);  //显示固定字符 "/"
 372   1         OutputInformation(10,1,0x2f); //显示固定字符 "/"
 373   1         OutputInformation(13,1,0x2f); //显示固定字符 "/"
 374   1         DisplayListChar(0,1,DATE);    //显示固定字符串Date(日期)         
 375   1         if(a==1)                                      //冒号闪烁
 376   1          {OutputInformation(7,0,0x3a); OutputInformation(10,0,0x3a);}
 377   1         else
 378   1          {OutputInformation(7,0,0x20); OutputInformation(10,0,0x20);}
 379   1      
 380   1       /*******************model为零时第二行显示日期,不为零显示设置项目*******/
 381   1       
 382   1              OutputInformation(5,1,R1302(0x8d)/16+0x30);  //显示年
 383   1          OutputInformation(6,1,R1302(0x8d)%16+0x30);
 384   1       
 385   1          OutputInformation(8,1,R1302(0x89)/16+0x30);  //显示月 
 386   1          OutputInformation(9,1,R1302(0x89)%16+0x30);    
 387   1            
 388   1          OutputInformation(11,1,R1302(0x87)/16+0x30); //显示日
 389   1          OutputInformation(12,1,R1302(0x87)%16+0x30);    
 390   1      
 391   1          OutputInformation(14,1,R1302(0x8b)%16+0x30); //显示星期
 392   1      
 393   1          OutputInformation(5,0,R1302(0x85)/16+0x30);  //显示小时
 394   1          OutputInformation(6,0,R1302(0x85)%16+0x30); 
 395   1                 
 396   1          OutputInformation(8,0,R1302(0x83)/16+0x30);  //显示分钟
 397   1          OutputInformation(9,0,R1302(0x83)%16+0x30); 
 398   1                 
 399   1          OutputInformation(11,0,R1302(0x81)/16+0x30); //显示秒
 400   1          OutputInformation(12,0,R1302(0x81)%16+0x30); 
 401   1      }
 402            
 403          /*************************model不为零时显示系统设置***********************************/
 404          
 405          
 406                   
 407                                                                    //model为1时time闪烁,按下模式键后进入时间调整
 408          void model1()
 409                   /*************************************判断ID的值来显示项目***********************/
 410          {        OutputInformation(0,0,0x20);          //不显示
 411   1           OutputInformation(1,0,0x20);
 412   1           DisplayListChar(2,0,systemp);         //第一行显示system setup
 413   1            if(id==0)                                                    //为0时显示TIME  date lalcak
 414   1                       {OutputInformation(9,1,0x20);     //不显示
 415   2                    OutputInformation(4,1,0x20);     //不显示
 416   2                        OutputInformation(15,1,0x20);    //不显示
 417   2                        DisplayListChar(5,1,DATE);       //显示date 
 418   2                        DisplayListChar(10,1,alarmclock);//显示lalcak
 419   2                                                                              
 420   2                        if(a==1)
 421   2                       {OutputInformation(0,1,0x20);     //不显示
 422   3                        OutputInformation(1,1,0x20);     //不显示
 423   3                            OutputInformation(2,1,0x20);     //不显示
 424   3                                OutputInformation(3,1,0x20);     //不显示
 425   3                           }
 426   2                    else                                                                                       
C51 COMPILER V8.08   DA1302                                                                09/16/2008 21:50:25 PAGE 8   

 427   2                      DisplayListChar(0,1,TIMER);       //显示time     
 428   2                       }
 429   1                else
 430   1                 {                                                                                         //id不为零进入时间调整项目
 431   2                         OutputInformation(3,1,0x3a);                  //显示固定字符 ":"
 432   2                 OutputInformation(6,1,0x3a);                  //显示固定字符 ":"
 433   2                 OutputInformation(9,1,0x20);                  //不显示
 434   2                         OutputInformation(10,1,0x20);                 //不显示
 435   2                         OutputInformation(0,1,0x20);                  //不显示
 436   2         /****************************时显示闪烁控制********************/
 437   2                         if((id==6)&&(a==1))                                           //id为5时时闪烁
 438   2                      {
 439   3                           OutputInformation(1,1,0x20); //不显示
 440   3                               OutputInformation(2,1,0x20); //不显示
 441   3                              }
 442   2                 else
 443   2                              {OutputInformation(1,1,R1302(0x85)/16+0x30); //显示时
 444   3                   OutputInformation(2,1,R1302(0x85)%16+0x30); 
 445   3                              }
 446   2        /******************************分显示闪烁控制********************/
 447   2                        if((id==7)&&(a==1))                                            //id为6时分闪烁
 448   2                      {
 449   3                           OutputInformation(4,1,0x20); //不显示
 450   3                               OutputInformation(5,1,0x20); //不显示
 451   3                              }
 452   2                        else
 453   2                               {OutputInformation(4,1,R1302(0x83)/16+0x30); //显示分
 454   3                    OutputInformation(5,1,R1302(0x83)%16+0x30); 
 455   3                               }
 456   2        /******************************秒显示闪烁控制********************/
 457   2                        if((id==8)&&(a==1))                                            //id为7时秒闪烁
 458   2                      {
 459   3                           OutputInformation(7,1,0x20); //不显示
 460   3                               OutputInformation(8,1,0x20); //不显示
 461   3                               }
 462   2                              else
 463   2                               {OutputInformation(7,1,R1302(0x81)/16+0x30); //显示秒
 464   3                    OutputInformation(8,1,R1302(0x81)%16+0x30); 

⌨️ 快捷键说明

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