Chapter 3 Software Programming
19
Example program
The following example program, can84 I.lib, implements the sending
and receiving of messages over the CAN controller. The program is
written in C.
#include "can841.h" /*Library function declaration*/
/*------------------------------------------------*/
/* CAN controller interrupt connection */
#define CAN1_IRQ 12 /* 0 means polling */
#define CAN2_IRQ 15 /* 0 means polling */
#define PORT1 0
#define PORT2 1
#define FAIL 0
#define SUCCESS 1
void main(void)
(
/* Declare the CAN card segment address. */
UI gSegment=OxDA00;
CAN_STRUCT canl, can2;
MSG_STRUCT smsql, smsg2;
MSG_STRUCT rmsql, rmsg2;
UI i;
if(canInitHW(gSegment,CANl_IRQ,CAN2 IRQ)==FAIL)
{
clrscr();
cprintf(“\n\n Hardware Initialization Error.’);
return;
}
/* Reset CAN controller */
canReset(PORT1);
canReset(PORT2);
canl.acc_code=0;
/*
*/
canl.acc mask=Oxff;
/*
*/
canl.btO=03;
/* baud rate lMbps
*/
canl.btl=0xlc;
if(canConfig(PORTl,canl)==FAIL)
{
clrscr();
cprintf("\n\n CAN Port %d Configuration Error",1);
return;
{
Summary of Contents for PCL-841 Series
Page 2: ...1 Introduction C H A P T E R ...
Page 5: ...4 PCL 841 Series User s Manual ...
Page 6: ...2 Hardware Installation C H A P T E R ...
Page 8: ...Chapter 2 Hardware Installation 7 Jumper and switch locations ...
Page 13: ...12 PCL 841 Series User s Manual ...
Page 14: ...3 Software Programming C H A P T E R ...
Page 22: ...4 DataMonitor Utility C H A P T E R ...
Page 28: ...5 Wiring C H A P T E R ...
Page 31: ...30 PCL 841 Series User s Manual ...