📄 ds1302+lcd1602-c51.lst
字号:
524 3 }
525 2 //---------------------------------------------------------
526 2 if(!K3&flag) //开始设定时间
527 2 {
528 3 delay1(35); //消除抖动
529 3 if(!K3&flag)
530 3 {
531 4 write_ds1302(0x8e,0x00); //写保护控制字,允许写
532 4 write_ds1302(0x80,0x80); //停止时钟运行
533 4 write_ds1302(0x8e,0x80); //写保护控制字,禁止写
534 4 beep();
535 4 year=1;
536 4 count=((init[6]&0xf0)>>4)*10+(init[6]&0x0f); //读当前年数据
537 4 }
538 3 }
539 2 while(year) //设定年
540 2 {
541 3 key_set(99,1,1); // 键设定函数
542 3 if(!K3)
543 3 {
544 4 delay1(35); //消除抖动
545 4 if(!K3)
546 4 {
547 5 Set_W1302(0x8c); // 设定值写入DS1302
548 5 Set_place(1,1); // 指定位置显示
549 5 year=0;
C51 COMPILER V8.02 DS1302_LCD1602_C51 01/22/2008 14:37:10 PAGE 10
550 5 month=1;
551 5 count=((init[4]&0xf0)>>4)*10+(init[4]&0x0f); //读当前月数据
552 5 }
553 4 }
554 3 }
555 2
556 2 while(month) //设定月
557 2 {
558 3 key_set(12,1,4);
559 3 if(!K3)
560 3 {
561 4 delay1(35); //消除抖动
562 4 if(!K3)
563 4 {
564 5 Set_W1302(0x88); // 设定值写入DS1302
565 5 Set_place(1,4); // 指定位置显示
566 5 month=0;
567 5 day=1;
568 5 count=((init[3]&0xf0)>>4)*10+(init[3]&0x0f); //读当前日数据
569 5 }
570 4 }
571 3 }
572 2
573 2 while(day) //设定日
574 2 {
575 3 key_set(31,1,7); // 键设定函数
576 3 if(!K3)
577 3 {
578 4 delay1(35); //消除抖动
579 4 if(!K3)
580 4 {
581 5 Set_W1302(0x86); // 设定值写入DS1302
582 5 Set_place(1,7); // 指定位置显示
583 5 day=0;
584 5 week=1;
585 5 count=init[5]&0x0f; //读当前星期数据
586 5 }
587 4 }
588 3 }
589 2
590 2 while(week) //设定星期
591 2 {
592 3 if(!K2)
593 3 {
594 4 delay1(40); //消除抖动
595 4 if(!K2)
596 4 {
597 5 beep();
598 5 if(count!=7)
599 5 count++;
600 5 else count=1;
601 5 }
602 4 }
603 3 if(!K1)
604 3 {
605 4 delay1(40); //消除抖动
606 4 if(!K1)
607 4 {
608 5 beep();
609 5 if(count!=1)
610 5 count--;
611 5 else count=7;
C51 COMPILER V8.02 DS1302_LCD1602_C51 01/22/2008 14:37:10 PAGE 11
612 5 }
613 4 }
614 3 init1[1]=count%10;
615 3
616 3 if(flag)
617 3 {
618 4 write_position(1,15);
619 4 lcd_wdat(init1[1]+0x30); //写显示数据到LCD
620 4 }
621 3 else
622 3 {
623 4 write_position(1,15);
624 4 lcd_wdat(0x20);
625 4 }
626 3 if(!K3)
627 3 {
628 4 delay1(35); //消除抖动
629 4 if(!K3)
630 4 {
631 5 Set_W1302(0x8a); // 设定值写入DS1302
632 5 write_position(1,15);
633 5 lcd_wdat(init1[1]+0x30); //写显示数据到LCD
634 5 week=0;
635 5 hour=1;
636 5 count=((init[2]&0xf0)>>4)*10+(init[2]&0x0f); //读当前时数据
637 5 }
638 4 }
639 3 }
640 2
641 2 while(hour) //设定时
642 2 {
643 3 key_set(23,2,7);
644 3 if(!K3)
645 3 { delay1(35); //消除抖动
646 4 if(!K3)
647 4 {
648 5 Set_W1302(0x84); // 设定值写入DS1302
649 5 Set_place(2,7); // 指定位置显示
650 5 hour=0;
651 5 min=1;
652 5 count=((init[1]&0xf0)>>4)*10+(init[1]&0x0f); //读当前分数据
653 5 }
654 4 }
655 3 }
656 2
657 2 while(min) //设定分
658 2 {
659 3 key_set(59,2,10); // 键设定函数
660 3 if(!K3)
661 3 { delay1(35); //消除抖动
662 4 if(!K3)
663 4 {
664 5 Set_W1302(0x82); // 设定值写入DS1302
665 5 Set_place(2,10); // 指定位置显示
666 5 min=0;
667 5 sec=1;
668 5 count=((init[0]&0xf0)>>4)*10+(init[0]&0x0f); //读当前秒数据
669 5 }
670 4 }
671 3 }
672 2
673 2 while(sec) //设定秒
C51 COMPILER V8.02 DS1302_LCD1602_C51 01/22/2008 14:37:10 PAGE 12
674 2 {
675 3 key_set(59,2,13);
676 3 if(!K3)
677 3 { delay1(35); //消除抖动
678 4 if(!K3)
679 4 {
680 5 Set_W1302(0x80); // 设定值写入DS1302
681 5 Set_place(2,13); // 指定位置显示
682 5 sec=0;
683 5 count=0;
684 5 }
685 4 }
686 3 }
687 2 Play_nowtime();
688 2 Time_compare();
689 2 }
690 1 }
691
692 /**********************************************************/
693 // Time0中断函数
694 /**********************************************************/
695 void Time0(void) interrupt 1 using 0
696 {
697 1 TH0=0x4c; //50ms定时
698 1 TL0=0x00;
699 1 timecount++;
700 1 if(timecount>9)
701 1 {
702 2 timecount=0;
703 2 flag=~flag;
704 2 }
705 1 }
706 /**********************************************************/
707 // 设定值写入DS1302
708 /**********************************************************/
709 void Set_W1302(uchar addr)
710 {
711 1 uchar temp;
712 1 write_ds1302(0x8e,0x00);
713 1 temp=(init1[0]<<4)+init1[1]; //转换为十六进制数
714 1 write_ds1302(addr,temp);
715 1 write_ds1302(0x8e,0x80);
716 1 beep();
717 1 }
718
719 /**********************************************************/
720 // 被设置数据闪动
721 /**********************************************************/
722 void Set_Flash(uchar row,uchar col )
723 {
724 1 init1[0]=count/10;
725 1 init1[1]=count%10;
726 1
727 1 if(flag)
728 1 { //显示
729 2 write_position(row,col); //设定显示位置
730 2 lcd_wdat(init1[0]+0x30); //写显示数据到LCD
731 2 write_position(row,col+1); //设定显示位置
732 2 lcd_wdat(init1[1]+0x30); //写显示数据到LCD
733 2 }
734 1 else
735 1 { //清屏
C51 COMPILER V8.02 DS1302_LCD1602_C51 01/22/2008 14:37:10 PAGE 13
736 2 write_position(row,col); //设定显示位置
737 2 lcd_wdat(0x20); //写显示数据到LCD
738 2 write_position(row,col+1); //设定显示位置
739 2 lcd_wdat(0x20); //写显示数据到LCD
740 2 }
741 1 }
742
743 /**********************************************************/
744 // 指定位置显示
745 /**********************************************************/
746 void Set_place(uchar row,uchar col)
747 {
748 1 write_position(row,col); //设定显示位置
749 1 lcd_wdat(init1[0]+0x30); //写显示数据到LCD
750 1 write_position(row,col+1); //设定显示位置
751 1 lcd_wdat(init1[1]+0x30); //写显示数据到LCD
752 1 }
753
754 /**********************************************************/
755 // 显示当前时间
756 /**********************************************************/
757 void Play_nowtime()
758 {
759 1 read_nowtime(0x81,init,7); //读出当前时间,读出7个字节 秒,分,时,日,月,星期,年
760 1
761 1 write_position(2,7); //设定显示位置
762 1 lcd_wdat(((init[2]&0xf0)>>4)+0x30);//写显示数据到LCD 十位
763 1
764 1 write_position(2,8); //设定显示位置
765 1 lcd_wdat('0'+(init[2]&0x0f)); //读小时 个位
766 1
767 1 // write_position(2,9);
768 1 // lcd_wdat(':');
769 1
770 1 write_position(2,10); //设定显示位置
771 1 lcd_wdat('0'+((init[1]&0xf0)>>4)); //写显示数据到LCD 十位
772 1
773 1 write_position(2,11); //设定显示位置
774 1 lcd_wdat('0'+(init[1]&0x0f)); //读分钟 个位
775 1
776 1 // write_position(2,12);
777 1 // lcd_wdat(':');
778 1
779 1 write_position(2,13); //设定显示位置
780 1 lcd_wdat('0'+((init[0]&0xf0)>>4)); //写显示数据到LCD
781 1
782 1 write_position(2,14);
783 1 lcd_wdat('0'+(init[0]&0x0f)); //读秒
784 1
785 1 write_position(1,1);
786 1 lcd_wdat('0'+((init[6]&0xf0)>>4)); //写显示数据到LCD
787 1
788 1 write_position(1,2);
789 1 lcd_wdat('0'+(init[6]&0x0f)); //读年
790 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -