📄 ds1302.lst
字号:
469 2 if(TempBuffer[1]=='1')
470 2 {
471 3 TempBuffer[1]='1';
472 3 }
473 2 else
474 2 {
475 3 TempBuffer[1]=' ';
476 3 }
477 2 }
478 1 }
479
480 void temp_to_str() //温度数据转换成液晶字符显示
481 {
482 1
483 1 TempBuffer[2]=temp_value%100/10+'0'; //十位
484 1 TempBuffer[3]=temp_value%10+'0'; //个位
485 1 TempBuffer[4]='.';
486 1 TempBuffer[5]=temp1_value*625/1000%10+'0';
C51 COMPILER V7.06 DS1302 02/28/2009 00:12:56 PAGE 9
487 1 TempBuffer[6]=temp1_value*625/100%10+'0';
488 1 TempBuffer[7]=temp1_value*625/10%10+'0';
489 1 //TempBuffer[8]=temp1_value*625%10+'0';
490 1 TempBuffer[8]='\0';
491 1 }
492
493 //**********************************************
494 //延时子程序模块
495 //**********************************************
496 void mdelay(uint delay)
497 { uint i;
498 1 for(;delay>0;delay--)
499 1 {for(i=0;i<80;i++) //1ms延时.
500 2 {;}
501 2 }
502 1 }
503
504 //************************************************
505 //按键设置程序模块
506 //************************************************
507
508 //*************************
509 //升序按键
510 //*************************
511 void Upkey()
512 {
513 1 Up=1;
514 1 if(Up==0)
515 1 {
516 2 mdelay(5);
517 2 switch(count)
518 2 {case 1:
519 3 temp=Read1302(DS1302_SECOND); //读取秒数
520 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
521 3 temp=temp+1; //秒数加1
522 3 up_flag=1; //数据调整后更新标志
523 3 if((temp)>59) //超过59秒,清零
524 3 temp=0;
525 3 temp=temp/10*16+temp%10;
526 3 break;
527 3 case 2:
528 3 temp=Read1302(DS1302_MINUTE); //读取分数
529 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
530 3 temp=temp+1; //分数加1
531 3 up_flag=1;
532 3 if(temp>59) //超过59分,清零
533 3 temp=0;
534 3 temp=temp/10*16+temp%10;
535 3 break;
536 3 case 3:
537 3 temp=Read1302(DS1302_HOUR); //读取小时数
538 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
539 3 temp=temp+1; //小时数加1
540 3 up_flag=1;
541 3 if(temp>23) //超过23小时,清零
542 3 temp=0;
543 3 temp=temp/10*16+temp%10;
544 3 break;
545 3 case 4:
546 3 temp=Read1302(DS1302_WEEK); //读取星期数
547 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
548 3 temp=temp+1; //星期数加1
C51 COMPILER V7.06 DS1302 02/28/2009 00:12:56 PAGE 10
549 3 up_flag=1;
550 3 if(temp>7)
551 3 temp=1;
552 3 temp=temp/10*16+temp%10;
553 3 break;
554 3 case 5:
555 3 temp=Read1302(DS1302_DAY); //读取日数
556 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
557 3 temp=temp+1; //日数加1
558 3 up_flag=1;
559 3 if(temp>31)
560 3 temp=1;
561 3 temp=temp/10*16+temp%10;
562 3 break;
563 3 case 6:
564 3 temp=Read1302(DS1302_MONTH); //读取月数
565 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
566 3 temp=temp+1; //月数加1
567 3 up_flag=1;
568 3 if(temp>12)
569 3 temp=1;
570 3 temp=temp/10*16+temp%10;
571 3 break;
572 3 case 7:
573 3 temp=Read1302(DS1302_YEAR); //读取年数
574 3 temp=((temp&0xf0)>>4)*10 + (temp&0x0F);
575 3 temp=temp+1; //年数加1
576 3 up_flag=1;
577 3 if(temp>99)
578 3 temp=0;
579 3 temp=temp/10*16+temp%10;
580 3 break;
581 3 default:break;
582 3 }
583 2
584 2 // while(Up==0);
585 2 }
586 1 }
587
588 //////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
589 //************************
590 //降序按键
591 //************************
592 void Downkey()
593 {
594 1 Down=1;
595 1 if(Down==0)
596 1 {
597 2 mdelay(5);
598 2 switch(count)
599 2 {case 1:
600 3 temp=Read1302(DS1302_SECOND); //读取秒数
601 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
602 3 temp=temp-1; //秒数减1
603 3 down_flag=1; //数据调整后更新标志
604 3 if(temp==-1) //小于0秒,返回59秒
605 3 temp=59;
606 3 temp=temp/10*16+temp%10;
607 3 break;
608 3 case 2:
609 3 temp=Read1302(DS1302_MINUTE); //读取分数
C51 COMPILER V7.06 DS1302 02/28/2009 00:12:56 PAGE 11
610 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
611 3 temp=temp-1; //分数减1
612 3 down_flag=1;
613 3 if(temp==-1)
614 3 temp=59; //小于0秒,返回59秒
615 3 temp=temp/10*16+temp%10;
616 3 break;
617 3 case 3:
618 3 temp=Read1302(DS1302_HOUR); //读取小时数
619 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
620 3 temp=temp-1; //小时数减1
621 3 down_flag=1;
622 3 if(temp==-1)
623 3 temp=23;
624 3 temp=temp/10*16+temp%10;
625 3 break;
626 3 case 4:
627 3 temp=Read1302(DS1302_WEEK); //读取星期数;
628 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
629 3 temp=temp-1; //星期数减1
630 3 down_flag=1;
631 3 if(temp==0)
632 3 temp=7;
633 3 temp=temp/10*16+temp%10;
634 3 break;
635 3 case 5:
636 3 temp=Read1302(DS1302_DAY); //读取日数
637 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
638 3 temp=temp-1; //日数减1
639 3 down_flag=1;
640 3 if(temp==0)
641 3 temp=31;
642 3 temp=temp/10*16+temp%10;
643 3 break;
644 3 case 6:
645 3 temp=Read1302(DS1302_MONTH); //读取月数
646 3 temp=((temp&0x70)>>4)*10 + (temp&0x0F);
647 3 temp=temp-1; //月数减1
648 3 down_flag=1;
649 3 if(temp==0)
650 3 temp=12;
651 3 temp=temp/10*16+temp%10;
652 3 break;
653 3 case 7:
654 3 temp=Read1302(DS1302_YEAR); //读取年数
655 3 temp=((temp&0xf0)>>4)*10 + (temp&0x0F);
656 3 temp=temp-1; //年数减1
657 3 down_flag=1;
658 3 if(temp==-1)
659 3 temp=99;
660 3 temp=temp/10*16+temp%10;
661 3 break;
662 3 default:break;
663 3 }
664 2
665 2 // while(Down==0);
666 2 }
667 1 }
668
669 //**************************
670 //模式选择按键
671 //**************************
C51 COMPILER V7.06 DS1302 02/28/2009 00:12:56 PAGE 12
672 void Setkey()
673 {
674 1 Set=1;
675 1 if(Set==0)
676 1 {
677 2 mdelay(5);
678 2 count=count+1; //Setkey按一次,count就加1
679 2 done=1; //进入调整模式
680 2 while(Set==0);
681 2 }
682 1
683 1 }
684
685 //*************************
686 //按键功能执行
687 //*************************
688 void keydone()
689 { uchar Second;
690 1 /* if(flag==0) //关闭时钟,停止计时
691 1 { Write1302(0x8e,0x00); //写入允许
692 1 temp=Read1302(0x80);
693 1 Write1302(0x80,temp|0x80);
694 1 Write1302(0x8e,0x80); //禁止写入
695 1 flag=1;
696 1 }*/
697 1 Setkey(); //扫描模式切换按键
698 1 switch(count)
699 1 {case 1:do //count=1,调整秒
700 2 {
701 3
702 3 Upkey(); //扫描加按钮
703 3 Downkey(); //扫描减按钮
704 3 if(up_flag==1||down_flag==1) //数据更新,重新写入新的数据
705 3 {
706 4 Write1302(0x8e,0x00); //写入允许
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -