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

📄 232tocan.lst

📁 RS232/CAN转换器 硬件电路需自己设计(电路很简单)
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V8.17   232TOCAN                                                              03/22/2009 15:12:45 PAGE 16  

 923   3                  {
 924   4                      CanBaud = 1;
 925   4                      Write_byte(2, CanBaud);
 926   4                      Send_ok();
 927   4                  }
 928   3                  else if (strcmp(Command,"can+500k") == 0)
 929   3                  {
 930   4                      CanBaud = 2;
 931   4                      Write_byte(2, CanBaud);
 932   4                      Send_ok();
 933   4                  }
 934   3                  //命令出错
 935   3                  else
 936   3                  {
 937   4                      Send_stream("Command error!");
 938   4                      Send_end();
 939   4                  }
 940   3              }
 941   2              //can工作模式0 
 942   2              else if (strcmp(Command,"basiccan") == 0)
 943   2              {
 944   3                  Can_mode = 0;
 945   3                  Write_byte(3, Can_mode);
 946   3                  Send_ok();
 947   3              }
 948   2              //can工作模式1
 949   2              else if (strcmp(Command,"pelican") == 0)
 950   2              {
 951   3                  Can_mode = 1;
 952   3                  Write_byte(3, Can_mode);
 953   3                  Send_ok();
 954   3              }
 955   2              //验收码
 956   2              else if (strncmp(Command,"code+",5) == 0)
 957   2              {
 958   3                  //4位十六进制数
 959   3                  if (Recjs - 5 == 4)
 960   3                  {
 961   4                      t_b = 0;
 962   4                      
 963   4                      for (t_a = 5; t_a < Recjs; t_a++)
 964   4                      {
 965   5                          //是否都为十六进制数
 966   5                          if (!isxdigit(Command[t_a]))
 967   5                          {
 968   6                              t_b = 1;
 969   6                              break;
 970   6                          }
 971   5                          //转换成16进制数
 972   5                          else
 973   5                          {
 974   6                              Command[t_a] = toint(Command[t_a]);
 975   6                          } 
 976   5                      }
 977   4                      //正确
 978   4                      if (t_b == 0)
 979   4                      {
 980   5                          crc = Command[5] * 4096 + Command[6] * 256 + Command[7] * 16 + Command[8];
 981   5                          Acr_data = crc;
 982   5                          Write_int(4, Acr_data);
 983   5                          Send_ok();
 984   5                      }
C51 COMPILER V8.17   232TOCAN                                                              03/22/2009 15:12:45 PAGE 17  

 985   4                      else
 986   4                      {
 987   5                          Send_stream("Command error!");
 988   5                          Send_end();
 989   5                      }
 990   4                  }
 991   3                  else
 992   3                  {
 993   4                      Send_stream("Command error!");
 994   4                      Send_end();
 995   4                  }
 996   3              }
 997   2              //屏蔽码
 998   2              else if (strncmp(Command,"mask+",5) == 0)
 999   2              {
1000   3                  //4位十六进制数
1001   3                  if (Recjs - 5 == 4)
1002   3                  {
1003   4                      t_b = 0;
1004   4                      
1005   4                      for (t_a = 5; t_a < Recjs; t_a++)
1006   4                      {
1007   5                          //是否都为十六进制数
1008   5                          if (!isxdigit(Command[t_a]))
1009   5                          {
1010   6                              t_b = 1;
1011   6                              break;
1012   6                          }
1013   5                          //转换成16进制数
1014   5                          else
1015   5                          {
1016   6                              Command[t_a] = toint(Command[t_a]);
1017   6                          } 
1018   5                      }
1019   4                      //正确
1020   4                      if (t_b == 0)
1021   4                      {
1022   5                          crc = Command[5] * 4096 + Command[6] * 256 + Command[7] * 16 + Command[8];
1023   5                          Amr_data = crc;
1024   5                          Write_int(6, Amr_data);
1025   5                          Send_ok();
1026   5                      }
1027   4                      else
1028   4                      {
1029   5                          Send_stream("Command error!");
1030   5                          Send_end();
1031   5                      }
1032   4                  }
1033   3                  else
1034   3                  {
1035   4                      Send_stream("Command error!");
1036   4                      Send_end();
1037   4                  }
1038   3              }
1039   2              //返回出厂值
1040   2              else if (strcmp(Command,"return") == 0)
1041   2              {
1042   3                  Cs_init();
1043   3                  Baudrate(ComBaud);
1044   3                  Send_ok();
1045   3              }
1046   2              //退出
C51 COMPILER V8.17   232TOCAN                                                              03/22/2009 15:12:45 PAGE 18  

1047   2              else if (strcmp(Command,"quit") == 0)
1048   2              {
1049   3                  Send_ok();
1050   3                  return 1;
1051   3              }
1052   2              //命令出错
1053   2              else
1054   2              {
1055   3                  Send_stream("Command error!");
1056   3                  Send_end();
1057   3              }
1058   2          }
1059   1          
1060   1          return 0;   
1061   1      }
1062          //通讯参数进行配置
1063          void Debug_config(void)
1064          { 
1065   1          uchar t_c;
1066   1          uchar debug;
1067   1          
1068   1          ES = 0;
1069   1          debug = 0;
1070   1          
1071   1          //等待5秒钟
1072   1          Wait_timer = TIMER5s;
1073   1          
1074   1          while (Wait_timer > 0)
1075   1          {
1076   2              //点亮指示灯
1077   2              REC_LED = 0;
1078   2              SEND_LED = 0;
1079   2              Dog(); 
1080   2               
1081   2              if (_testbit_(RI) && Recjs < CMD_LENGHT)
1082   2              {
1083   3                  t_c = SBUF;
1084   3                  Command[Recjs] = t_c;
1085   3                  
1086   3                  //是否有换行符
1087   3                  if (t_c == ASCII_LF && Recjs > 0)
1088   3                  {
1089   4                      //前面一个字符是否为回车符
1090   4                      if (Command[Recjs - 1] == ASCII_ENTER)
1091   4                      {
1092   5                          //进入调试模式
1093   5                          debug = 1;
1094   5                          Recjs = 0;
1095   5                          break;
1096   5                      }
1097   4                  }
1098   3                  
1099   3                  Recjs++;
1100   3              }  
1101   2          }
1102   1          
1103   1          //调试模式
1104   1          if (debug == 1)
1105   1          {
1106   2              Send_stream("FANLO Tech. Co., Ltd.");
1107   2              Send_end();
1108   2               
C51 COMPILER V8.17   232TOCAN                                                              03/22/2009 15:12:45 PAGE 19  

1109   2              Send_stream("RS232/CAN Version ");
1110   2              
1111   2              Command[0] = Ver_a + 48;
1112   2              Command[1] = '\0';
1113   2              Send_stream(Command);
1114   2              
1115   2              Send_stream(".");
1116   2              
1117   2              Command[0] = Ver_b + 48;
1118   2              Command[1] = '\0';
1119   2              Send_stream(Command);
1120   2              
1121   2              Command[0] = Ver_c + 48;
1122   2              Command[1] = '\0';
1123   2              Send_stream(Command);
1124   2              
1125   2              Send_end();
1126   2              
1127   2              switch (ComBaud)
1128   2              {
1129   3                  case 0:
1130   3                      Send_stream("Com,1200bps,None,1,8,1");
1131   3                  break;
1132   3                  
1133   3                  case 1:
1134   3                      Send_stream("Com,2400bps,None,1,8,1");
1135   3                  break;
1136   3                  
1137   3                  case 2:
1138   3                      Send_stream("Com,4800bps,None,1,8,1");
1139   3                  break;
1140   3                  
1141   3                  case 3:
1142   3                      Send_stream("Com,9600bps,None,1,8,1");
1143   3                  break;
1144   3                  
1145   3                  case 4:
1146   3                      Send_stream("Com,19200bps,None,1,8,1");
1147   3                  break;
1148   3                  
1149   3                  case 5:
1150   3                      Send_stream("Com,38400bps,None,1,8,1");
1151   3                  break;
1152   3                  
1153   3                  case 6:
1154   3                      Send_stream("Com,57600bps,None,1,8,1");
1155   3                  break;
1156   3                  
1157   3                  case 7:
1158   3                      Send_stream("Com,115200bps,None,1,8,1");
1159   3                  break;
1160   3              }
1161   2              Send_end();
1162   2              
1163   2              switch (Rec_delay)
1164   2              {
1165   3                  case 1:
1166   3                      Send_stream("Com,Receive,Delay,50ms");
1167   3                  break;
1168   3                  
1169   3                  case 2:
1170   3                      Send_stream("Com,Receive,Delay,100ms");
C51 COMPILER V8.17   232TOCAN                                                              03/22/2009 15:12:45 PAGE 20  

1171   3                  break;
1172   3                  
1173   3                  case 4:
1174   3                      Send_stream("Com,Receive,Delay,200ms");
1175   3                  break;
1176   3                  
1177   3                  case 10:
1178   3                      Send_stream("Com,Receive,Delay,500ms");
1179   3                  break;
1180   3                  
1181   3                  case 20:
1182   3                      Send_stream("Com,Receive,Delay,1s");
1183   3                  break;
1184   3                  
1185   3                  case 40:
1186   3                      Send_stream("Com,Receive,Delay,2s");
1187   3                  break;
1188   3                  
1189   3                  case 100:
1190   3                      Send_stream("Com,Receive,Delay,5s");
1191   3                  break;
1192   3                  
1193   3                  case 200:
1194   3                      Send_stream("Com,Receive,Delay,10s");
1195   3                  break;
1196   3              }
1197   2              
1198   2              Send_end();
1199   2              
1200   2              if (Can_mode == 0)
1201   2              {
1202   3                  Send_stream("BasicCAN Mode");
1203   3              }
1204   2              else
1205   2              {
1206   3                  Send_stream("PeliCAN Mode");
1207   3              }
1208   2              Send_end();
1209   2              
1210   2              if (CanBaud == 0)
1211   2              {
1212   3                  Send_stream("Can,125Kbps");
1213   3              }
1214   2              else if (CanBaud == 1)
1215   2              {
1216   3                  Send_stream("Can,250Kbps");
1217   3              }
1218   2              else
1219   2              {
1220   3                  Send_stream("Can,500Kbps");
1221   3              }
1222   2              Send_end();
1223   2              
1224   2              Send_stream("Acceptance Code:");
1225   2              Command[0] =  Acr_data / 4096;
1226   2              Command[1] = (Acr_data % 4096) / 256;
1227   2              Command[2] = (Acr_data % 256) / 16;
1228   2              Command[3] =  Acr_data % 16;
1229   2              
1230   2              for (t_c = 0; t_c < 4; t_c++)
1231   2              {
1232   3                  Hex_to_ascii(&Command[t_c]);

⌨️ 快捷键说明

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