-
Notifications
You must be signed in to change notification settings - Fork 2
/
ports.c
475 lines (454 loc) · 13.2 KB
/
ports.c
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
/*******************************************************************************
* File: ports.c
* Author: Will Flores waflores@ncsu.edu
* Usage: Implementation of 'ports.h'.
* Description: This file contains the function implentations for the port
* initializations for this board.
* Environment: Windows 7, x64 build
* Built in HEW with MC16 Series Compiler V.5.44 Release 00
* Notes: NONE
* Revisions: 0.0, Initial Release
* 1.0, Better documented file header with function headers
* 2.0, Better documented Port 7 & 8 functions
* Created on March 12, 2012
*******************************************************************************/
//---------------------------------------------------
// Purpose: Initialize Port 8
// System registers associated with Port 8 configured
// * Pin 0 - I/O General Purpose I/O
// Pin 0 - TA4OUT Timer A4 Out
// Pin 0 - U Three-Phase Positive Waveform Output Pin
// * Pin 1 - I/O General Purpose I/O
// Pin 1 - TA4IN Timer A4 In
// Pin 1 - U Three-Phase Negative Waveform Output Pin
// * Pin 2 - I/O General Purpose I/O
// Pin 2 - INT0 Interrupt 0 Input
// * Pin 3 - I/O General Purpose I/O
// Pin 3 - INT1 Interrupt 1 Input
// * Pin 4 - I/O General Purpose I/O
// Pin 4 - INT2 Interrupt 2 Input
// Pin 5 - I/O General Purpose I/O
// * Pin 5 - NMI Non-Maskable Interrupt Input
// Pin 6 - I/O General Purpose I/O
// * Pin 6 � XCIN ==> Connected to X2 back side
// Pin 7 - I/O General Purpose I/O
// * Pin 7 - XCOUT ==> Connected to X2 back side
// * as configured below
// Passed: No variables passed
// Locals: No local values used
// Returned: No values returned.
// Author: Jim Carlson
// Rev: 1.0 Initial Release
// Built using: HEW Version 4.07.00.007
//
#include "sfr62p.h"
#include "ports.h"
#include "QSKDefines.h"
#include "proto.h"
#include "extern.h"
/* Button Pressing Flag */
volatile unsigned short buttonPressed;
/*******************************************************************************
* Purpose: This function calls all the port initialization functions for this
* board.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
void init_ports(void) {
init_port0();
init_port1();
init_port2();
init_port3();
init_port4();
init_port5();
//init_port6();
init_port7();
init_port8();
//init_port9();
//init_port10();
return;
}
/*******************************************************************************
* Purpose: Initialize Port _
* System registers associated with Port _ configured
* Pin 0
* Pin 1
* Pin 2
* Pin 3
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
void init_port0(void){
pd0 = OUTPUT_PORT;
p0_0 = PIN_LOW;
p0_1 = PIN_LOW;
p0_2 = PIN_LOW;
p0_3 = PIN_LOW;
p0_4 = PIN_LOW;
p0_5 = PIN_LOW;
p0_6 = PIN_LOW;
p0_7 = PIN_LOW;
return;
}
/*******************************************************************************
* Purpose: Initialize Port _
* System registers associated with Port _ configured
* Pin 0
* Pin 1
* Pin 2
* Pin 3
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
// init_port1: initializes port 1 to be an output port with all pins low
void init_port1(void){
pd1 = OUTPUT_PORT;
p1_0 = PIN_LOW;
p1_1 = PIN_LOW;
p1_2 = PIN_LOW;
p1_3 = PIN_LOW;
p1_4 = PIN_LOW;
p1_5 = PIN_LOW;
p1_6 = PIN_LOW;
p1_7 = PIN_LOW;
return;
}
/*******************************************************************************
* Purpose: Initialize Port _
* System registers associated with Port _ configured
* Pin 0
* Pin 1
* Pin 2
* Pin 3
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
// init_port2: initializes port 2 to be an output port with all pins low
void init_port2(void){
pd2 = OUTPUT_PORT;
p2_0 = PIN_LOW;
p2_1 = PIN_LOW;
p2_2 = PIN_LOW;
p2_3 = PIN_LOW;
p2_4 = PIN_LOW;
p2_5 = PIN_LOW;
p2_6 = PIN_LOW;
p2_7 = PIN_LOW;
return;
}
/*******************************************************************************
* Purpose: Initialize Port _
* System registers associated with Port _ configured
* Pin 0
* Pin 1
* Pin 2
* Pin 3
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
// init_port3: initializes port 3 to be an output port with all pins low
// This port is where our motors reside
void init_port3(void) {
/* Set up the direction of port 3, pins 0 and 2 */
pd3 = OUTPUT_PORT;
p3_0 = PIN_LOW; // left motor
p3_1 = PIN_LOW;
p3_2 = PIN_LOW; // right motor
p3_3 = PIN_LOW;
p3_4 = PIN_LOW; // GPS_PWRCNTRL
p3_5 = PIN_HIGH; // GPS_Reset
p3_6 = PIN_HIGH; // GPS_PWR
p3_7 = PIN_LOW; // IR emitter
return;
}
/*******************************************************************************
* Purpose: Initialize Port _
* System registers associated with Port _ configured
* Pin 0
* Pin 1
* Pin 2
* Pin 3
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
// init_port4: initializes port 4 to be an output port with all pins low
void init_port4(void){
pd4 = OUTPUT_PORT;
p4_0 = PIN_LOW;
p4_1 = PIN_LOW;
p4_2 = PIN_LOW;
p4_3 = PIN_LOW;
p4_4 = PIN_LOW;
p4_5 = PIN_LOW;
p4_6 = PIN_LOW;
p4_7 = PIN_LOW;
return;
}
/*******************************************************************************
* Purpose: Initialize Port _
* System registers associated with Port _ configured
* Pin 0
* Pin 1
* Pin 2
* Pin 3
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
// init_port5: initializes port 5 to be an output port with all pins low
void init_port5(void){
pd5 = OUTPUT_PORT;
p5_0 = PIN_LOW;
p5_1 = PIN_LOW;
p5_2 = PIN_LOW;
p5_3 = PIN_LOW;
p5_4 = PIN_LOW;
p5_5 = PIN_LOW;
p5_6 = PIN_LOW;
p5_7 = PIN_LOW;
return;
}
/*******************************************************************************
* Purpose: Initialize Port _
* System registers associated with Port _ configured
* Pin 0
* Pin 1
* Pin 2
* Pin 3
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
// init_port6: initializes port 6 (serial port) with all pins low
void init_port6(void){
pd6_0 = OUTPUT; // send - receive ctrl bits
pd6_1 = OUTPUT; // transfer clock I/O
pd6_2 = INPUT; // serial data input
pd6_3 = OUTPUT; // serial output
pd6_4 = OUTPUT;
pd6_5 = OUTPUT;
pd6_6 = INPUT;
pd6_7 = OUTPUT;
p6_0 = PIN_LOW;
p6_1 = PIN_LOW;
p6_2 = PIN_LOW;
p6_3 = PIN_LOW;
p6_4 = PIN_LOW;
p6_5 = PIN_LOW;
p6_6 = PIN_LOW;
p6_7 = PIN_LOW;
return;
}
/*******************************************************************************
* Purpose: Initialize Port 7
* System registers associated with Port 7 configured
* Pin 0
* Pin 1
* Pin 2 - I/O General Purpose I/O
* Pin 2 - CLK_VP
* Pin 2 - LED2 The Right Most LED
* Pin 3
* Pin 4 - I/O General Purpose I/O
* Pin 4 - TA2OUT Timer A2 Out
* Pin 4 - LED1 The Middle LED
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
void init_port7(void){
//pd7 = OUTPUT_PORT;
pd7_0 = OUTPUT; // UART2 TX
pd7_1 = INPUT; // UART2 RX
LED2_DDR = OUTPUT; // LED2 - right LED
pd7_3 = OUTPUT;
LED1_DDR = OUTPUT; // LED1 - middle LED
pd7_5 = OUTPUT;
pd7_6 = OUTPUT;
pd7_7 = OUTPUT;
p7_0 = PIN_LOW;
p7_1 = PIN_LOW;
LED2 = LED_OFF; // LED2 Off
p7_3 = PIN_LOW;
LED1 = LED_OFF; // LED1 Off
p7_5 = PIN_LOW;
p7_6 = PIN_LOW;
p7_7 = PIN_LOW;
return;
}
/*******************************************************************************
* Purpose: Initialize Port 8
* System registers associated with Port 8 configured
* *Pin 0 - I/O General Purpose I/O
* Pin 0 - TA4OUT_UP
* Pin 0 - LED0 The Left Most LED
* *Pin 1 - I/O General Purpose I/O
* Pin 1 - TA4IN_UN
* Pin 1 - S2 Middle Switch
* *Pin 2 - I/O General Purpose I/O
* Pin 2 - INT0 Interrupt 0 Switch
* Pin 2 - S3 Right-most Switch
* *Pin 3 - I/O General Purpose I/O
* Pin 3 - INT1 Interrupt 1 Input
* Pin 3 - S1 Left-most Switch
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
void init_port8(void){
//pd8 = OUTPUT_PORT;
LED0_DDR = OUTPUT; // LED0 - left LED
SW2_DDR = INPUT; // switch 2
SW3_DDR = INPUT; // switch 3
SW1_DDR = INPUT; // switch 1
pd8_4 = OUTPUT;
pd8_6 = OUTPUT;
pd8_7 = OUTPUT;
LED0 = LED_OFF; // LED0 Off
SW2 = BUTTON_RESET; // Switch 2 unpressed
SW3 = BUTTON_RESET; // Switch 3 unpressed
SW1 = BUTTON_RESET; // Switch 1 unpressed
p8_4 = PIN_LOW;
p8_5 = PIN_LOW;
p8_6 = PIN_LOW;
p8_7 = PIN_LOW;
/* Initialize Button Pressed Flag */
buttonPressed = DEFAULTS;
return;
}
/*******************************************************************************
* Purpose: Initialize Port _
* System registers associated with Port _ configured
* Pin 0
* Pin 1
* Pin 2
* Pin 3
* Pin 4
* Pin 5
* Pin 6
* Pin 7
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
// init_port9: initializes port 9 to an output port and sets all pins LOW
void init_port9(void){
//pd9 = OUTPUT_PORT;
pd9_0 = OUTPUT;
pd9_1 = OUTPUT;
pd9_2 = OUTPUT;
pd9_3 = OUTPUT;
pd9_4 = OUTPUT;
pd9_5 = OUTPUT; // ADC
pd9_6 = OUTPUT; // ADC
pd9_7 = OUTPUT; // GPS PWRCHK
p9_0 = PIN_LOW;
p9_1 = PIN_LOW;
p9_2 = PIN_LOW;
p9_3 = PIN_LOW;
p9_4 = PIN_LOW;
p9_5 = PIN_LOW;
p9_6 = PIN_LOW;
p9_7 = PIN_LOW;
return;
}
/*******************************************************************************
* Purpose: Initialize Port 10
* System registers associated with Port _ configured
* Pin 0 - Potentiometer
* Pin 1 - Thermistor
* Pin 2 - Unused
* Pin 3 - Unused
* Pin 4 - Unused
* Pin 5 - Unused
* Pin 6 - Unused
* Pin 7 - Unused
*
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores waflores@ncsu.edu
*******************************************************************************/
// init_port10: initializes port 10 to an output port and sets all pins LOW
void init_port10(void){
pd10 = INPUT; // Shorthand for only enabling the thumbwheel to work
//pd10_0 = OUTPUT_PORT;
/*pd9_1 = OUTPUT;
pd9_2 = OUTPUT;
pd9_3 = OUTPUT;
pd9_4 = OUTPUT;
pd9_5 = OUTPUT; // ADC
pd9_6 = OUTPUT; // ADC
pd9_7 = OUTPUT;
*/
p10_0 = PIN_LOW;
p10_1 = PIN_LOW;
p10_2 = PIN_LOW;
p10_3 = PIN_LOW;
p10_4 = PIN_LOW;
p10_5 = PIN_LOW;
p10_6 = PIN_LOW;
p10_7 = PIN_LOW;
return;
}