
The COLLECTOR processor reads the temperature, formats it, and sends to the
DISPLAY processor over the CAN bus
The DISPLAY processor reads the temperature from the CAN bus and then
displays it on the LCD
This process is repeated every second
DISPLAY Program
Figure 9.17 shows the program listing of the DISPLAY program, called DISPLAY.C.
At the beginning of the program PORTC pins are configured as outputs, RB3 is
configured as input (CANRX), and RB2 is configured as output (CANTX). In this
project the CAN bus bit rate is selected as 100Kb/s. With a microcontroller clock
frequency of 8MHz, the Baud Rate Calculator program (see Figure 9.14) is used to
calculate the timing parameters as:
SJW ¼ 1
BRP ¼ 1
Phase_Seg1 ¼ 6
Phase_Seg2 ¼ 7
Prop_Seg ¼ 6
The mikroC CAN bus function CANInitialize is used to initialize the CAN module. The
timing parameters and the initialization flag are specified as arguments in this function.
The initialization flag is made up from the bitwise AND of:
init_flag ¼ CAN_CONFIG_SAMPLE_THRICE &
CAN_CONFIG_PHSEG2_PRG_ON &
CAN_CONFIG_STD_MSG &
CAN_CONFIG_DBL_BUFFER_ON &
CAN_CONFIG_VALID_XTD_MSG &
CAN_CONFIG_LINE_FILTER_OFF;
Where sampling the bus three times is specified, the standard identifier is specified,
double buffering is turned on, and the line filter is turned off.
Then the operation mode is set to CONFIG and the filter masks and filter values are specified.
Bothmask1andmask2aresettoall1’s(1 is a shorthand way of writing hexadecimal
FFFFFFFF, i.e., setting all mask bits to 1’s) so that all filter bits match up with incoming data.
www.newnespress.com
507Advanced PIC18 Projects—CAN Bus Projects
Comentarios a estos manuales