Electronic – Accessing individual I/O pin on MSP430

cgpiomsp430software

I'm porting some software from Microchip PIC (using the HI-Tech C Compiler) to TI MSP430, and in the existing code they access the pins directly with something like:

RA1 = 1;

Is there a similar way to do this with the MSP430, or do I have to write to the entire input/output register each time? If it is not possible has any one come up with a good equivalent? I am using Code Composer Studio v5.3 and the compiler that comes with that.

Best Answer

In the MSP430, accessing individual pins is commonly written using defines and bitwise operators:

P2OUT &= ~BIT1;    /* Pin P2.1 = 0 */
P2OUT |= BIT1;     /* Pin P2.1 = 1 */
P2OUT ^= BIT1;     /* Toggle Pin P2.1 */

Be sure to include the proper header file for your specific chip that contains the port and pin (BIT#) defines.