mikroElektronika PIC Microcontrollers PIC12 User Manual page 167

Mikroc user's manual
Table of Contents

Advertisement

mikroC
making it simple...
Library Example
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
const char _FALSE = 0x00;
void main(){
TRISB = 0;
Spi_Init();
TRISC.F2 = 0;
PORTC.F2 = 0;
PORTC.F0 = 1;
TRISC.F0 = 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;
// Form value to be used with CANSPISendMessage
aa1 = CAN_TX_PRIORITY_0 &
CAN_TX_XTD_FRAME &
CAN_TX_NO_RTR_FRAME;
PORTC.F0 = 1;
// continues ..
MikroElektronika: Development tools - Books - Compilers
= 0xFF;
// Initialize SPI module
// Clear (TRISC,2)
// Clear (PORTC,2)
// Set
(PORTC,0)
// Clear (TRISC,0)
&
&
// Set (PORTC,2)
// Set (PORTC,0)
mikroC - C Compiler for Microchip PIC microcontrollers
page
159

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