Hi,
I'd like to write a code that does toggling on the LED1 (P1.0) to LED2 (P1.6) when the S2 (P1.3) is pressed.
My code is the following;
----------
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x41; // LED1 and LED2 are output
P1OUT |= BIT0; // LED1 is on - initial
P1OUT |= BIT3; // Code for switch (S2)to be used
P1REN |= BIT3; // Code for switch (S2) to be used
P1OUT &= ~BIT6; // LED2 is off - initial
while(1)
{
if (!(BIT3 & P1IN)) //when S2 is pressed
{
P1OUT ^= 0x41; //do xor to LED1 and LED2
}
}
--------------
When I use this, MSP40 does sometimes turns on LED1 and turns off LED2, but sometimes LED2 stays stills and LED1 toggles.
What am I doing wrong?
I have checked a lot about this in forums and web but couldn't find a solution.
Thanks.
Basar