mikroC
making it simple...
Library Example
mikroC - C Compiler for Microchip PIC microcontrollers
The code is a simple demonstration of CANSPI protocol. It is a simple data exchange between 2 PIC’s, where data is incremented upon each bounce. Data is printed on PORTC (lower byte) and PORTD (higher byte) for a visual check.
char data[8],aa, aa1, len, aa2; long id;
char zr; |
|
|
|
const char _TRUE | = 0xFF; |
| |
const char _FALSE = 0x00; |
| ||
void main(){ |
|
| |
TRISB | = 0; |
|
|
Spi_Init(); | // Initialize SPI module | ||
TRISC.F2 = 0; // Clear (TRISC,2) | |||
PORTC.F2 = 0; // Clear (PORTC,2) | |||
PORTC.F0 = 1; | // Set | (PORTC,0) | |
TRISC.F0 = 0; // Clear (TRISC,0) | |||
PORTD = 0; |
|
| |
TRISD = 0; |
|
| |
aa | = 0; |
|
|
aa1 | = 0; |
|
|
aa2 | = 0; |
|
|
//Form value to be used with CANSPIInitialize aa = CAN_CONFIG_SAMPLE_THRICE &
CAN_CONFIG_PHSEG2_PRG_ON &
CAN_CONFIG_STD_MSG & CAN_CONFIG_DBL_BUFFER_ON & CAN_CONFIG_VALID_XTD_MSG;
PORTC.F2 = 1; // Set (PORTC,2)
//Form value to be used with CANSPISendMessage aa1 = CAN_TX_PRIORITY_0 &
CAN_TX_XTD_FRAME & CAN_TX_NO_RTR_FRAME;
PORTC.F0 = 1; // Set (PORTC,0)
// continues ..
|
| page |
|
MikroElektronika: Development tools - Books - Compilers | 159 | ||
|
|