LTlib LaurTec Library  4.0.0 Beta
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 
2 #include <xc.h>
3 
4 #include "LTlib.h"
5 
6 #include "module_IO.h"
7 #include "module_IO.c"
8 
9 #include "delay.h"
10 #include "delay.c"
11 
12 #include "module_SPI.h"
13 #include "module_SPI.c"
14 
15 #include "MCP4822.h"
16 #include "MCP4822.c"
17 
18 
19 //*************************************
20 // Voltage reference
21 //*************************************
22 
23 #define REFERENCE_0000 0
24 #define REFERENCE_1500 1500
25 #define REFERENCE_1800 1800
26 #define REFERENCE_3300 3300
27 
28 //*************************************
29 // Constants
30 //*************************************
31 
32 #define STATUS_ON 0x01
33 #define STATUS_OFF 0x00
34 
35 #define WAIT_TIME 1000
36 #define DEBOUNCE_TIME 10
37 
38 #define BUTTON_1 IO_BIT4
39 #define BUTTON_2 IO_BIT5
40 #define BUTTON_3 IO_BIT6
41 #define BUTTON_4 IO_BIT7
42 #define BUTTON_PRESSED 0x00
43 
44 
45 int main (void) {
46 
47  unsigned char system_status = STATUS_OFF;
48  unsigned int last_voltage = REFERENCE_0000;
49 
53 
55 
57 
58  while (1) {
59 
60  //*************************************
61  // BT1
62  //*************************************
63 
65 
67 
70  last_voltage = REFERENCE_1500;
71  }
72  }
73 
74  //*************************************
75  // BT2
76  //*************************************
77 
79 
81 
84  last_voltage = REFERENCE_1800;
85  }
86  }
87 
88  //*************************************
89  // BT3
90  //*************************************
92 
94 
97  last_voltage = REFERENCE_3300;
98  }
99 
100  }
101 
102  //*************************************
103  // BT4
104  //*************************************
105 
106  if (IO_read_port_bit(IO_PORTB, BUTTON_4) == BUTTON_PRESSED && system_status == STATUS_ON){
107 
109 
113 
115  system_status = STATUS_OFF;
116  delay_ms (1000);
117  }
118  }
119 
120  if (IO_read_port_bit(IO_PORTB, BUTTON_4) == BUTTON_PRESSED && system_status == STATUS_OFF){
121 
123 
126  MCP4822_set_amplitude (last_voltage, MCP4822_DAC_A);
127 
129  system_status = STATUS_ON;
130  delay_ms (1000);
131  }
132  }
133  }
134 }