📄 can.lst
字号:
490 /*
491 //****************************************************************************
492 // @Function void CAN_vLoadData(unsigned char ObjNr, unsigned char *pubBuffer)
493 //
494 //----------------------------------------------------------------------------
495 // @Description If a message object has to be loaded with data
496 // but not with a new identifier, this function may be used
497 // instead of the function CAN_vConfigMsgObj.
498 // The message object should be accessed by calling the function
499 // CAN_bRequestMsgObj before calling this function. This
500 // prevents the CAN controller from working with invalid data.
501 //
502 //----------------------------------------------------------------------------
503 // @Returnvalue none
504 //
505 //----------------------------------------------------------------------------
506 // @Parameters Number of the message object to be configured (1-15)
507 // @Parameters Pointer on a data buffer
508 //
509 //----------------------------------------------------------------------------
510 // @Date 01-2-24 12:51:13
511 //
512 //****************************************************************************
513 void CAN_vLoadData(unsigned char ObjNr, unsigned char *pubBuffer)
514 {
515 unsigned char i;
516 CAN_OBJ[ObjNr-1].MCR1=0xfa;//set CPUUPD and NEWDAT
517 for(i=0;i<(CAN_OBJ[ObjNr-1].MCFG & 0xf0)>>4;i++)
518 {
519 CAN_OBJ[ObjNr-1].Data[i]= * (pubBuffer++);
520 }
521 CAN_OBJ[ObjNr-1].MCR1 = 0xf7; // reset CPUUPD
522 }
523 */
524
525 //****************************************************************************
526 // @Function void CAN_vConfigMsgObj(unsigned char ObjNr,unsigned int id,unsigned char pubBuffer)
527 //
528 //----------------------------------------------------------------------------
529 // @Description This function sets up the message objects. This includes
530 // the 8 data bytes, the identifier (11- or 29-bit), number (0-7 bytes) and
- the XTD-bit.
531 // The message is not sent; for this the function
532 // CAN_vTransmit must be called.
533 //
534 //----------------------------------------------------------------------------
535 // @Returnvalue none
536 //
537 //----------------------------------------------------------------------------
538 // @Parameters ObjNr---Number of the message object to be configured (1-15)
539 // id---identifier;
540 // pubBuffer---Pointer on a message object's data;
541 //
542 //----------------------------------------------------------------------------
543 // @Date 01-2-24 12:51:13
544 //
545 //****************************************************************************
546
547 void CAN_vConfigMsgObj(unsigned char ObjNr,unsigned int id,unsigned char *pubBuffer)
548 {
549 1 unsigned char i;
550 1 CAN_OBJ[ObjNr-1].MCR1=0xfa;//set CPUUPD and NEWDAT
C51 COMPILER V7.06 CAN 10/23/2004 16:55:18 PAGE 10
551 1 CAN_OBJ[ObjNr-1].MCR0=0x7f;
552 1 ///////configure identifier//////////
553 1 id=id<<5;
554 1 CAN_OBJ[ObjNr-1].UAR1=(unsigned char)(id % 256);
555 1 CAN_OBJ[ObjNr-1].UAR0=(unsigned char)(id/256);
556 1 ///////load data////////////
557 1
558 1 for(i=0;i<8;i++)
559 1 {
560 2 CAN_OBJ[ObjNr-1].Data[i]= * pubBuffer;
561 2 pubBuffer++;
562 2 wdt_refresh();
563 2 cs5045=0;
564 2 _nop_();
565 2 _nop_();
566 2 cs5045=1;
567 2 }
568 1 CAN_OBJ[ObjNr-1].MCR1 = 0xf7; // reset CPUUPD
569 1 CAN_OBJ[ObjNr-1].MCR0 = 0xbf;
570 1 }
571 //****************************************************************************
572 // @Function void CAN_vTransmit(unsigned char ObjNr)
573 //
574 //----------------------------------------------------------------------------
575 // @Description This function triggers the CAN controller to send the
576 // selected message.
577 // If the selected message object is a TRANSMIT OBJECT then
578 // this function triggers the sending of a data frame.
579 // If however the selected message object is a RECEIVE OBJECT
580 // this function triggers the sending of a remote frame.
581 // send a data frame or a romote frame
582 //----------------------------------------------------------------------------
583 // @Returnvalue none
584 //
585 //----------------------------------------------------------------------------
586 // @Parameters Number of the message object to be sent (1-14)
587 //
588 //----------------------------------------------------------------------------
589 // @Date 01-2-24 12:51:13
590 //
591 //****************************************************************************
592 void CAN_vTransmit(unsigned char ObjNr)
593 {
594 1 CAN_OBJ[ObjNr-1].MCR1 = 0xE7; // set TXRQ, reset CPUUPD
595 1 }
596
597 //****************************************************************************
598 //function: void error_warn(void);
599 //description: communication show ,if error warn
600 //parameter: none
601 //return: none
602 //****************************************************************************
603 //void error_warn(void)
604 //{
605 // ;
606 //}
607
608 //////////////////////////信息控制寄存器位操作函数///////////////////////////////
609 //****************************************************************************
610 // @Function bit read_msg_MCR(unsigend char ObjNr,MCR_BIT)
611 //
612 //----------------------------------------------------------------------------
C51 COMPILER V7.06 CAN 10/23/2004 16:55:18 PAGE 11
613 // @Description This function read one bit of the message object's control
614 // register.
615 //----------------------------------------------------------------------------
616 // @Returnvalue Bit value maybe "1" or "0"
617 //
618 //----------------------------------------------------------------------------
619 // @Parameters Number of the message object (1-15);
620 // Bit location of the message control register;
621 //----------------------------------------------------------------------------
622 // @Date 01-2-24 12:51:13
623 //
624 //****************************************************************************
625 /*
626 bit read_msg_MCR(ObjNr,MCR_BIT)
627 unsigned char ObjNr;
628 unsigned char MCR_BIT;
629 {
630 unsigned char MCR_temp;
631 bit temp_bit;
632 switch(MCR_BIT)
633 {
634 case MSGVAL:
635 MCR_temp=CAN_OBJ[ObjNr-1].MCR0; //read MCR0
636 if((MCR_temp & 0xc0)==0x80){temp_bit=1;} //if MSGVAL=1 then set temp_bit
637 if((MCR_temp & 0xc0)==0x40){temp_bit=0;} //if MSGVAL=0 then clear temp_bit
638 break;
639 case TXIE:
640 MCR_temp=CAN_OBJ[ObjNr-1].MCR0; //read MCR0
641 if((MCR_temp & 0x30)==0x20){temp_bit=1;} //if TXIE=1 then set temp_bit
642 if((MCR_temp & 0x30)==0x10){temp_bit=0;} //if TXIE=0 then clear temp_bit
643 break;
644 case RXIE:
645 MCR_temp=CAN_OBJ[ObjNr-1].MCR0; //read MCR0
646 if((MCR_temp & 0x0c)==0x08){temp_bit=1;} //if RXIE=1 then set temp_bit
647 if((MCR_temp & 0x0c)==0x04){temp_bit=0;} //if RXIE=0 then clear temp_bit
648 break;
649 case INTPND:
650 MCR_temp=CAN_OBJ[ObjNr-1].MCR0; //read MCR0
651 if((MCR_temp & 0x03)==0x02){temp_bit=1;} //if INTPND=1 then set temp_bit
652 if((MCR_temp & 0x03)==0x01){temp_bit=0;} //if INTPND=0 then clear temp_bit
653 break;
654 case RMTPND:
655 MCR_temp=CAN_OBJ[ObjNr-1].MCR1; //read MCR1
656 if((MCR_temp & 0xc0)==0x80){temp_bit=1;} //if RMTPND=1 then set temp_bit
657 if((MCR_temp & 0xc0)==0x40){temp_bit=0;} //if RMTPND=0 then clear temp_bit
658 break;
659 case TXRQ:
660 MCR_temp=CAN_OBJ[ObjNr-1].MCR1; //read MCR1
661 if((MCR_temp & 0x30)==0x20){temp_bit=1;} //if TXRQ=1 then set temp_bit
662 if((MCR_temp & 0x30)==0x10){temp_bit=0;} //if TXRQ=0 then clear temp_bit
663 break;
664 case CPUUPD:
665 MCR_temp=CAN_OBJ[ObjNr-1].MCR1; //read MCR1
666 if((MCR_temp & 0x0c)==0x08){temp_bit=1;} //if CPUUPD=1 then set temp_bit
667 if((MCR_temp & 0x0c)==0x04){temp_bit=0;} //if CPUUPD=0 then clear temp_bit
668 break;
669 case NEWDAT:
670 MCR_temp=CAN_OBJ[ObjNr-1].MCR1; //read MCR1
671 if((MCR_temp & 0x03)==0x02){temp_bit=1;} //if NEWDAT=1 then set temp_bit
672 if((MCR_temp & 0x03)==0x01){temp_bit=0;} //if NEWDAT=0 then clear temp_bit
673 break;
674 }
C51 COMPILER V7.06 CAN 10/23/2004 16:55:18 PAGE 12
675 return (temp_bit);
676 }
677 */
678 //****************************************************************************
679 // @Function void set_msg_MCR(unsigend char ObjNr,MCR_BIT,bit bit_value)
680 //
681 //----------------------------------------------------------------------------
682 // @Description This function set or reset one bit of the message object's control
683 // register.
684 //----------------------------------------------------------------------------
685 // @Returnvalue None
686 //
687 //----------------------------------------------------------------------------
688 // @Parameters Number of the message object (1-15);
689 // Bit location of the message control register;
690 // Bit value that will be set.
691 //----------------------------------------------------------------------------
692 // @Date 01-2-24 12:51:13
693 //
694 //****************************************************************************
695
696
697 //modify one bit of mesage object control regist
698 void set_msg_MCR(ObjNr,MCR_BIT,BIT_VALUE)
699 unsigned char ObjNr; //message object n(1~15).
700 unsigned char MCR_BIT; //MSGVAL,TXIE,RXIE etc.
701 bit BIT_VALUE; //bit value 0 or 1.
702 {
703 1 switch(MCR_BIT)
704 1 {
705 2 case MSGVAL:
706 2 if(BIT_VALUE)
707 2 {
708 3 CAN_OBJ[ObjNr-1].MCR0=0xbf;
709 3 }
710 2 else
711 2 {
712 3 CAN_OBJ[ObjNr-1].MCR0=0x7f;
713 3 }
714 2 break;
715 2 case TXIE:
716 2 if(BIT_VALUE)
717 2 {
718 3 CAN_OBJ[ObjNr-1].MCR0=0xef;
719 3 }
720 2 else
721 2 {
722 3 CAN_OBJ[ObjNr-1].MCR0=0xdf;
723 3 }
724 2 break;
725 2 case RXIE:
726 2 if(BIT_VALUE)
727 2 {
728 3 CAN_OBJ[ObjNr-1].MCR0=0xfb;
729 3 }
730 2 else
731 2 {
732 3 CAN_OBJ[ObjNr-1].MCR0=0xf7;
733 3 }
734 2 break;
735 2 case INTPND:
736 2 if(BIT_VALUE)
C51 COMPILER V7.06 CAN 10/23/2004 16:55:18 PAGE 13
737 2 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -