mikroElektronika PIC Microcontrollers PIC12 User Manual page 168

Mikroc user's manual
Table of Contents

Advertisement

mikroC - C Compiler for Microchip PIC microcontrollers
// .. continued
// Initialize external CAN module
CANSPIInitialize(1,1,3,3,1,aa);
// Set CANSPI to CONFIG mode
CANSPISetOperationMode(CAN_MODE_CONFIG,_TRUE);
ID = -1;
// Set all mask1 bits to ones
CANSPISetMask(CAN_MASK_B1,id,CAN_CONFIG_XTD_MSG);
// Set all mask2 bits to ones
CANSPISetMask(CAN_MASK_B2,id,CAN_CONFIG_XTD_MSG);
// Set id of filter B1_F1 to 12111
CANSPISetFilter(CAN_FILTER_B2_F4,12111,CAN_CONFIG_XTD_MSG);
// Set CANSPI to NORMAL mode
CANSPISetOperationMode(CAN_MODE_NORMAL,_TRUE);
while (1) {
zr = CANSPIRead(&id , &Data , &len, &aa2);
if (id == 12111 & zr )
PORTB = data[0]++ ;
id = 3;
Delay_ms(500);
// Send incremented data back
CANSPIWrite(id,&data,1,aa1);
// If message contains 2 data bytes, output second byte at PORTD
if (len == 2) PORTD = data[1];
}
}
}//~!
page
160
{
MikroElektronika: Development tools - Books - Compilers
// Receive data, if any
// Output data on PORTB
mikroC
making it simple...

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?

This manual is also suitable for:

Pic microcontrollers pic16Pic microcontrollers pic18

Table of Contents