/
lab3.c
71 lines (55 loc) · 1.98 KB
/
lab3.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
#include <pololu/orangutan.h>
#include <inttypes.h> //gives us uintX_t
#include "motor.h"
#include "controller.h"
#include "serial_interface.h"
// Globals
volatile uint8_t G_reset_source = 0;
volatile uint8_t G_logging_flag = 0;
/******************************************************************************/
/* Print Reset Source */
/* */
/* This dumps strings over the serial port to indicate why we recently */
/* reset. */
/******************************************************************************/
void print_reset_reason() {
if (G_reset_source & (1<<JTRF)) { print_usb("JTAG Reset\r\n", 12); }
if (G_reset_source & (1<<WDRF)) { print_usb("Watchdog Reset\r\n", 16); }
if (G_reset_source & (1<<BORF)) { print_usb("Brownout Reset\r\n", 16); }
if (G_reset_source & (1<<EXTRF)) { print_usb("External Reset\r\n", 16); }
if (G_reset_source & (1<<PORF)) { print_usb("Power-on Reset\r\n", 16); }
}
int main() {
// capture any reset reason
G_reset_source = MCUSR;
// clear the status register by writing ones
// (odd, I know, but that is how it is done)
MCUSR = 0x1F;
// Display on the LCD that serial connection is needed
print("Waiting for");
lcd_goto_xy(0, 1);
print(" serial conn...");
// This init will block if no serial connection present
// so user sees message on LCD to make a connection
init_interface();
// Display the user interface over the serial usb
// connection
serial_check();
print_reset_reason();
print_usb("Welcome to lab 3!\r\n", 19);
print_usage();
print_prompt();
// clear "Waiting for connection" message from the LCD
clear();
// turn on interrupts
sei();
init_motor();
init_encoder();
// set controller for 1000 Hz
init_controller_w_rate(50);
while (1) {
serial_check();
check_for_new_bytes_received();
}
return 0;
}