LTlib LaurTec Library  4.0.1
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 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 
24 
26 
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
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 &
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 }