-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path02_Hello_LEDs.c
30 lines (25 loc) · 911 Bytes
/
02_Hello_LEDs.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
/*
This code toggles between the red and green LEDs connected to P1.0 and P1.6 respectively on the Launchpad
"Hello, LEDs!"
Make sure both the LEDs are connected to the port pins via the jumpers. (They are already connected by default)
*/
#include <msp430.h>
//Constants Definitions
//The value of DELAY will be proportional to the time the LED will be held on or off
#define DELAY 20000
int main(void)
{
volatile int i; //Force the compliler to not optimize the variable 'i'
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR|=BIT0|BIT6; //Set P1.0 and P1.6 as output pin
while(1) //Keep toggling the LEDs forever
{
P1OUT|=BIT0; //Turn on red LED
P1OUT&=~BIT6; //Turn off green LED
for(i=DELAY;i>0;i--); //Delay
P1OUT|=BIT6; //Turn on green LED
P1OUT&=~BIT0; //Turn off red LED
for(i=DELAY;i>0;i--); //Delay
}
return 0;
}