User`s manual
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
CAN (Controller Area Network) module is available with a number of PIC MCU
models. mikroBasic includes a set of library routines to provide you comfortable
work with the module.
CAN routines are currently supported by PIC MCU models P18XXX8.
Microcontroller must be connected to CAN tranceiver (MCP2551 or similar)
which is connected to CAN bus.
The Controller Area Network module is a serial interface, useful for communicat-
ing with other peripherals or microcontrollers. Details about CAN can be found in
appropriate literature and on mikroElektronika Web site.
Following routines can be considered a driver for CAN module on PIC MCUs.
MikroElektronika:
Development
tools
-
Books
-
Compilers
mikroBASIC
making it simple...
113
page
CAN Library
sub procedure CANSetOperationMode(dim mode as byte, dim WAIT as byte)
sub function CANGetOperationMode as byte
sub procedure CANInitialize(dim SJW as byte, dim BRP as byte, dim PHSEG1 as byte,
dim PHSEG2 as byte, dim PROPSEG as byte,dim CAN_CONFIG_FLAGS as byte)
sub procedure CANSetBaudRate(dim SJW as byte, dim BRP as byte, dim PHSEG1 as byte,
dim PHSEG2 as byte, dim PROPSEG as byte,dim CAN_CONFIG_FLAGS as byte)
sub procedure CANSetMask(dim CAN_MASK as byte, dim val as longint, dim CAN_CONFIG_FLAGS as byte)
sub procedure CANSetFilter(dim CAN_FILTER as byte, dim val as longint,
dim CAN_CONFIG_FLAGS as byte)
sub function RegsToCANID(dim byref ptr as byte, dim CAN_CONFIG_FLAGS as byte) as longint
sub procedure CANIDToRegs(dim byref ptr as byte, dim val as longint, dim CAN_CONFIG_FLAGS as
byte)
sub function CANwrite(dim id as longint, dim byref Data as byte[8], dim DataLen as byte,
dim CAN_TX_MSG_FLAGS as byte) as byte
sub function CANread(dim byref id as longint, dim byref Data as byte[8],
dim byref DataLen as byte, dim byref CAN_RX_MSG_FLAGS as byte) as byte