home


 * Starting up with LaunchPad**

We assume that you have just purchased a launchpad from here and are about to start. So, we will start with very basics discussing about each and everything that you require to start developing your required project.

To start with, you need a launchpad as shown on the right.

Lets us start our discussion with simple input output basics and coding part for msp430.

It is a group of 8 pins which are used for exchanging data with the external world like motors or
 * PORT :**

computer itself.

>> MSP430 devices have upto 8 digital input output ports implemented P1 to P8.

>> Each input/output pin is individually configurable for input or output direction.That means we can decide what pin we want to use as an input pin and what pin do we want to use a s output pin.


 * REGISTERS :**

Data direction Register (PxDIR) : Here x stands for the PORT number.suppose for Port 1, we will write P1DIR.

Each bit in PxDIR selects the direction of the corresponding I/O pin. PxDIR is an 8 bit register. Each bit stands for each pin physically present in a port.The status of the bit can either be 0 or 1.

While, 0 stands for input pin and 1 stands for output pin.


 * //Example : P1DIR=Ob00001111;//**

The above statement will make the the first four pins of Port 1 as output pins and last four pins as input pins.

__**Note**__ //: The LSB is pin0 of the corresponding Port and MSB is the Pin 7 of that Port.//


 * //Example 2 : P2DIR=0xFF;//**

The above statement will declare all the pins of Port 2 as output pins as output pins.

Thus the status of the bins can be declared as either binary format or hexadecinmal format.

__**INPUT REGISTER(PxIN)**__ : It is used for reading data from port pins in input mode.
Each bit in PxIN register reflects the value of the input signal at the corresponding pin when the pin is configured as I/O function.


 * Bit=0 => input is low**


 * Bit =1=> input is high**

P1IN value will be an 8bit binary number each bit corresponding to each pin of the PORT.


 * //__Example 1__: Reading the status of the PORT 1//**

//**X=P1IN;**//

Above command will store the value of the P1IN register in x.


 * //__Example 2__: Reading the status of a particular pin of a Port//**


 * //X=P1IN&BIT3;//**

The above command will store the status of Pin 3 of Port 1 into x.


 * If Pin 3 is high, x=1 else x=0**


 * __NOTE__:** BIT3=0b00001000; BIT7=Ob10000000;

**__OUTPUT REGISTER (PxOUT)__ :**
It is used for writing the values to the port pins in Output mode in simple language. Each bit in each **PxOUT** register is the value to be output on the corresponding I/O pin when thepin is configure In Output mode using **PxDIR** register.


 * Bit=0=>**The output is low


 * Bit=1=>**The Output Is high

//**Example 1:**//**To make all the pins high on a Port**

//or we can write//
 * P4DIR=0b11111111;**
 * //P4DIR=0xFF;//**


 * //P4DIR=0xFF;//**

//The above example will make all the pins of Port 4 as high. This can be tested by connecting// //LEDs on the respective Port pins.//


 * Exapmle 2 : To output data on 0th bit on Port 2**


 * P2DIR |=0x01;**


 * P2OUT |= 0x01;**


 * //NOTE: THE OR OPERATION IN THE ABOVE EXAPMLE IS USED TO SHOW THAT IF WE WANT TO// //CHANGE THE//** **//STATUS OF A PARTICULAR PIN WITHOUT CHANGING THE STATUS OF OTHER PINS.//**

**__Pullup/Pulldown Resistor Enable Registers PxREN__ //://**
//Each bit in PxREN register enable sor disables the pullup or pulldown resistor of the// //corresponding pin.The corresponding bit in the PxOUT register selects if the pin is pulled// //up or pulled down.//


 * //Bit=0 Pullup/pulldown resistor disabled//**


 * //Bit=1 Pullup/pulldown resistor enabled//**

//If the pin's pullup/pulldown resistor is enabled, the corresponding bit in the PxOUT register//

//selects pullup or pulldown//


 * //Bit = 0: The pin is pulled down//**
 * //Bit = 1: The pin is pulled up//**

//A pull-up resistor weakly "pulls" the voltage of the wire it is connected to towards its voltage// //source level when the other components on the line are inactive.//
 * __NOTE__//://** PULL UP RESISTOR IS USED TO ENSURE THAT THE INPUT ALWAYS READS HIGH WHEN NOT DRIVEN BY ANY EXTERNAL ENTITY//.//

__**Steps TO USE A PIN in pullup/pulldown MODE**__ //://

//1.DEFINE THE CORRESPONDING PIN IN Input mode using PxDIR.//

//2.enable the PULLUP/PULLDOWN resistor using PxREN//

//3.Set the pin as pullup or pulldown using PxOUT//

__**FUNCTION SELECT REGISTERS(PxSEL)**__ //://

//Often, port pins are multiplesed with other peripheral module functions. Each pxSEL bit is used// //to select the pin function-I/O port or peripheral module function//

//PxSEL=0 ---I/O function is selected// //PxSEL=1 ---Primary peripheral module function is selected// For the time ,this will not be emphasized much as it will be covered in later sections.

__**SOME MORE EXERCISES AND ILLUSTRATIONS**__


 * //1.__Configure PORT 2 as output port__//**

//Ans.//

//P2DIR=oxFF;//
 * //2. __Configure PORT 1 as output port and set lower nibble as low and higher nibble as high.__//**

//Ans.//

//P2DIR=0xFF;// //P2OUT=0b11110000;// Or P2OUT=oxF0;
 * 3.__//Configure Port 3 as pullup input and read lower nibble in x//__**

Ans.

//P3DIR=0x00;//

//PxREN=0xFF;//

//PxOUT=0xFF;//