-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
164 lines (147 loc) · 3.12 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
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
#ifdef _DEBUG
#include <__cross_studio_io.h>
#endif
#include <msp430x16x.h>
#include "adafruit_GPS.h"
#include "ports.h"
#include "uart.h"
#include "ecran.h"
#include "pad.h"
#include "led.h"
#include "tools.h"
#include <math.h>
typedef enum Mode {
MAINMENU, BOUSSOLE
} Mode;
Mode mode = MAINMENU;
void main(void)
{
unsigned int i;
int j;
float degres;
/* Le watchdog doit ?re d?activ?pour ne pas provoquer de red?arrage */
WDTCTL = WDTPW + WDTHOLD; // Stop WDT (watch dog timer)
BCSCTL1 &= ~XT2OFF; // XT2on
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
IFG2 &= ~OFIFG; // Clear OSCFault flag
P2IFG = 0;
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG) != 0); // OSCFault flag still set?
BCSCTL2 |= SELM1+SELS+DIVM1; // MCLK = SMCLK = XT2 (safe)
initPorts();
initUart0();
initUart1();
// Reset de l'�cran
P4OUT = 0x04; // Reset �ran
for (i = 0x0F; i > 0; i--);
P4OUT = 0x06; // Remise �ran
P1OUT = 0x00; // Eteint les leds (chiant qd allumé)
gps_init();
setCmdSwitch(GPS);
//setCmdSwitch(USB);
setGPS(1);
gps_send_command(PMTK_SET_BAUD_9600);
gps_send_command(PMTK_SET_NMEA_UPDATE_1HZ);
gps_send_command(PMTK_SET_NMEA_OUTPUT_OFF);
gps_send_command(PMTK_SET_NMEA_OUTPUT_RMCGGA);
standby();
degres = cos(180);
debug_printf("%f\n", degres);
led_centre(1);
_EINT(); // Interrupt ON
//reverse screen
delay(500);
sendCommandScreen("FF680001");
// stop scroll
sendCommandScreen("000C0000");
MainMenu();
for (;;)
{
if (nmea_received)
{
_DINT();
#ifdef _DEBUG
gps_debug_trame();
#endif
if (gps_parse())
{
#ifdef _DEBUG
gps_debug_parse();
#endif
switch (mode) {
case MAINMENU:
break;
case BOUSSOLE:
break;
}
}
_EINT();
}
}
}
void usart0_rx (void) __interrupt[UART0RX_VECTOR]
{
//POUR QUE LECRAN MARCHE EN USB
//-----------------------------
//while ((IFG2 & UTXIFG1) == 0);
//TXBUF1 = RXBUF0;
gps_read();
}
void usart1_rx (void) __interrupt[UART1RX_VECTOR]
{
//POUR QUE LECRAN MARCHE EN USB
//-----------------------------
//while ((IFG1 & UTXIFG0) == 0);
//TXBUF0 = RXBUF1;
screen_ack();
}
void bouton_push (void) __interrupt[PORT2_VECTOR]
{
P2IE &= ~(0x1F);
if(P2IFG & 0x01) // Push
{
if((P2IES & 0x01))
{ //P1OUT = 0x01; // Pressé
standby();
MainMenu();
mode = MAINMENU;
}
else; // Relaché
}
if(P2IFG & 0x02) // Top
{
if((P2IES & 0x02))
{//P1OUT = 0x02;
enregistrementMenu();
}
else;
}
if(P2IFG & 0x04) // Bottom
{
if((P2IES & 0x04)) P1OUT = 0x04;
else;
}
if(P2IFG & 0x08) // Left
{
if((P2IES & 0x08))
{
navigationMenu();
}
else;
}
if(P2IFG & 0x10){ // Right
if((P2IES & 0x10))
{
wakeup();
BoussoleMenu();
mode = BOUSSOLE;
}
else;
}
P2IES ^= P2IFG; // inversion des transition
P2IFG = 0;
P2IE |= 0x1F;
}