Let us review the LED flash program with a twist.
This program will alternate between the red LED1 and green LED2 on the MSP-EXP430G2 LaunchPad evaluation board.
I have used the #define preprocessor statement as described in the previous blog post to make the code more readable.
PREVIOUS NEXT
MSP430 Tutorial - Index
Code:
// Patrol Cruiser Flashing LEDs Example
// 2013.04.25 - MrChips
#include "io430.h"
#define ON 1
#define OFF 0
#define LED1 P1OUT_bit.P0
#define LED2 P1OUT_bit.P6
#define DELAY 10000
void init(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1OUT = 0x00;
P1DIR = 0xFF;
}
void delay(unsigned long d)
{
unsigned long i;
for (i = 0; i < d; i++);
}
void main( void )
{
init();
while (1)
{
LED1 = ON;
LED2 = OFF;
delay(DELAY);
LED1 = OFF;
LED2 = ON;
delay(DELAY);
}
}
I have used the #define preprocessor statement as described in the previous blog post to make the code more readable.
PREVIOUS NEXT
MSP430 Tutorial - Index