Other Parts Discussed in Thread: MSP430G2231
I'm trying to set up a simple code where the red and green LEDs on the launchpad are triggered to flash high for a given length of delay and low for a length of delay. For example, when Vcc is applied to input pin P1.5, the red LED would come on for some time, then shut down for some time, then the green led would turn on for some time, then shut off. In the following code, I have found that when the delay is less than a certain range it will seem to repeat the cycle several times. However, if the delay is longer than that range, it will act as it should only performing the cycle once. Changing the delay to 100000 will cause the undesired repeating of the if() action, and changing the delay to 200000 will allow it to act normal (albeit slower) only cycling once. What's going on? I only want it to cycle once, not twice or more as it does with lower delay values. Thanks for the help/clarification!
#include <msp430g2231.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
P1DIR |= 0x40; // Set P6.0 to output direction
for(;;)
{
if (0x20 & P1IN)
{
P1OUT |= 0x01;
__delay_cycles(200000);
P1OUT &= ~0x01;
__delay_cycles(200000);
P1OUT |= 0x40;
__delay_cycles(200000);
}
else
{
P1OUT &= ~0x01;
P1OUT &= ~0x40;
}
}
}