-
Notifications
You must be signed in to change notification settings - Fork 2
/
proj2main.c
112 lines (99 loc) · 3.19 KB
/
proj2main.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
/*******************************************************************************
* File: main.c
* Author: Will Flores [email protected]
* Usage: Implements Project 2b.
* Description: This file contains the main function which allows the user
* to press buttons on the QSK board and have the LCD display
* words as per button presses.
* 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 main function
* 2.0, Project 2a + Homework 5 improvements
* 2.5, Project 2b
*
* Created on March 26, 2012
*******************************************************************************/
#include "QSKDefines.h"
#include "proto.h"
#include "extern.h"
#include "ports.h"
#include "shapes.h"
#include "movement.h"
#include "IR.h"
#define DISPLAY_DELAY (1000)
/*******************************************************************************
* Purpose: This function allows the user to press a button which lets the car
* travel in the desired directions.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void main(void) {
/* counter var */
int count = 0;
/* Watchdog timer would go here */
/* Initialize the ports */
init_ports();
/* Initialize the interrupts */
init_interrupts();
/* Initialize the System clock */
system_clock_init();
/* Initialize the display */
InitDisplay("Project2");
/* Initialize the System timers */
TimerInit();
/* Initialize Serial ports */
InitUART();
/* Initialize AD converter */
ADInit();
while(FOREVER) {
if (buttonPressed) {
if((buttonPressed & SW1_PRESSED)) {
/* Clear the bit */
buttonPressed &= ~(SW1_PRESSED);
/* Clear the screen */
BNSPrintf(LCD, "\t ");
/* Move around */
BNSPrintf(LCD, "\tMoving.\nAround..");
moveBackandForth();
}
else if ((buttonPressed & SW2_PRESSED)) {
/* Clear the bit */
buttonPressed &= ~(SW2_PRESSED);
BNSPrintf(LCD, "\tMotor toggle: %d", count);
/* toggle motors */
switch (count) {
case 0:
left_motor_forward();
break;
case 1:
left_motor_reverse();
break;
case 2:
right_motor_forward();
break;
case 3:
right_motor_reverse();
break;
default:
count = 0;
}
++count;
}
else if ((buttonPressed & SW3_PRESSED)){
/* Clear the bit */
buttonPressed &= ~(SW3_PRESSED);
/* Calibrate the sensors */
calibrateIR();
}
}
else {
/* Display the calibrated value */
BNSPrintf(LCD, "\tIR val: \n%03x ", IR_threshold);
DisplayDelay(DISPLAY_DELAY);
}
}
}