1 min read

Blinking lights MSP430 FG461x

MSP430

I have been working on MSP430 for sometime now. It is an TI ([Texas Instruments](http://maps.google.com/maps?ll=32.909256,-96.751054&spn=0.01,0.01&q=32.909256,-96.751054 (Texas%20Instruments)&t=h "Texas Instruments") ) chip. Very fun to play with. We are using a MSP430FG461x series experimental board. This little experimental board has all the bells and whistles one may need to create any application from a home automation controller to a simple step-motor driver. TI provides very good documentation for this grown up toy.

Our first lab homework for this baby was :

By using the MSP430 FG4618 Microcontroller, write a program that controls the LED #1, #2,#4.When we perpetually push the two buttons at the right bottom corner of the board, all of the LEDs turn on.When we push perpetually one of the buttons, only the LED #4 blinks, the others turn off.When we push no buttons, the LED #1 and #2 blinks complementarily and the LED#4 turns off.

My biggest problem with this exercise was to find what led was connected to what port. However, in the end I figured it all out.

Below you will find the program :

#include <msp430xG46x.h>

void initPortPins(void);

void main(void)
{ 
	 WDTCTL=WDTPW + WDTHOLD;
	 initPortPins(); 
	 while(1) {				  
	 	if (P1IN == (0x00))
	 	{
			P2OUT |= 0x06;
			P5OUT |= 0x02;
		}
		else if (P1IN == 0x03)
		{
			P2OUT &amp;= 0x00;
			P5OUT &amp;= 0x00;
			P2OUT |= 0x02;               					   
			__delay_cycles (40000);
			P2OUT &amp;= 0x00;
			P2OUT |= 0x04;
			__delay_cycles (40000);
		}                                                                  
		else 
		{
			P2OUT &amp;= 0x00;
			P5OUT &amp;= 0x00;
			__delay_cycles (40000);
			P5OUT |= 0x02;
			__delay_cycles (40000);
		}
	 }
};

void initPortPins(void)
{
  P1DIR = 0x00;	// Set P2.2,1 as outputs
  P5DIR = 0x02; // Set P5.1 as output
  P2DIR = 0x06; // Set P2.1 to 1
};