📄 com.lst
字号:
253 2 LoadInt(Para1.chuchang_bianhao);
254 2 }
255 1 else if(buf[0]==10) //出厂时间
256 1 {
257 2 ComBuf[ComHand]=0x34; //字节数4
258 2 ComHand++;
259 2 LoadInt(Para1.chuchang_time);
260 2 }
261 1 else if(buf[0]==11) //接收机编号
262 1 {
263 2 ComBuf[ComHand]=0x34; //字节数4
264 2 ComHand++;
265 2 LoadInt(Para1.jieshouji_bianhao);
266 2 }
267 1
268 1 else if(buf[0]==12) //用户名
269 1 {
270 2 ComBuf[ComHand]=0x4f; //字节数20
271 2 for(j=0;j<10,j++;)
272 2 {
273 3 LoadInt(Para2.yonghuming[j]);
274 3 }
275 2 }
276 1
277 1
278 1 //CRC校验数据
279 1 buf[0]=Data_XRL(ComBuf,1,ComHand);
280 1 Hex_To_Ascii(buf); //把校验数据转换成ASCII
*** WARNING C214 IN LINE 280 OF COM.C: 'Argument': conversion: pointer to non-pointer
281 1 ComBuf[ComHand]=buf[0];
282 1 ComHand++;
283 1 ComBuf[ComHand]=buf[1];
284 1 ComHand++;
285 1 ComBuf[ComHand]=0x0D;
286 1 ComHand++;
287 1 IsBeginCom=1; //要求发射数据的标志
288 1 //ComTime=5;
289 1
290 1 SBUF=0x40; //启动发射数据
291 1 }
*** WARNING C280 IN LINE 182 OF COM.C: 'ch': unreferenced local variable
292
293
294 /*************************串行中断程序**********************/
295
296 void ComInt() interrupt 4
297 {
298 1 unsigned char ch,j;
299 1 unsigned char buf[4];
300 1 unsigned char str[2];
C51 COMPILER V7.08 COM 03/05/2007 16:38:07 PAGE 6
301 1 long int i ;
302 1
303 1 if(TI==1) //发中断
304 1 {
305 2 TI=0;
306 2 ComJs++;
307 2 if(ComJs<ComHand) //未发完
308 2 {
309 3 SBUF=ComBuf[ComJs];
310 3 }
311 2 else //已发完
312 2 {
313 3 IsBeginCom=0; //要求发射数据的标志
314 3 //QH=0;
315 3 }
316 2 }
317 1 else //收中断
318 1 {
319 2 RI=0;
320 2 ch=SBUF;
321 2 if(!Is40H) //未收到数据头
322 2 {
323 3 if(ch==0x40) //为数据头
324 3 {
325 4 Is40H=1;
326 4 ComHand=0;
327 4 }
328 3 return;
329 3 }
330 2 else //已收到数据头
331 2 {
332 3 if(ch!=0x0D) //不为数据尾
333 3 {
334 4 ComBuf[ComHand]=ch;
335 4 ComHand++;
336 4 if(ComHand>=23) //接收超个数
337 4 {
338 5 Is40H=0;
339 5 }
340 4 return;
341 4 }
342 3 else //收到数据尾
343 3 {
344 4 Is40H=0;
345 4
346 4 buf[0]=ComBuf[0]; //ComBuf的0,1字节为设备地址
347 4 buf[1]=ComBuf[1];
348 4
349 4 Ascii_To_Hex(buf); //设备地址
*** WARNING C214 IN LINE 349 OF COM.C: 'Argument': conversion: pointer to non-pointer
350 4
351 4 if(Para1.chuchang_bianhao!=buf[0]) //不为本机
352 4 {
353 5 return;
354 5 }
355 4 //为本机
356 4 //QH=1;
357 4 buf[0]=ComBuf[ComHand-2];
358 4 buf[1]=ComBuf[ComHand-1];
359 4 Ascii_To_Hex(buf); //取异或
*** WARNING C214 IN LINE 359 OF COM.C: 'Argument': conversion: pointer to non-pointer
360 4
C51 COMPILER V7.08 COM 03/05/2007 16:38:07 PAGE 7
361 4 ch=Data_XRL(ComBuf,0,ComHand-2); //计算异或
362 4
363 4 if(ch!=buf[0]) //异或错
364 4 {
365 5 Make_Error(0x2A); // 发射** 接收数据不正确要求重发
366 5 }
367 4 else //异或和正确 接收数据正确
368 4 {
369 5
370 5 buf[0]=ComBuf[6];
371 5 buf[1]=ComBuf[7];
372 5 Ascii_To_Hex(buf); //buf[0]中为数据地址
*** WARNING C214 IN LINE 372 OF COM.C: 'Argument': conversion: pointer to non-pointer
373 5
374 5 ch=ComBuf[3]&0x01;
375 5
376 5 if(ch==1) //写
377 5 {
378 6 // IsSave=1;
379 6 str[0]=ComBuf[10];
380 6 str[1]=ComBuf[11];
381 6 Ascii_To_Hex(str); //高字节
*** WARNING C214 IN LINE 381 OF COM.C: 'Argument': conversion: pointer to non-pointer
382 6 ch=str[0];
383 6
384 6 str[0]=ComBuf[12];
385 6 str[1]=ComBuf[13];
386 6 Ascii_To_Hex(str); //低字节
*** WARNING C214 IN LINE 386 OF COM.C: 'Argument': conversion: pointer to non-pointer
387 6 i=(long int)ch*256+(long int)str[0];
388 6
389 6 if(buf[0]==1) //称重数据
390 6 {
391 7 str[0]=ComBuf[14];
392 7 str[1]=ComBuf[15];
393 7 Ascii_To_Hex(str); //高字节
*** WARNING C214 IN LINE 393 OF COM.C: 'Argument': conversion: pointer to non-pointer
394 7 ch=str[0];
395 7
396 7 str[0]=ComBuf[16];
397 7 str[1]=ComBuf[17];
398 7 Ascii_To_Hex(str); //高字节
*** WARNING C214 IN LINE 398 OF COM.C: 'Argument': conversion: pointer to non-pointer
399 7
400 7 zhongliang_data=(i<<16)+(long int)ch*256+(long int)str[0];
401 7
402 7 }
403 6
404 6 else if(buf[0]==2) //发射机频率
405 6 {
406 7 Para.fasheji_pinlv=i;
407 7 }
408 6 else if(buf[0]==3) //零点
409 6 {
410 7 Para.lingdian=i;
411 7 }
412 6 else if(buf[0]==4) //分度值
413 6 {
414 7 Para.fenduzhi=i;
415 7 }
416 6
417 6 else if(buf[0]==5) //量程
C51 COMPILER V7.08 COM 03/05/2007 16:38:07 PAGE 8
418 6 {
419 7 Para.liangcheng=i;
420 7 }
421 6
422 6 /* else if(buf[0]==6) //单位
423 6 {
424 6 Para.danwei=ch;
425 6 }
426 6 */
427 6 else if(buf[0]==7) //斜率
428 6 {
429 7 Para.xielv_data=i;
430 7 }
431 6
432 6 else if(buf[0]==8) //传感器量程
433 6 {
434 7 Para.chuanganqi_liangcheng=i;
435 7 }
436 6
437 6 else if(buf[0]==9) //出厂编号
438 6 {
439 7 Para1.chuchang_bianhao=i;
440 7 }
441 6
442 6 else if(buf[0]==10) //出厂时间
443 6 {
444 7 Para1.chuchang_time=i;
445 7 }
446 6 else if(buf[0]==11) //接收机编号
447 6 {
448 7 Para1.jieshouji_bianhao=i;
449 7 }
450 6
451 6 else if(buf[0]==12) //用户名
452 6 {
453 7 for (j=0;j<20;j++)
454 7 {
455 8 str[0]=ComBuf[j+10];
456 8 str[1]=ComBuf[j+11];
457 8 Ascii_To_Hex(str);
*** WARNING C214 IN LINE 457 OF COM.C: 'Argument': conversion: pointer to non-pointer
458 8 Para2.yonghuming[j]=str[0];
459 8
460 8 }
461 7 }
462 6 }
463 5 else return;
464 5
465 5 }
466 4 }
467 3 }
468 2 }
469 1 }
470
471
472
473 //向通信缓冲装入int数据
474 void LoadInt(int cs)
475 {
476 1 unsigned char buf[4];
477 1 Make_Two_Byte(cs,buf); //把一个数据转化成两个ASCII并装入
478 1 ComBuf[ComHand]=buf[0];
C51 COMPILER V7.08 COM 03/05/2007 16:38:07 PAGE 9
479 1 ComHand++;
480 1 ComBuf[ComHand]=buf[1];
481 1 ComHand++;
482 1 ComBuf[ComHand]=buf[2];
483 1 ComHand++;
484 1 ComBuf[ComHand]=buf[3];
485 1 ComHand++;
486 1 }
487
488 //初始化串口
489 void Init_Com()
490 {
491 1 /* TR2=0;
492 1 T2CON=0x30; //定时器2作为波特率发生器
493 1
494 1 TH2=Com24M[Para.Com*2];
495 1 RCAP2H=TH2;
496 1 TL2=Com24M[Para.Com*2+1];
497 1 RCAP2L=TL2; //波特率
498 1
499 1 SCON=0x50; //串口工作方式1+
500 1 PCON=PCON&0x7F; //波特率不加倍
501 1 */
502 1
503 1 /*定义T1为串口发生器*/
504 1 TMOD=0x20; //确定定时器1工作方式为方式2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -