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 #include <xc.h>
34 #include "MainBrain.h"
35
36 int ADC0_result;
37 float ADC6_result;
38
39
40 const uint16_t TMR1_FREQ_SET = 0xe500;
41
42
43 void TMR1_init(void)
44 {
45 IPC1bits.T1IP = 6;
46 IPC1bits.T1IS = 3;
47
48 IEC0bits.T1IE = 1;
49
50 T1CON = 0;
51 T1CONbits.TCKPS = 0;
52 IFS0bits.T1IF = 0;
53 T1CONbits.ON = 1;
54 }
55
56
57 void TMR2_init(void)
58 {
59 IPC2bits.T2IP = 6;
60 IPC2bits.T2IS = 2;
61
62 IEC0bits.T2IE = 0;
63
64 T2CONbits.ON = 1;
65 }
66
67
68 void TMR3_init(void)
69 {
70 T3CONbits.ON = 0;
71
72 IPC3bits.T3IP = 6;
73 IPC3bits.T3IS = 1;
74
75
76 T3CONbits.TCKPS = 4;
77
78
79
80 PR3 = 0xA702;
81
82 IEC0bits.T3IE = 1;
83
84 T3CONbits.ON = 0;
85 }
86
87 void TMR4_init(void)
88 {
89 T4CONbits.ON = 0;
90 IPC4bits.T4IP = 5;
91 IPC4bits.T4IS = 3;
92 IEC0bits.T4IE = 1;
93 T4CONbits.T32 = 1;
94 IFS0bits.T4IF = 0;
95 }
96
97
98 void TMR5_init(void)
99 {
100 T5CONbits.ON = 0;
101 IPC6bits.T5IP = 5;
102 IPC6bits.T5IS = 2;
103 IEC0bits.T5IE = 1;
104 IFS0bits.T5IF = 0;
105 }
106
107
108 void TMR6_init(void)
109 {
110 T6CONbits.ON = 0;
111 T6CONbits.TCKPS = 7;
112 IPC7bits.T6IP = 5;
113 IPC7bits.T6IS = 1;
114 IEC0bits.T6IE = 1;
115 IFS0bits.T6IF = 0;
116 }
117
118
119 void __attribute__((vector(_TIMER_1_VECTOR), interrupt(ipl6srs), nomips16)) TMR1_handler()
120 {
121
122 PR1 = TMR1_FREQ_SET;
123
124
125 PORTGbits.RG6 = !PORTGbits.RG6;
126
127
128 ADCCON3bits.GSWTRG = 1;
129
130
131 while (ADCDSTAT1bits.ARDY0 == 0);
132 ADC0_result = ADCDATA0;
133
134 while (ADCDSTAT1bits.ARDY6 == 0);
135 ADC6_result = ADCDATA6;
136
137
138 IFS0bits.T1IF = 0;
139 }
140
141
142 void __attribute__((vector(_TIMER_2_VECTOR), interrupt(ipl6srs), nomips16)) TMR2_handler()
143 {
144
145 IFS0bits.T2IF = 0;
146 }
147
148
149 void __attribute__((vector(_TIMER_3_VECTOR), interrupt(ipl6srs), nomips16)) TMR3_handler()
150 {
151 SetPeripheralAddress(0);
152 T3CONbits.ON = 0;
153
154
155 PORTFbits.RF8 = 1;
156
157
158 IO_Locked = false;
159
160
161 IFS0bits.T3IF = 0;
162 }
163
164
165 void __attribute__((vector(_TIMER_4_VECTOR), interrupt(ipl5srs), nomips16)) TMR4_handler()
166 {
167
168
169 IFS0bits.T4IF = 0;
170 }
171
172
173 void __attribute__((vector(_TIMER_5_VECTOR), interrupt(ipl5srs), nomips16)) TMR5_handler()
174 {
175
176
177 IFS0bits.T5IF = 0;
178 }
179
180
181 void __attribute__((vector(_TIMER_6_VECTOR), interrupt(ipl5srs), nomips16)) TMR6_handler()
182 {
183
184
185 PORTFbits.RF3 = 0;
186
187
188 T6CONbits.ON = 0;
189
190
191 IFS0bits.T6IF = 0;
192 }
193
194