Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CAN program for pic18f4580

Status
Not open for further replies.

priya ravichander

Newbie level 4
Newbie level 4
Joined
Aug 15, 2013
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
69

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
void main()
{
unsigned char temperature, data[8];
unsigned short init_flag, send_flag, dt, len, read_flag;
char SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg, txt[4];
unsigned int temp;
unsigned long mV;
long id, mask;
TRISA = 0xFF; // PORTA are inputs
TRISB = 0x08; // RB2 is output, RB3 is input
//
// Configure A/D converter
//
ADCON1 = 0x80;
//
// CAN BUS Timing Parameters
//
SJW = 1;
BRP = 1;
Phase_Seg1 = 6;
Phase_Seg2 = 7;
BRP = 1;
Prop_Seg = 6;
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;
send_flag = CAN_TX_PRIORITY_0 &
CAN_TX_XTD_FRAME &
CAN_TX_NO_RTR_FRAME;
read_flag = 0;
//
// Initialise CAN module
//
CANInitialize(SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg, init_flag);
//
// Set CAN CONFIG mode
//
CANSetOperationMode(CAN_MODE_CONFIG, 0xFF);
mask = -1;
//
// Set all MASK1 bits to 1's
//
CANSetMask(CAN_MASK_B1, mask, CAN_CONFIG_XTD_MSG);
//
// Set all MASK2 bits to 1's
//
CANSetMask(CAN_MASK_B2, mask, CAN_CONFIG_XTD_MSG);
//
// Set id of filter B1_F1 to 3
//
CANSetFilter(CAN_FILTER_B2_F3,500,CAN_CONFIG_XTD_MSG);
//
// Set CAN module to NORMAL mode
//
CANSetOperationMode(CAN_MODE_NORMAL, 0xFF);
//
// Program loop. Read the temperature from analog temperature
// sensor
//
for(;;) // Endless loop
{
//
// Wait until a request is received
//
dt = 0;
while(!dt) dt = CANRead(&id, data, &len, &read_flag);
if(id == 500 && data[0] == 'T')
{
//
// Now read the temperature
//
temp = Adc_Read(0); // Read temp
mV = (unsigned long)temp * 5000 / 1024; // in mV
temperature = mV/10; // in degrees C
//
// send the temperature to Node:Display
//
data[0] = temperature;
id = 3; // Identifier
CANWrite(id, data, 1, send_flag); // send temperature
}
}
}



get me the header for this program and compiler to be used for this program
 
Last edited by a moderator:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
void main()
{
unsigned char temperature, data[8];
unsigned short init_flag, send_flag, dt, len, read_flag;
char SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg, txt[4];
unsigned int temp;
unsigned long mV;
long id, mask;
TRISA = 0xFF; // PORTA are inputs
TRISB = 0x08; // RB2 is output, RB3 is input
//
// Configure A/D converter
//
ADCON1 = 0x80;
//
// CAN BUS Timing Parameters
//
SJW = 1;
BRP = 1;
Phase_Seg1 = 6;
Phase_Seg2 = 7;
BRP = 1;
Prop_Seg = 6;
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;
send_flag = CAN_TX_PRIORITY_0 &
CAN_TX_XTD_FRAME &
CAN_TX_NO_RTR_FRAME;
read_flag = 0;
//
// Initialise CAN module
//
CANInitialize(SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg, init_flag);
//
// Set CAN CONFIG mode
//
CANSetOperationMode(CAN_MODE_CONFIG, 0xFF);
mask = -1;
//
// Set all MASK1 bits to 1's
//
CANSetMask(CAN_MASK_B1, mask, CAN_CONFIG_XTD_MSG);
//
// Set all MASK2 bits to 1's
//
CANSetMask(CAN_MASK_B2, mask, CAN_CONFIG_XTD_MSG);
//
// Set id of filter B1_F1 to 3
//
CANSetFilter(CAN_FILTER_B2_F3,500,CAN_CONFIG_XTD_MSG);
//
// Set CAN module to NORMAL mode
//
CANSetOperationMode(CAN_MODE_NORMAL, 0xFF);
//
// Program loop. Read the temperature from analog temperature
// sensor
//
for(;;) // Endless loop
{
//
// Wait until a request is received
//
dt = 0;
while(!dt) dt = CANRead(&id, data, &len, &read_flag);
if(id == 500 && data[0] == 'T')
{
//
// Now read the temperature
//
temp = Adc_Read(0); // Read temp
mV = (unsigned long)temp * 5000 / 1024; // in mV
temperature = mV/10; // in degrees C
//
// send the temperature to Node:Display
//
data[0] = temperature;
id = 3; // Identifier
CANWrite(id, data, 1, send_flag); // send temperature
}
}
}



from where i can get the header files

- - - Updated - - -

pls send me the header files
 
Last edited by a moderator:

As thannara123 has already mentioned, it would be difficult to accommodate such a request without knowing the origin of the code.

You also maybe missing more than a header file, as the entire source for the CAN Driver implementation appears to be missing.

You would be better off stating your app requirements, the intended compiler toolset and request recommendations.

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top