-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmovement.c
167 lines (154 loc) · 5.79 KB
/
movement.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
/*******************************************************************************
* File: movement.c
* Author: Will Flores [email protected]
* Usage:
* Description: This file contains the functions that move the car back and
* forth.
* 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, Implements full H-Bridge capabilities
* Created on March 12, 2012
*******************************************************************************/
#include "movement.h"
#include "shapes.h"
#include "ports.h"
#include "QSKDefines.h"
/*******************************************************************************
* Purpose: Turns the left motor pin forward on - along with the left LED,
* indefinitely.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void left_motor_forward(void) {
/* Check to see if Left Reverse Pin is active */
if (is_left_reverse_on()) {
left_motor_off();
}
/* Turn the Left Forward Pin on */
p3_2 = LEFT_MOTOR_ON;
LED0 = LED_ON; /* Left LED ON */
return;
}
/*******************************************************************************
* Purpose: Turns the left motor pin reverse on - along with the left LED,
* indefinitely.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void left_motor_reverse(void) {
/* Check to see if Left Forward Pin is active */
if(is_left_forward_on()) {
left_motor_off();
}
/* Turn the Left Reverse Pin on */
p3_3 = LEFT_MOTOR_ON;
LED0 = LED_ON; /* Left LED ON */
}
/*******************************************************************************
* Purpose: Turns the right motor pin forward on - along with the right LED,
* indefinitely.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void right_motor_forward(void) {
/* Check to see if the Right Reverse Pin is on */
if(is_right_reverse_on()) {
right_motor_off();
}
/* Turn the Right Forward Pin on */
p3_0 = RIGHT_MOTOR_ON;
LED2 = LED_ON; /* Right LED ON */
return;
}
/*******************************************************************************
* Purpose: Turns the right motor pin reverse on - along with the right LED,
* indefinitely.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void right_motor_reverse(void) {
/* Check to see if the Reverse Forward Pin is on*/
if(is_right_forward_on()) {
right_motor_off();
}
/* Turn the Right Reverse Pin on */
p3_1 = RIGHT_MOTOR_ON;
LED2 = LED_ON; /* Right LED ON */
return;
}
/*******************************************************************************
* Purpose: Turns both motors off.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void motors_off(void) {
/* This is to kill the motor IO */
right_motor_off();
left_motor_off();
return;
}
/*******************************************************************************
* Purpose: Turns right motor and LED off.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void right_motor_off(void) {
p3_0 = RIGHT_MOTOR_OFF; /* R_FORWARD Pin */
p3_1 = RIGHT_MOTOR_OFF; /* R_REVERSE Pin */
LED2 = LED_OFF;
return;
}
/*******************************************************************************
* Purpose: Turns left motor and LED off.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void left_motor_off(void) {
p3_2 = LEFT_MOTOR_OFF; /* L_FORWARD Pin */
p3_3 = LEFT_MOTOR_OFF; /* L_REVERSE Pin */
LED0 = LED_OFF;
return;
}
/*******************************************************************************
* Purpose: Turns both motors forward and LEDs on, indefinitely.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void move_forward(void) {
/* set the wheel counts and start the timer before proceeding */
left_motor_forward();
right_motor_forward();
return;
}
/*******************************************************************************
* Purpose: Turns both motors reverse and LEDs on, indefinitely.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void move_reverse(void) {
/* set the wheel counts and start the timer before proceeding */
left_motor_reverse();
right_motor_reverse();
return;
}