-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
115 lines (100 loc) · 2.47 KB
/
main.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
#include <msp430.h>
#include <stdint.h>
#include "oled.h"
#include "dma.h"
#include "timers.h"
#include "game.h"
#include "uart.h"
#define TRUE 1
#define FALSE 0
void check_oled_actions();
enum {
LEFT = '1',
DOWN_BRIGHTNESS,
START,
INVERT,
UP_BRIGHTNESS,
RIGHT
} actions;
uint8_t action;
int action_received = FALSE;
int update_screen = FALSE;
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
config_uart();
config_oled();
config_timers();
__enable_interrupt();
while (1) {
switch (state) {
case INITIAL:
show_start_game_screen();
if (action_received) {
if (action == START) {
action_received = FALSE;
start_game();
state = PLAYING;
}
else check_oled_actions();
}
break;
case PLAYING:
if (update_screen) {
update_screen = FALSE;
move_cars_forward();
oled_update_screen();
}
if (action_received) {
if (action == LEFT) {
action_received = FALSE;
move_player_car_left();
}
else if (action == RIGHT) {
action_received = FALSE;
move_player_car_right();
}
else check_oled_actions();
}
break;
case LOST:
show_game_over_scene();
state = INITIAL;
break;
default:
break;
}
}
return 0;
}
void check_oled_actions() {
switch (action) {
case INVERT:
oled_invert();
break;
case UP_BRIGHTNESS:
oled_increase_brightness();
break;
case DOWN_BRIGHTNESS:
oled_reduce_brightness();
break;
default:
break;
}
action_received = FALSE;
}
#pragma vector = USCI_A0_VECTOR
__interrupt void UART0_INTERRUPT(void) {
switch (UCA0IV) {
case 2: // Recepção
if (UCA0RXBUF != 0x0D && UCA0RXBUF != 0x0A) {
action = UCA0RXBUF;
action_received = TRUE;
}
break;
default: break;
}
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void timer_A0_isr(void) {
update_screen = TRUE;
}