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

📄 can.c

📁 xc164的双can的使用例程
💻 C
📖 第 1 页 / 共 5 页
字号:
  CAN_MSGDRL254  =  0x0000;      // load data register 4 low
  CAN_MSGDRH254  =  0x0000;      // load data register 4 high

  ///  - functionality of standard message object

  CAN_MSGFGCRL25  =  0x0000;     // load FIFO/gateway control register low
  CAN_MSGFGCRH25  =  0x0019;     // load FIFO/gateway control register high

  CAN_MSGCTRH25  =  0x0000;      // load message control register high
  CAN_MSGCTRL25  =  0x5599;      // load message control register low

  ///  -----------------------------------------------------------------------
  ///  Configuration of Message Object 26:
  ///  -----------------------------------------------------------------------
  ///  - message object 26 is valid
  ///  - enable receive interrupt; bit INTPND is set after successfull 
  ///    reception of a frame

  ///  - message object is used as receive object
  ///  - standard 11-bit identifier
  ///  - 0 valid data bytes
  ///  - this message object works with CAN node A
  ///  - remote monitoring is disabled
  ///  - receive interrupt node pointer: TwinCAN SRN 0

  CAN_MSGCFGL26  =  0x0000;      // load message configuration register low
  CAN_MSGCFGH26  =  0x0000;      // load message configuration register high

  ///  - acceptance mask 11-bit: 0x7FF
  ///  - identifier 11-bit:      0x01B

  CAN_MSGAMRL26  =  0xFFFF;      // load acceptance mask register low
  CAN_MSGAMRH26  =  0xFFFF;      // load acceptance mask register high
  CAN_MSGARL26   =  0x0000;      // load arbitration register low
  CAN_MSGARH26   =  0x006C;      // load arbitration register high
  CAN_MSGDRL260  =  0x0000;      // load data register 0 low
  CAN_MSGDRH260  =  0x0000;      // load data register 0 high
  CAN_MSGDRL264  =  0x0000;      // load data register 4 low
  CAN_MSGDRH264  =  0x0000;      // load data register 4 high

  ///  - functionality of standard message object

  CAN_MSGFGCRL26  =  0x0000;     // load FIFO/gateway control register low
  CAN_MSGFGCRH26  =  0x001A;     // load FIFO/gateway control register high

  CAN_MSGCTRH26  =  0x0000;      // load message control register high
  CAN_MSGCTRL26  =  0x5599;      // load message control register low

  ///  -----------------------------------------------------------------------
  ///  Configuration of Message Object 27:
  ///  -----------------------------------------------------------------------
  ///  - message object 27 is valid
  ///  - enable receive interrupt; bit INTPND is set after successfull 
  ///    reception of a frame

  ///  - message object is used as receive object
  ///  - standard 11-bit identifier
  ///  - 0 valid data bytes
  ///  - this message object works with CAN node A
  ///  - remote monitoring is disabled
  ///  - receive interrupt node pointer: TwinCAN SRN 0

  CAN_MSGCFGL27  =  0x0000;      // load message configuration register low
  CAN_MSGCFGH27  =  0x0000;      // load message configuration register high

  ///  - acceptance mask 11-bit: 0x7FF
  ///  - identifier 11-bit:      0x01C

  CAN_MSGAMRL27  =  0xFFFF;      // load acceptance mask register low
  CAN_MSGAMRH27  =  0xFFFF;      // load acceptance mask register high
  CAN_MSGARL27   =  0x0000;      // load arbitration register low
  CAN_MSGARH27   =  0x0070;      // load arbitration register high
  CAN_MSGDRL270  =  0x0000;      // load data register 0 low
  CAN_MSGDRH270  =  0x0000;      // load data register 0 high
  CAN_MSGDRL274  =  0x0000;      // load data register 4 low
  CAN_MSGDRH274  =  0x0000;      // load data register 4 high

  ///  - functionality of standard message object

  CAN_MSGFGCRL27  =  0x0000;     // load FIFO/gateway control register low
  CAN_MSGFGCRH27  =  0x001B;     // load FIFO/gateway control register high

  CAN_MSGCTRH27  =  0x0000;      // load message control register high
  CAN_MSGCTRL27  =  0x5599;      // load message control register low

  ///  -----------------------------------------------------------------------
  ///  Configuration of Message Object 28:
  ///  -----------------------------------------------------------------------
  ///  - message object 28 is valid
  ///  - enable receive interrupt; bit INTPND is set after successfull 
  ///    reception of a frame

  ///  - message object is used as receive object
  ///  - standard 11-bit identifier
  ///  - 0 valid data bytes
  ///  - this message object works with CAN node A
  ///  - remote monitoring is disabled
  ///  - receive interrupt node pointer: TwinCAN SRN 0

  CAN_MSGCFGL28  =  0x0000;      // load message configuration register low
  CAN_MSGCFGH28  =  0x0000;      // load message configuration register high

  ///  - acceptance mask 11-bit: 0x7FF
  ///  - identifier 11-bit:      0x01D

  CAN_MSGAMRL28  =  0xFFFF;      // load acceptance mask register low
  CAN_MSGAMRH28  =  0xFFFF;      // load acceptance mask register high
  CAN_MSGARL28   =  0x0000;      // load arbitration register low
  CAN_MSGARH28   =  0x0074;      // load arbitration register high
  CAN_MSGDRL280  =  0x0000;      // load data register 0 low
  CAN_MSGDRH280  =  0x0000;      // load data register 0 high
  CAN_MSGDRL284  =  0x0000;      // load data register 4 low
  CAN_MSGDRH284  =  0x0000;      // load data register 4 high

  ///  - functionality of standard message object

  CAN_MSGFGCRL28  =  0x0000;     // load FIFO/gateway control register low
  CAN_MSGFGCRH28  =  0x001C;     // load FIFO/gateway control register high

  CAN_MSGCTRH28  =  0x0000;      // load message control register high
  CAN_MSGCTRL28  =  0x5599;      // load message control register low

  ///  -----------------------------------------------------------------------
  ///  Configuration of Message Object 29:
  ///  -----------------------------------------------------------------------
  ///  - message object 29 is valid
  ///  - enable receive interrupt; bit INTPND is set after successfull 
  ///    reception of a frame

  ///  - message object is used as receive object
  ///  - standard 11-bit identifier
  ///  - 0 valid data bytes
  ///  - this message object works with CAN node A
  ///  - remote monitoring is disabled
  ///  - receive interrupt node pointer: TwinCAN SRN 0

  CAN_MSGCFGL29  =  0x0000;      // load message configuration register low
  CAN_MSGCFGH29  =  0x0000;      // load message configuration register high

  ///  - acceptance mask 11-bit: 0x7FF
  ///  - identifier 11-bit:      0x01E

  CAN_MSGAMRL29  =  0xFFFF;      // load acceptance mask register low
  CAN_MSGAMRH29  =  0xFFFF;      // load acceptance mask register high
  CAN_MSGARL29   =  0x0000;      // load arbitration register low
  CAN_MSGARH29   =  0x0078;      // load arbitration register high
  CAN_MSGDRL290  =  0x0000;      // load data register 0 low
  CAN_MSGDRH290  =  0x0000;      // load data register 0 high
  CAN_MSGDRL294  =  0x0000;      // load data register 4 low
  CAN_MSGDRH294  =  0x0000;      // load data register 4 high

  ///  - functionality of standard message object

  CAN_MSGFGCRL29  =  0x0000;     // load FIFO/gateway control register low
  CAN_MSGFGCRH29  =  0x001D;     // load FIFO/gateway control register high

  CAN_MSGCTRH29  =  0x0000;      // load message control register high
  CAN_MSGCTRL29  =  0x5599;      // load message control register low

  ///  -----------------------------------------------------------------------
  ///  Configuration of Message Object 30:
  ///  -----------------------------------------------------------------------
  ///  - message object 30 is valid
  ///  - enable receive interrupt; bit INTPND is set after successfull 
  ///    reception of a frame

  ///  - message object is used as receive object
  ///  - standard 11-bit identifier
  ///  - 0 valid data bytes
  ///  - this message object works with CAN node A
  ///  - remote monitoring is disabled
  ///  - receive interrupt node pointer: TwinCAN SRN 0

  CAN_MSGCFGL30  =  0x0000;      // load message configuration register low
  CAN_MSGCFGH30  =  0x0000;      // load message configuration register high

  ///  - acceptance mask 11-bit: 0x7FF
  ///  - identifier 11-bit:      0x01F

  CAN_MSGAMRL30  =  0xFFFF;      // load acceptance mask register low
  CAN_MSGAMRH30  =  0xFFFF;      // load acceptance mask register high
  CAN_MSGARL30   =  0x0000;      // load arbitration register low
  CAN_MSGARH30   =  0x007C;      // load arbitration register high
  CAN_MSGDRL300  =  0x0000;      // load data register 0 low
  CAN_MSGDRH300  =  0x0000;      // load data register 0 high
  CAN_MSGDRL304  =  0x0000;      // load data register 4 low
  CAN_MSGDRH304  =  0x0000;      // load data register 4 high

  ///  - functionality of standard message object

  CAN_MSGFGCRL30  =  0x0000;     // load FIFO/gateway control register low
  CAN_MSGFGCRH30  =  0x001E;     // load FIFO/gateway control register high

  CAN_MSGCTRH30  =  0x0000;      // load message control register high
  CAN_MSGCTRL30  =  0x5599;      // load message control register low

  ///  -----------------------------------------------------------------------
  ///  Configuration of Message Object 31:
  ///  -----------------------------------------------------------------------
  ///  - message object 31 is valid
  ///  - enable receive interrupt; bit INTPND is set after successfull 
  ///    reception of a frame

  ///  - message object is used as receive object
  ///  - standard 11-bit identifier
  ///  - 0 valid data bytes
  ///  - this message object works with CAN node A
  ///  - remote monitoring is disabled
  ///  - receive interrupt node pointer: TwinCAN SRN 0

  CAN_MSGCFGL31  =  0x0000;      // load message configuration register low
  CAN_MSGCFGH31  =  0x0000;      // load message configuration register high

  ///  - acceptance mask 11-bit: 0x7FF
  ///  - identifier 11-bit:      0x020

  CAN_MSGAMRL31  =  0xFFFF;      // load acceptance mask register low
  CAN_MSGAMRH31  =  0xFFFF;      // load acceptance mask register high
  CAN_MSGARL31   =  0x0000;      // load arbitration register low
  CAN_MSGARH31   =  0x0080;      // load arbitration register high
  CAN_MSGDRL310  =  0x0000;      // load data register 0 low
  CAN_MSGDRH310  =  0x0000;      // load data register 0 high
  CAN_MSGDRL314  =  0x0000;      // load data register 4 low
  CAN_MSGDRH314  =  0x0000;      // load data register 4 high

  ///  - functionality of standard message object

  CAN_MSGFGCRL31  =  0x0000;     // load FIFO/gateway control register low
  CAN_MSGFGCRH31  =  0x001F;     // load FIFO/gateway control register high

  CAN_MSGCTRH31  =  0x0000;      // load message control register high
  CAN_MSGCTRL31  =  0x5599;      // load message control register low


  ///  -----------------------------------------------------------------------
  ///  Configuration of Service Request Nodes 0 - 7:
  ///  -----------------------------------------------------------------------
  ///  SRN0 service request node configuration:
  ///  - SRN0 interrupt priority level (ILVL) = 8
  ///  - SRN0 interrupt group level (GLVL) = 2
  ///  - SRN0 group priority extension (GPX) = 0

  CAN_0IC        =  0x0062;     



  // USER CODE BEGIN (Init,3)

  // USER CODE END


  CAN_PISEL      =  0x0008;      // load port input select register

  //   -----------------------------------------------------------------------
  //   Start the CAN Nodes:
  //   -----------------------------------------------------------------------

  CAN_ACR       &= ~(uword)0x0041; // reset INIT and CCE
  CAN_BCR       &= ~(uword)0x0041; // reset INIT and CCE


  // USER CODE BEGIN (Init,4)

  // USER CODE END

} //  End of function CAN_vInit


//****************************************************************************
// @Function      void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj) 
//
//----------------------------------------------------------------------------
// @Description   This function fills the forwarded SW message object with 
//                the content of the chosen HW message object.
//                
//                The structure of the SW message object is defined in the 
//                header file CAN.H (see TCAN_SWObj).
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    ubObjNr: 
//                Number of the message object to be read (0-31)
// @Parameters    *pstObj: 
//                Pointer on a message object to be filled by this function
//
//----------------------------------------------------------------------------
// @Date          12/17/2004
//
//****************************************************************************

// USER CODE BEGIN (GetMsgObj,1)

// U

⌨️ 快捷键说明

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