mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

//.. 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);

// Receive data, if any

if (id == 12111 & zr ) {

 

PORTB = data[0]++ ;

// Output data on PORTB

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