-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_adc_usage.c
48 lines (38 loc) · 947 Bytes
/
main_adc_usage.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
#include <msp430.h>
#include "adc.h"
#include "lib/clock_system.h"
int main()
{
/* Desliga Watchdog */
WDTCTL = WDTPW + WDTHOLD;
PM5CTL0 &= ~LOCKLPM5;
P1DIR |= BIT0;
P6DIR |= BIT6;
init_clock_system();
battery_voltage_t battery;
adc_init(&battery);
for (;;)
{
if (battery.cell_0 >= CELL_MAX_VOLTAGE
| battery.cell_1 >= CELL_MAX_VOLTAGE)
{
/* Sobre tensão em uma das células */
P1OUT |= BIT0;
P6OUT &= ~BIT6;
}
else if (battery.cell_0 < CELL_MIN_VOLTAGE
| battery.cell_1 < CELL_MIN_VOLTAGE)
{
/* Sub tensão em uma das células */
P1OUT |= BIT0;
P6OUT &= ~BIT6;
}
else
{
/* Tensão dentro dos limites de operação */
P6OUT |= BIT6;
P1OUT &= ~BIT0;
}
__bis_SR_register(GIE);
}
}