////////////////////////////////////////////////////////////////////////
//
// can_set_mode
//
// This function first sets three most significant bits (reqop2:reqop0)
// to the mode given through the argument. The modes can be
//
// mode
//
// 1xx -> Configuration Mode
// This mode allows the user to configure the Control Registers,
// the Acceptance Mask Registers and the Acceptance Filter
// Registers.
//
// 011 -> Listen Only Mode
// This mode allows the PIC microcontroller to listen to the
// bus but not actually write to it.
//
// 010 -> Loop Back Mode
// This mode allows to the transmission of data directly from
// the Transmission Buffers to the Recive Buffers without
// actually driving any data to the bus
//
// 001 -> Dissable Mode
// This mode prefents the PIC microcontroller from transmitting
// and reciving, however the WAKIF interrupt is still active
//
// 000 -> Normal Mode
// This is the normal mode of opperation for the CAN bus. It
// will recive all messages and is the only mode in which
// data can be transmitted.
//
// The reqop bits do not immediatly change the mode of operation, the
// three most significant bits in the CANSTAT register (opmode2:opmode0)
// must change to reflect the actuall change in mode, therefore a while
// statement is used to check if the CANSTAT opmode bits have changed to
// reflect the passed in mode
//
// More information can be found in the PIC18F4580 datasheet section 23.3
////////////////////////////////////////////////////////////////////////
void can_set_mode(CAN_OP_MODE mode) {
CANCON.reqop=mode;
while( (CANSTAT.opmode) != mode );
}