MSP430 Polling Vs Interrupt

In this example other than the usual polling method we uses an interrupt to get the switch reading…
In MSP430 port1 interrupt service routine is written like this

#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{

}

I used code composer studio to get the output of interrupt code…The mspgcc interrupt service routine is like this but i failed to get the output using mspgcc

//port1 interrupt service routine
void Port_1 (void) __attribute__((interrupt(PORT1_VECTOR)));
void Port_1 (void)
{

}

This example also reads switch and toggles light…This is the full code of the interrupt program..

/*interrupt.c
ganeshredcobra@gmail.com
GPL
*/
#include <msp430g2553.h>
#define LED1 BIT0
#define LED2 BIT6
#define BUTTON BIT3
volatile unsigned int i;//to prevent optimization
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR |= (LED1+LED2);//
P1OUT &= ~(LED1+LED2);
P1IE |= BUTTON;
P1IFG &= ~BUTTON;

//__enable_interrupt();//enable all interrupts
_BIS_SR(LPM4_bits+GIE);
for(;;)
{}
}

//port1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= (LED1+LED2);
P1IFG &= ~BUTTON;
P1IES ^= BUTTON;
}

MSP430 GPIO Programming Reading an external switch

To read an external switch using MSP430 an external switch is connected to P1.4…We uses polling method here to read the switch

/*button_press.c
ganeshredcobra@gmail.com
GPL
An external button connected to P1.4 is used in this example...
connect P1.4 to vcc through a resistor...
*/
#include 

volatile unsigned int i;//to prevent optimization
void main(void)
{
	WDTCTL=WDTPW+WDTHOLD;
 	P1DIR|=0X01;//set all bits in P1 to input except BIT0
	for(;;)
	{
	  if((P1IN & BIT4)==0)//while pushing S1
		P1OUT=0X00;//LED ON
	  else
		P1OUT=0x01;//LED OFF		 
	}
}

When we pushes the button LED will be ON and when we releases it will be OFF…
Happy Hacking 🙂