Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
259
CAN_FILTER Constants
CAN_FILTER
 constants define filter codes. Function CANxSetFilter expects one of these as its argument:
Copy Code To Clipboard 
const
    _CAN_FILTER_B1_F1 as word = 0
    _CAN_FILTER_B1_F2 as word = 1
    _CAN_FILTER_B2_F1 as word = 2
    _CAN_FILTER_B2_F2 as word = 3
    _CAN_FILTER_B2_F3 as word = 4
    _CAN_FILTER_B2_F4 as word = 5
Library Example
The example demonstrates CAN protocol. The 1st node initiates the communication with the 2nd node by sending 
some data to its address. The 2nd node responds by sending back the data incremented by 1. The 1st node then does 
the same and sends incremented data back to the 2nd node, etc.
Code for the first CAN node:
Copy Code To Clipboard 
program CAN_1st
dim Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags, Rx_Data_Len as word
    RxTx_Data as byte[8]
    Rx_ID     as longint
    Msg_Rcvd  as word
const ID_1st as longint = 12111
const ID_2nd as longint = 3                           ‘ node IDs
main:
  ADPCFG = 0xFFFF
  PORTB  = 0
  TRISB  = 0
  Can_Init_Flags   = 0
  Can_Send_Flags   = 0
  Can_Rcv_Flags    = 0
Can_Send_Flags   = _CAN_TX_PRIORITY_0 and           ‘ form value to be used
                     _CAN_TX_XTD_FRAME and          ‘ with CANSendMessage
                     _CAN_TX_NO_RTR_FRAME
Can_Init_Flags   = _CAN_CONFIG_SAMPLE_THRICE and    ‘ form value to be used
                     _CAN_CONFIG_PHSEG2_PRG_ON and  ‘ with CANInitialize
                     _CAN_CONFIG_XTD_MSG and
                     _CAN_CONFIG_DBL_BUFFER_ON and
                     _CAN_CONFIG_MATCH_MSG_TYPE and
                     _CAN_CONFIG_LINE_FILTER_OFF