📄 232tocan.lst
字号:
C51 COMPILER V8.17 232TOCAN 03/22/2009 15:12:45 PAGE 11
613 1 return var.crc;
614 1 }
615 //EEROM中单元中参数初始化
616 void Cs_init(void)
617 {
618 1 ComBaud = 3; //串口波特率
619 1 Rec_delay = 1; //串口接收延时
620 1 CanBaud = 0; //CAN波特率
621 1 Can_mode = 1; //CAN工作模式
622 1 Acr_data = 0xffff; //验收码
623 1 Amr_data = 0xffff; //屏蔽码
624 1
625 1 Write_byte(0, ComBaud);
626 1 Write_byte(1, Rec_delay);
627 1 Write_byte(2, CanBaud);
628 1 Write_byte(3, Can_mode);
629 1 Write_int(4, Acr_data);
630 1 Write_int(6, Amr_data);
631 1 }
632 //从EEROM单元中读数据到内存中
633 void Read_cs(void)
634 {
635 1 ComBaud = Read_byte(0); //串口波特率
636 1 Rec_delay = Read_byte(1); //串口接收延时
637 1 CanBaud = Read_byte(2); //CAN波特率
638 1 Can_mode = Read_byte(3); //CAN工作模式
639 1 Acr_data = Read_int(4); //验收码
640 1 Amr_data = Read_int(6); //屏蔽码
641 1 }
642 //读软件版本号
643 void Read_version(void)
644 {
645 1 Ver_a=Read_byte(505);
646 1 Ver_b=Read_byte(506);
647 1 Ver_c=Read_byte(507);
648 1 }
649 //写软件版本号
650 void Write_version(void)
651 {
652 1 Ver_a=1; //第一次上电初始化版本号
653 1 Ver_b=0;
654 1 Ver_c=0;
655 1
656 1 Write_byte(505,Ver_a);
657 1 Write_byte(506,Ver_b);
658 1 Write_byte(507,Ver_c);
659 1 }
660 //是否初始化存储器单元
661 void Clear_blank(void)
662 {
663 1 uint t_a;
664 1 uchar Ver_update;
665 1
666 1 Read_version(); //读软件版本号
667 1
668 1 if (Ver_a == 0 || Ver_a > 9 || Ver_b > 9 || Ver_c > 9) //兼容V1.00-V9.99版本
669 1 {
670 2 Ver_update = 1;
671 2 }
672 1 else
673 1 {
674 2 Ver_update = 0;
C51 COMPILER V8.17 232TOCAN 03/22/2009 15:12:45 PAGE 12
675 2
676 2 if (Ver_a != 1 || Ver_b != 0 || Ver_c != 0)
677 2 {
678 3 Write_version();
679 3 }
680 2 }
681 1
682 1 if (Ver_update > 0)
683 1 {
684 2 Ver_update = 0;
685 2
686 2 for (t_a=0; t_a <= 0x1ff; t_a++)
687 2 {
688 3 Write_byte(t_a,0);
689 3 }
690 2
691 2 Dog();
692 2 //第一次上电初始化系统参数
693 2 Cs_init();
694 2
695 2 Write_version();
696 2 }
697 1 }
698 //5045开机初始化
699 void X5045_init(void)
700 {
701 1 SCLK = 1;
702 1 SPI_SI = 0;
703 1 SPI_SO = 1;
704 1
705 1 SPI_CS = 1;
706 1 SPI_CS = 0;
707 1 SPI_CS = 1;
708 1 }
709 //串口发送一串字节
710 void Send_stream(uchar buf[])
711 {
712 1 uchar t_a;
713 1 uchar len;
714 1
715 1 len = strlen(buf);
716 1
717 1 for (t_a = 0; t_a < len; t_a++)
718 1 {
719 2 SEND_LED = 0;
720 2 SBUF = buf[t_a];
721 2
722 2 while (!TI)
723 2 {
724 3 Dog();
725 3 }
726 2
727 2 TI = 0;
728 2 }
729 1 }
730 //发送回车换行符
731 void Send_end(void)
732 {
733 1 SBUF = ASCII_ENTER;
734 1
735 1 SEND_LED = 0;
736 1 while (!TI)
C51 COMPILER V8.17 232TOCAN 03/22/2009 15:12:45 PAGE 13
737 1 {
738 2 Dog();
739 2 }
740 1
741 1 TI = 0;
742 1
743 1 SBUF = ASCII_LF;
744 1
745 1 while (!TI)
746 1 {
747 2 Dog();
748 2 }
749 1
750 1 TI = 0;
751 1 }
752 //命令执行成功
753 void Send_ok(void)
754 {
755 1 Send_stream("Succeed!");
756 1 Send_end();
757 1 }
758 //转换十六进制数为ASCII值
759 void Hex_to_ascii(uchar *p)
760 {
761 1 uchar t_c;
762 1
763 1 t_c = *p;
764 1
765 1 //0-9
766 1 if (t_c < 10)
767 1 {
768 2 t_c += 48;
769 2 }
770 1 //A-F
771 1 else
772 1 {
773 2 t_c += 55;
774 2 }
775 1
776 1 *p = t_c;
777 1 }
778 //命令解析
779 uchar Perform_cmd(void)
780 {
781 1 uchar t_a;
782 1 uchar t_b;
783 1 uint crc;
784 1
785 1 //去掉回车及换行符
786 1 Recjs -= 2;
787 1
788 1 if (Recjs != 0)
789 1 {
790 2 for (t_a = 0; t_a < Recjs; t_a++)
791 2 {
792 3 Command[t_a] = tolower(Command[t_a]);
793 3 }
794 2 //字符串结束标专
795 2 Command[Recjs] = '\0';
796 2
797 2 //串口波特率
798 2 if (strncmp(Command,"com+",4) == 0)
C51 COMPILER V8.17 232TOCAN 03/22/2009 15:12:45 PAGE 14
799 2 {
800 3 if (strcmp(Command,"com+1200") == 0)
801 3 {
802 4 ComBaud = 0;
803 4 Write_byte(0, ComBaud);
804 4 Send_ok();
805 4 }
806 3 else if (strcmp(Command,"com+2400") == 0)
807 3 {
808 4 ComBaud = 1;
809 4 Write_byte(0, ComBaud);
810 4 Send_ok();
811 4 }
812 3 else if (strcmp(Command,"com+4800") == 0)
813 3 {
814 4 ComBaud = 2;
815 4 Write_byte(0, ComBaud);
816 4 Send_ok();
817 4 }
818 3 else if (strcmp(Command,"com+9600") == 0)
819 3 {
820 4 ComBaud = 3;
821 4 Write_byte(0, ComBaud);
822 4 Send_ok();
823 4 }
824 3 else if (strcmp(Command,"com+19200") == 0)
825 3 {
826 4 ComBaud = 4;
827 4 Write_byte(0, ComBaud);
828 4 Send_ok();
829 4 }
830 3 else if (strcmp(Command,"com+38400") == 0)
831 3 {
832 4 ComBaud = 5;
833 4 Write_byte(0, ComBaud);
834 4 Send_ok();
835 4 }
836 3 else if (strcmp(Command,"com+57600") == 0)
837 3 {
838 4 ComBaud = 6;
839 4 Write_byte(0, ComBaud);
840 4 Send_ok();
841 4 }
842 3 else if (strcmp(Command,"com+115200") == 0)
843 3 {
844 4 ComBaud = 7;
845 4 Write_byte(0, ComBaud);
846 4 Send_ok();
847 4 }
848 3 //命令出错
849 3 else
850 3 {
851 4 Send_stream("Command error!");
852 4 Send_end();
853 4 }
854 3 }
855 2 //串口接收延时
856 2 else if (strncmp(Command,"delay",5) == 0)
857 2 {
858 3 if (strcmp(Command,"delay50ms") == 0)
859 3 {
860 4 Rec_delay = 1;
C51 COMPILER V8.17 232TOCAN 03/22/2009 15:12:45 PAGE 15
861 4 Write_byte(1, Rec_delay);
862 4 Send_ok();
863 4 }
864 3 else if (strcmp(Command,"delay100ms") == 0)
865 3 {
866 4 Rec_delay = 2;
867 4 Write_byte(1, Rec_delay);
868 4 Send_ok();
869 4 }
870 3 else if (strcmp(Command,"delay200ms") == 0)
871 3 {
872 4 Rec_delay = 4;
873 4 Write_byte(1, Rec_delay);
874 4 Send_ok();
875 4 }
876 3 else if (strcmp(Command,"delay500ms") == 0)
877 3 {
878 4 Rec_delay = 10;
879 4 Write_byte(1, Rec_delay);
880 4 Send_ok();
881 4 }
882 3 else if (strcmp(Command,"delay1s") == 0)
883 3 {
884 4 Rec_delay = 20;
885 4 Write_byte(1, Rec_delay);
886 4 Send_ok();
887 4 }
888 3 else if (strcmp(Command,"delay2s") == 0)
889 3 {
890 4 Rec_delay = 40;
891 4 Write_byte(1, Rec_delay);
892 4 Send_ok();
893 4 }
894 3 else if (strcmp(Command,"delay5s") == 0)
895 3 {
896 4 Rec_delay = 100;
897 4 Write_byte(1, Rec_delay);
898 4 Send_ok();
899 4 }
900 3 else if (strcmp(Command,"delay10s") == 0)
901 3 {
902 4 Rec_delay = 200;
903 4 Write_byte(1, Rec_delay);
904 4 Send_ok();
905 4 }
906 3 //命令出错
907 3 else
908 3 {
909 4 Send_stream("Command error!");
910 4 Send_end();
911 4 }
912 3 }
913 2 //can通讯速率
914 2 else if (strncmp(Command,"can+",4) == 0)
915 2 {
916 3 if (strcmp(Command,"can+125k") == 0)
917 3 {
918 4 CanBaud = 0;
919 4 Write_byte(2, CanBaud);
920 4 Send_ok();
921 4 }
922 3 else if (strcmp(Command,"can+250k") == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -