-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecond.c
43 lines (32 loc) · 889 Bytes
/
second.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
#include <msp430g2231.h>
#define SWITCH BIT3
#define SWITCH_PRESSED 0x00
#define RED BIT0
#define GREEN BIT6
int count = 0;
int main(void)
{
/* stop watchdog timer */
WDTCTL = WDTPW | WDTHOLD;
P1DIR |= RED + GREEN; // Define se o bit é entrada ou saída
P1REN = SWITCH; // Habilita resistor de pull-up
P1OUT |= GREEN; // Green LED lit at startup
P1OUT &= ~RED; // Red LED off at startup
P1IE = SWITCH; // Habilita a interrupção p/ P1.3
P1IES = SWITCH; // Definição da borda subida/descida
P1IFG = SWITCH_PRESSED;
__enable_interrupt(); // Habilita as interrupções
while (1)
{
}
}
#pragma vector = PORT1_VECTOR
__interrupt void Port_1(void)
{
count++;
if (count % 5 == 0)
{
P1OUT ^= GREEN | RED; // Troca o estado do led
}
P1IFG = SWITCH_PRESSED; // Zera a flag
}