I just got a MSP-EXP430G2 Launchpad from TI. I've been fooling around on it, making the LEDs blink and everything. I'm working on a simple bit of code that blinks the red LED on PIN0, turns it off and then turns on the green LED on PIN6. However, I want it so that when I press the button attached to PIN3 the flashing will stop. I am attempting to accomplish this with the following setup code:
// Define the GPIO Pins, 0b01001001
P1DIR = 0x01;
P1DIR |= 0x40;
P1DIR |= 0x08;
// Write PIN0 to HIGH, 0b00000001
P1OUT = 0x01;
// Define PIN3 as an input, 0b00001000
P1IN = 0x08;
However, when I execute this code on the MSP430 I see that the the actual values written to the P1DIR, P1OUT, and P1IN registries are:
P1IN = 0b00000111
P1OUT = 0b00000001
P1DIR = 0b01001001
The P1DIR and P1OUT registries are as I expected and desired. However the P1IN isn't. PIN0 is written to a 1 when it should be 0, and PIN3 is 0 when it should be a 1. I suspect that PIN1 and PIN2 are set to 1 because they are the UART pins.
Am I using incorrect code? I am pretty new to microcontrollers in general but I think I set it up correctly. I would appreciate any help I can get.