📄 serial.lst
字号:
237 2 }
238 1 for (i=0;i<24;i++)
239 1 {
240 2 PutCharWithCheck(Cell[i].s | CurrentWorkStepMax<<4);
C51 COMPILER V7.06 SERIAL 06/06/2005 16:32:37 PAGE 5
241 2 }
242 1 PutChar(outchk);
243 1 PutChar(0x0d);
244 1 OS_ENTER_CRITICAL();
245 1 }
246
247 /*********************************************************************************************************
248 ** 函数名称: CommSendFenRongInfo(uint16 referenceu)
249 ** 功能描述: 发送分容信息报文
250 ** 输 入: 无
251 ** 输 出: 无
252 ** 全局变量: address cid rtn outchk
253 ** 调用模块: OSQCreate PutCharWithCheck PutChar
254 **
255 ** 作 者: 刘宝贵
256 ** 日 期: 2004年10月26日
257 **-------------------------------------------------------------------------------------------------------
258 ** 修改人:
259 ** 日 期:
260 **------------------------------------------------------------------------------------------------------
261 ********************************************************************************************************/
262 void CommSendFenRongInfo(uint16 refeu)
263 {
264 1 uint8 data i;
265 1 OSQCreate(SerialOutData,200);
266 1 outchk = 0;
267 1 PutCharWithCheck(0xeb);
268 1 PutCharWithCheck(0x90);
269 1 PutCharWithCheck(0xeb);
270 1 PutCharWithCheck(0x90);
271 1 PutCharWithCheck(Address);
272 1 PutCharWithCheck(cid);
273 1 PutCharWithCheck(1+48+2);
274 1 PutCharWithCheck(rtn);
275 1 for(i=SumWorkStep;i>0;i--)
276 1 {
277 2 if(WorkStep[i].type == DISCHARGE)
278 2 {
279 3 PutCharWithCheck((uint8)(WorkStep[i].i>>8));
280 3 PutCharWithCheck((uint8)(WorkStep[i].i));
281 3 break;
282 3 }
283 2 else if(i==1)
284 2 {
285 3 PutCharWithCheck(0);
286 3 PutCharWithCheck(0);
287 3 }
288 2 }
289 1 for(i=0;i<24;i++)
290 1 {
291 2 OSSemPend(IICSem,0);
292 2 PutCharWithCheck( EepromReadByte( ReferenceUTimeIICBase + ((3800-refeu)/100)*48 + i*2) );
293 2 PutCharWithCheck( EepromReadByte( ReferenceUTimeIICBase + ((3800-refeu)/100)*48 + i*2 + 1) );
294 2 OSSemPost(IICSem);
295 2 }
296 1 PutChar(outchk);
297 1 PutChar(0x0d);
298 1 }
299 /*********************************************************************************************************
300 ** 函数名称: GetCharWithCheck
301 ** 功能描述: 从读串口消息队列取一字节,并且对该字节校验
302 ** 输 入: 无
C51 COMPILER V7.06 SERIAL 06/06/2005 16:32:37 PAGE 6
303 ** 输 出: temp:从串口消息队列取的字节
304 ** 全局变量: inchk:校验和
305 ** 调用模块: OSQPend
306 **
307 ** 作 者: 刘宝贵
308 ** 日 期: 2004年4月21日
309 **-------------------------------------------------------------------------------------------------------
310 ** 修改人:
311 ** 日 期:
312 **------------------------------------------------------------------------------------------------------
313 ********************************************************************************************************/
314 uint8 GetCharWithCheck(void)
315 {
316 1 uint8 data temp;
317 1 OSQPend(&temp,SerialInData,0); /* 接收一个字节 */
318 1 inchk^=temp;
319 1 return(temp);
320 1 }
321
322 /*********************************************************************************************************
323 ** 函数名称: GetCharWithoutCheck
324 ** 功能描述: 从读串口消息队列取一字节
325 ** 输 入: 无
326 ** 输 出: temp:从串口消息队列取的字节
327 ** 全局变量: 无
328 ** 调用模块: OSQPend
329 **
330 ** 作 者: 刘宝贵
331 ** 日 期: 2004年4月21日
332 **-------------------------------------------------------------------------------------------------------
333 ** 修改人:
334 ** 日 期:
335 **------------------------------------------------------------------------------------------------------
336 ********************************************************************************************************/
337 uint8 GetCharWithoutCheck(void)
338 {
339 1 uint8 data temp;
340 1 OSQPend(&temp,SerialInData,0); /* 接收一个字节 */
341 1 return(temp);
342 1 }
343
344 /*********************************************************************************************************
345 ** 函数名称: TaskReceive
346 ** 功能描述: 串口接收处理任务
347 ** 输 入: 无
348 ** 输 出: 无
349 ** 全局变量: 无
350 ** 调用模块: 无
351 **
352 ** 作 者: 刘宝贵
353 ** 日 期: 2004年4月20日
354 **-------------------------------------------------------------------------------------------------------
355 ** 修改人:
356 ** 日 期:
357 **------------------------------------------------------------------------------------------------------
358 ********************************************************************************************************/
359 void TaskReceive(void)
360 {
361 1 uint8 code head[4] = {0xEB,0x90,0xEB,0x90};
362 1 OSQCreate(SerialInData,130); /* 建立所需要的消息队列 */
363 1 OSQCreate(SerialOutData,200);
364 1 while (1)
C51 COMPILER V7.06 SERIAL 06/06/2005 16:32:37 PAGE 7
365 1 {
366 2 uint8 xdata state=0;
367 2 while (1)//识别报文头
368 2 {
369 3 if(head[state] == GetCharWithoutCheck())
370 3 state++;
371 3 else
372 3 state=0;
373 3 if(state==4)
374 3 break;
375 3 }//while (1)//识别报文头
376 2 rtn=RIGHT; /* 返回码置初值 */
377 2 inchk = 0xeb^0x90^0xeb^0x90; /* 初始化校验和 */
378 2 if(Address == GetCharWithCheck()) /* 如果地址正确则继续 */
379 2 {
380 3 uint8 data i;
381 3 uint8 xdata length;
382 3 cid = GetCharWithCheck();
383 3 length = GetCharWithCheck();
384 3 if (length>100)
385 3 {
386 4 length=100;
387 4 }
388 3 for (i=0;i<length;i++) // 接收数据区数据
389 3 {
390 4 buf[i]=GetCharWithCheck();
391 4 }
392 3 i = GetCharWithoutCheck();
393 3 if (inchk != i && i!=0x55) // 判断校验和 0x55 为不校验
394 3 {
395 4 rtn = CHKSUM_ERROR;
396 4 }
397 3 if (0x0d != GetCharWithoutCheck()) // 判断报文尾
398 3 {
399 4 rtn = TYPE_ERROR;
400 4 }
401 3 EN_485 = 0;
402 3 OSWait(K_TMO,(5*OS_TICKS_PER_SEC)/1000); //delay15ms
403 3 if(rtn==1)//如果报文的校验和,类型正确
404 3 {
405 4 CommCounter = 0;
406 4 switch (cid)
407 4 {
408 5 case 0: // 握手命令
409 5 {
410 6 CommSendInfo();
411 6 }break;
412 5 case 1: // 取电池数据信息
413 5 {
414 6 CommSendCellDataInfo();
415 6 }break;
416 5 case 2: // 工步设置
417 5 {
418 6 if(CurrentWorkStep ==0)//如果当前为停止状态则可以修改工步
419 6 {
420 7 SumWorkStep = buf[0];
421 7 if(SumWorkStep>12)
422 7 SumWorkStep=12;
423 7 for(i=1;i<=SumWorkStep;i++)
424 7 {
425 8 WorkStep[i].type = buf[(i-1)*9+2];
426 8
C51 COMPILER V7.06 SERIAL 06/06/2005 16:32:37 PAGE 8
427 8 WorkStep[i].i = buf[(i-1)*9+3];
428 8 WorkStep[i].i = WorkStep[i].i <<8 ;
429 8 WorkStep[i].i = WorkStep[i].i | buf[(i-1)*9+4];
430 8 WorkStep[i].i *=10;
431 8
432 8 WorkStep[i].limit = buf[(i-1)*9+5];
433 8 WorkStep[i].limit = WorkStep[i].limit <<8 ;
434 8 WorkStep[i].limit = WorkStep[i].limit | buf[(i-1)*9+6];
435 8 WorkStep[i].limit *=10;
436 8
437 8 WorkStep[i].t = buf[(i-1)*9+7];
438 8 WorkStep[i].t = WorkStep[i].t <<8 ;
439 8 WorkStep[i].t = WorkStep[i].t | buf[(i-1)*9+8];
440 8 WorkStep[i].t *= 60;//换算成秒
441 8
442 8 WorkStep[i].u = buf[(i-1)*9+9];
443 8 WorkStep[i].u = WorkStep[i].u <<8 ;
444 8 WorkStep[i].u = WorkStep[i].u | buf[(i-1)*9+10];
445 8 WorkStep[i].u *= 10;
446 8
447 8 }
448 7 if( WorkStepCheck()==0 )//如果工步无效
449 7 {
450 8 rtn = DATA_ERROR;
451 8 }
452 7 CommSendInfo();
453 7 OSSemPend(IICSem,0);
454 7 EepromWriteByte(SumWorkStepIICBase,SumWorkStep);
455 7 for(i=1;i<=SumWorkStep;i++)
456 7 {
457 8 EepromWriteByte(WorkStepIICBase + i*9 + 0,WorkStep[i].type );
458 8 EepromWriteWord(WorkStepIICBase + i*9 + 1,WorkStep[i].i );
459 8 EepromWriteWord(WorkStepIICBase + i*9 + 3,WorkStep[i].limit);
460 8 EepromWriteWord(WorkStepIICBase + i*9 + 5,WorkStep[i].t );
461 8 EepromWriteWord(WorkStepIICBase + i*9 + 7,WorkStep[i].u );
462 8 }
463 7 OSSemPost(IICSem);
464 7 }
465 6 else//if(CurrentWorkStep ==0)//如果当前为停止状态则可以修改工步
466 6 {
467 7 rtn = LOGIC_ERROR;
468 7 CommSendInfo();
469 7 }
470 6 }break;
471 5 case 3:// 模块停止
472 5 {
473 6 CellCheckFlag = 0;
474 6 if(CurrentWorkStep>0)//CurrentWorkStep==0则系统众目停止
475 6 {
476 7 OSSemPost(StopWorkStepSem);
477 7 }
478 6 else
479 6 {
480 7 rtn = LOGIC_ERROR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -