ABL electronic PIC12 Personal Computer User Manual


 
MikroElektronika:
Development
tools
-
Books
-
Compilers
15 1
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
// .. continued
// Set all mask1 bits to ones
CANSetMask(CAN_MASK_B1,ID,CAN_CONFIG_XTD_MSG);
// Set all mask2 bits to ones
CANSetMask(CAN_MASK_B2,ID,CAN_CONFIG_XTD_MSG);
// Set id of filter B1_F1 to 3
CANSetFilter(CAN_FILTER_B2_F3,3,CAN_CONFIG_XTD_MSG);
// Set CAN to NORMAL mode
CANSetOperationMode(CAN_MODE_NORMAL,0xFF);
PORTD = 0xFF;
id = 12111;
CANWrite(id,data,1,aa1);
// Send message via CAN
while (1) {
oldstate = 0;
zr = CANRead(&id, data , &len, &aa2);
if ((id == 3) & zr) {
PORTD = 0xAA;
PORTC = data[0];
// Output data at PORTC
data[0]++ ;
// If message contains two data bytes, output second byte at PORTD
if (len == 2) PORTD = data[1];
data[1] = 0xFF;
id = 12111;
CANWrite(id, data, 2,aa1);
// Send incremented data back
}
}
}
//~!