-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
106 lines (78 loc) · 1.91 KB
/
main.c
File metadata and controls
106 lines (78 loc) · 1.91 KB
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
/* Author = Ian Taylor & Zack Teasdale
* Date : 5.4.17
* SWEN 563 Project 4 main file.
*/
// Imports
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "SysClock.h"
#include "pwm.h"
#include "UART.h"
#include "LED.h"
#include "GPIO.h"
// Defines
#define BUFFER_SIZE (0x20)
// Globals
//uint8_t buffer [BUFFER_SIZE] ;
// Function Declarations
static void move_servo(int new_position);
static void pause_servo(void);
static void resume_servo(void);
static void test_board(void);
static uint8_t decode(void);
// Function Definitions
// Moves servo to new position.
static void move_servo(int new_position) { set_servo_position(new_position); }
// Pauses the servo. Stops the pwm signal generation.
static void pause_servo() { stop_pwm(); }
// Resumes the servo. Restarts the pwm signal generation.
static void resume_servo() { start_pwm(); }
// Tests the LED's to make sure we can manage the board.
static void test_board() {
wait(10);
Green_LED_Off();
Red_LED_Off();
wait(10);
Green_LED_Off();
Red_LED_On();
wait(10);
Green_LED_On();
Red_LED_Off();
wait(10);
Green_LED_Off();
Red_LED_Off();
wait(10);
Green_LED_On();
Red_LED_On();
wait(10);
Green_LED_Off();
Red_LED_Off();
wait(10);
}
// Main function
int main(void) {
uint8_t buffer [BUFFER_SIZE] ;
int n;
uint8_t input;
// Init for sys clock and UART.
System_Clock_Init() ;
UART2_Init() ;
LED_Init();
setup_gpio();
//n = sprintf(buffer, "We're working boys!\r\n") ;
//USART_Write(USART2, buffer, n) ;
// pwm and timer setup.
configure_pwm();
config_timer1();
//test_board();
reset_servo();
while(1) {
// read in input (1 bit per pin)
input = read_pins();
move_servo(input);
//n = sprintf(buffer, "%d\r\n", (int)((OFFSET + (SCALAR * input)) * PERIOD));
//USART_Write(USART2, buffer, n) ;
wait(0);
}
}