Programming MSP430 on board button

To get user input or to make a switch working in MSP430 Launchpad first we will try programming the on board button P1.3 to read user inputs

Connect P1.3 pin to Vcc through a resistor…Thecode to get user input is below

on board button S2 is used in this example...
connect P1.3 to vcc through a resistor...
#include <msp430g2553.h>

volatile unsigned int i;//to prevent optimization
void main(void)
P1DIR|=0X01;//set all bits in P1 to input except BIT0
P1OUT=0x01;//BIT 0 LED ON
while((P1IN & BIT3)==0)//while pusing S1

The above code sets the red led on whenever we pushes the button the led is turned off….The code is self explanatory with comments…

This is an example of polling…

Happy Hacking 🙂


One thought on “Programming MSP430 on board button

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s