Hi, I am just getting started with the MSP430, turning leds on and off and such, and I seem to have a few problems with bitwise operators.
I dont understand why do I have to write:
P1OUT |= BIT0;
to turn LED 0 on when I initialize the program, but I cant write:
P1OUT = BIT0;
Shouldn't it be the same?
Also I get a lot of problems when transferring the program from CCS to the MSP430 and I wanted to know if this is normal. It seems like a lot of the times I transfer the program to the Launchpad it doesnt work, and I have to try to transfer it several times (without changing anything in the source code) until it "catches" and the program works. Sometimes turning the launchpad on and off seems to make the program that I just transferred, but wasnt working, to start working. I dont know if this is normal or I have a defective unit.
By the way this is the code I am using, it alternates the leds on and off by pressing the button.
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0+BIT6; // Set P1.0 and P1.6 to output direction
//--------------------------------------------------------------------------------------------------------------
P1OUT = 0x00; // IF I DELETE THIS LINE THE PROGRAM WORKS, IF I LEAVE IT IT DOESNT
//--------------------------------------------------------------------------------------------------------------
P1IE |= BIT3; // P1.3 interrupt enabled
P1IES |= BIT3; // P1.3 Hi/lo edge
P1REN |= BIT3; // Enable Pull Up on SW2 (P1.3)
P1IFG &= ~BIT3; // P1.3 IFG cleared
//BIT3 on Port 1 can be used as Switch2
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
long int i = 0;
P1IE = 0x0; // P1.3 interrupt disabled
P1OUT ^= BIT0+BIT6; // P1.0 + P1.6 = toggle
for(i=0; i< 30000; i++); // Wait for about half a second
P1IFG &= ~BIT3; // P1.3 IFG cleared
P1IE |= BIT3; // P1.3 interrupt enabled
}
Thanks in advance.