📄 commrs485.lst
字号:
232 6 CommBytehilow = 1;
233 6 }
234 5 else
235 5 {
236 6 CommState++;
237 6 CommLengthL = CommTemp1;
238 6 CommBytehilow = 0;
239 6 if(CommLengthL > 100)CommState = 0;
240 6 CommRxPointer = 0; //RxBufPointer
C51 COMPILER V7.06 COMMRS485 10/30/2008 13:20:06 PAGE 5
241 6 if(CommLengthL == 0)CommState++;
242 6 }
243 5 }break;
244 4 case 4: /*INFO*/
245 4 {
246 5 if(CommLengthL != 0)
247 5 {
248 6 CommRxBuf[CommRxPointer] = CommTemp1;
249 6 CommRxPointer++;
250 6 CommLengthL--;
251 6 CommLengthL--;
252 6 if(CommLengthL == 0)CommState++;
253 6 }
254 5 else
255 5 CommState++;
256 5 }break;
257 4 case 5: /*chksum*/
258 4 {
259 5 if(CommBytehilow == 0)
260 5 {
261 6 CommChksumH = CommTemp1;
262 6 CommBytehilow = 1;
263 6 }
264 5 else
265 5 {
266 6 CommBytehilow = 0;
267 6 CommChksumL = CommTemp1;
268 6 ReComCalculChkSum = CommChksumH;
269 6 ReComCalculChkSum = ReComCalculChkSum << 8;
270 6 ReComCalculChkSum |= CommChksumL;
271 6 ComCalculChkSum= (~ComCalculChkSum)+1;
272 6 //COMEN = CommTxden;
273 6 //Suart_Send_Byte(ComCalculChkSum >> 8);
274 6 //Suart_Send_Byte(ComCalculChkSum);
275 6 //COMEN = CommRxden;
276 6 if(ReComCalculChkSum == ComCalculChkSum)CommState++;
277 6 else
278 6 {
279 7 goto comrxend;
280 7 }
281 6 }
282 5 }break;
283 4 case 6: /*EOI */
284 4 {
285 5 if(CommTemp0 == 0x0D)
286 5 {
287 6 Massageflag = 1;
288 6 }
289 5 CommState = 0;
290 5 }break;
291 4 }
292 3 comrxend:
293 3 ;
294 3 }
295 2 }
296 1 RI = 0;
297 1 EA = ea_time;
298 1 }
299 /********************************************************************************************************
300 ** 函数名称: void CommRight(void)
301 ** 功能描述:
302 ** 输 入: 无
C51 COMPILER V7.06 COMMRS485 10/30/2008 13:20:06 PAGE 6
303 ** 输 出: 无
304 ** 全局变量:
305 ** 调用模块:
306 **
307 ** 作 者: 李伟
308 ** 日 期: 2008年12月20日
309 **-------------------------------------------------------------------------------------------------------
310 ** 修 改 人:
311 ** 日 期:
312 **-------------------------------------------------------------------------------------------------------
313 ********************************************************************************************************/
314 void CommRight(void)
315 {
316 1 Suart_Send_Byte(0x7E); //报文头
317 1 ComCalculChkSum = 0;
318 1 CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
319 1 CommSendByteWithChk(CommCid); //CID 07
320 1 CommSendWordWithChk(0xA006); //LENTH
321 1 CommSendByteWithChk(0x01); //
322 1 CommSendWordWithChk(0x0001); //写系数正确
323 1 ComCalculChkSum = (~ComCalculChkSum)+1;
324 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
325 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum));
326 1 Suart_Send_Byte(0x0D);
327 1 }
328 /********************************************************************************************************
329 ** 函数名称: void CommWrong(void)
330 ** 功能描述:
331 ** 输 入: 无
332 ** 输 出: 无
333 ** 全局变量:
334 ** 调用模块:
335 **
336 ** 作 者: 李伟
337 ** 日 期: 2008年12月20日
338 **-------------------------------------------------------------------------------------------------------
339 ** 修 改 人:
340 ** 日 期:
341 **-------------------------------------------------------------------------------------------------------
342 ********************************************************************************************************/
343 void CommWrong(void)
344 {
345 1 Suart_Send_Byte(0x7E); //报文头
346 1 ComCalculChkSum = 0;
347 1 CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
348 1 CommSendByteWithChk(CommCid); //CID 07
349 1 CommSendWordWithChk(0xA006); //LENTH
350 1 CommSendByteWithChk(0x01); //
351 1 CommSendWordWithChk(0x0000); //写系数错误
352 1 ComCalculChkSum = (~ComCalculChkSum)+1;
353 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
354 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum));
355 1 Suart_Send_Byte(0x0D);
356 1 }
357 /********************************************************************************************************
358 ** 函数名称: void Comm_rs485_handshake(void)
359 ** 功能描述:
360 ** 输 入: 无
361 ** 输 出: 无
362 ** 全局变量:
363 ** 调用模块:
364 **
C51 COMPILER V7.06 COMMRS485 10/30/2008 13:20:06 PAGE 7
365 ** 作 者: 李伟
366 ** 日 期: 2008年12月20日
367 **-------------------------------------------------------------------------------------------------------
368 ** 修 改 人:
369 ** 日 期:
370 **-------------------------------------------------------------------------------------------------------
371 ********************************************************************************************************/
372 void Comm_rs485_handshake(void)
373 {
374 1 Suart_Send_Byte(0x7E); //报文头
375 1 ComCalculChkSum = 0;
376 1 CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
377 1 CommSendByteWithChk(CommCid); //CID 01
378 1 CommSendWordWithChk(0xA006); //LENTH
379 1 CommSendByteWithChk(0x01); //
380 1 CommSendWordWithChk(0x55AA);
381 1 ComCalculChkSum = (~ComCalculChkSum)+1;
382 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
383 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum));
384 1 Suart_Send_Byte(0x0D);
385 1 }
386 /********************************************************************************************************
387 ** 函数名称: void Comm_rs485_readanalog(void)
388 ** 功能描述:
389 ** 输 入: 无
390 ** 输 出: 无
391 ** 全局变量:
392 ** 调用模块:
393 **
394 ** 作 者: 李伟
395 ** 日 期: 2008年12月20日
396 **-------------------------------------------------------------------------------------------------------
397 ** 修 改 人:
398 ** 日 期:
399 **-------------------------------------------------------------------------------------------------------
400 ********************************************************************************************************/
401 void Comm_rs485_readanalog(void)
402 {
403 1 uint8 i;
404 1 Suart_Send_Byte(0x7E); //报文头
405 1 ComCalculChkSum = 0;
406 1 CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
407 1 CommSendByteWithChk(CommCid); //CID 02
408 1 CommSendWordWithChk(0xF05C); //LENTH
409 1 CommSendByteWithChk(0x01); //
410 1 for(i = 0;i < 15;i++) //15只池电电压
411 1 {
412 2 CommSendWordWithChk(CellVoltage[i]);
413 2 }
414 1 CommSendByteWithChk(0x02); //
415 1 for(i = 0;i < 9;i++) //15只电池温度,1路环境温度
416 1 {
417 2 CommSendByteWithChk(Temperature[i]);
418 2 }
419 1 CommSendByteWithChk(0x03);
420 1 CommSendWordWithChk(ChargeCurrent); //充电电流
421 1 CommSendWordWithChk(DisChargeCurrent); //放电电流
422 1 ComCalculChkSum = (~ComCalculChkSum)+1;
423 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
424 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum));
425 1 Suart_Send_Byte(0x0D);
426 1 }
C51 COMPILER V7.06 COMMRS485 10/30/2008 13:20:06 PAGE 8
427 /********************************************************************************************************
428 ** 函数名称: void Comm_rs485_read_digital(void)
429 ** 功能描述:
430 ** 输 入: 无
431 ** 输 出: 无
432 ** 全局变量:
433 ** 调用模块:
434 **
435 ** 作 者: 李伟
436 ** 日 期: 2008年12月20日
437 **-------------------------------------------------------------------------------------------------------
438 ** 修 改 人:
439 ** 日 期:
440 **-------------------------------------------------------------------------------------------------------
441 ********************************************************************************************************/
442 void Comm_rs485_read_digital(void)
443 {
444 1 Suart_Send_Byte(0x7E); //报文头
445 1 ComCalculChkSum = 0;
446 1 CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
447 1 CommSendByteWithChk(CommCid); //CID 03
448 1 CommSendWordWithChk(0x501A); //LENTH
449 1
450 1 CommSendByteWithChk(0x01); //
451 1 CommSendByteWithChk(ComAlarmET ); //综合告警
452 1 CommSendByteWithChk(ComAlarmVh0); //1~ 8只电池过压告警
453 1 CommSendByteWithChk(ComAlarmVh1); //9~15只电池过压告警
454 1 CommSendByteWithChk(ComAlarmVl0); //1~ 8只电池欠压告警
455 1 CommSendByteWithChk(ComAlarmVl1); //9~15只电池欠压告警
456 1 CommSendByteWithChk(ComAlarmScCTh); //1~15只电池充电过温
457 1 CommSendByteWithChk(ComAlarmScCTl); //1~15只电池充电欠温
458 1 CommSendByteWithChk(ComAlarmSDcTh); //1~15只电池放电过温
459 1 CommSendByteWithChk(ComAlarmSDcTl); //1~15只电池放电欠温
460 1 CommSendByteWithChk(ComTemperaSensor ); //1~ 8路温度传感器失效
461 1 CommSendByteWithChk(ComVoltageSensor0); //电压传感器失效
462 1
463 1 ComCalculChkSum = (~ComCalculChkSum)+1;
464 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
465 1 CommSendByteWithoutChk((uint8)(ComCalculChkSum));
466 1 Suart_Send_Byte(0x0D);
467 1 }
468 /********************************************************************************************************
469 ** 函数名称: void Comm_rs232_read_config(void)
470 ** 功能描述:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -