LTlib LaurTec Library
4.0.1
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
main.c
Go to the documentation of this file.
1
#include <xc.h>
2
3
#include "
LTlib.h
"
4
5
#include "
module_IO.h
"
6
#include "
module_IO.c
"
7
8
#include "
module_CAN.h
"
9
#include "
module_CAN.c
"
10
11
#define BUTTON_PRESSED 0x00
12
13
#define BUTTON1 PORTBbits.RB4
14
#define BUTTON2 PORTBbits.RB5
15
#define BUTTON3 PORTBbits.RB6
16
#define BUTTON4 PORTBbits.RB7
17
18
int
main
(
void
) {
19
20
BYTE
info [8];
21
CANmessage
msg;
22
23
IO_set_all_ports_as_inputs
();
24
25
IO_set_port_direction
(
IO_PORTD
,
IO_ALL_PORT_OUTPUT
);
26
27
IO_enable_pull_up_resistors
(
IO_PORTB
,
IO_BIT4
+
IO_BIT5
+
IO_BIT6
+
IO_BIT7
);
28
29
//*********************************************************
30
// CAN Library Test
31
//*********************************************************
32
//Initialize at 125Kbits/s 16xTq
33
// 16MHz 125Kb/s --> 2,7,6,1,3
34
// 20MHz 125Kb/s --> 2,7,6,1,4
35
CAN_open
(2,7,6,1,4,
CAN_CONFIG_LINE_FILTER_OFF
&
36
CAN_CONFIG_SAMPLE_ONCE
&
37
CAN_CONFIG_ALL_VALID_MSG
&
38
CAN_CONFIG_DBL_BUFFER_ON
);
39
40
41
//Monitor all the buttons
42
while
(1){
43
44
info[0] = 0x00;
45
46
if
(
BUTTON1
==
BUTTON_PRESSED
){
47
info[0] = 0x01;
48
}
49
50
if
(
BUTTON2
==
BUTTON_PRESSED
){
51
info[0] = 0x02;
52
}
53
54
if
(
BUTTON3
==
BUTTON_PRESSED
){
55
info[0] = 0x04;
56
}
57
58
if
(
BUTTON4
==
BUTTON_PRESSED
){
59
info[0] = 0x08;
60
}
61
62
63
//Check if any button was pressed
64
if
(info[0] > 0) {
65
66
while
(!
CAN_is_TX_ready
());
67
68
CAN_write_message
(0x0A005510, info,1,
CAN_TX_XTD_FRAME
&
69
CAN_NORMAL_TX_FRAME
&
70
CAN_TX_PRIORITY_2
);
71
}
72
73
//Check if any data was received
74
if
(
CAN_is_RX_ready
()) {
75
CAN_read_message
(&msg);
76
77
LATD = msg.
data
[0];
78
}
79
80
}
81
}
LTlib_v_4.0.1
ex
PIC18
_module_CAN
01 - CAN_TX_RX_Example.X
main.c
Generated on Sat Mar 12 2016 11:01:40 for LTlib LaurTec Library by
1.8.3.1