-2

I am executing the code below on a TI MSP430 microcontroller. Basically what I expect it to do is to toggle both LEDS regularly (Pin 1.0 and Pin 4.7). Unfortunately only the LED on Pin 1.0 is toggled, the other one is on all the time. Can someone tell me why that is the case?

int main(void) {
WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer

// Set P1.0 and P4.7 as output pins
P1DIR |= BIT0;
P4DIR |= BIT7;

for(;;)
{
    P4OUT |= BIT7;
    __delay_cycles(2500000); // 1sec at 25MHz

    P1OUT ^= BIT0;
    P4OUT &= 0x0;

}


return 0;}
Daiz
  • 357
  • 1
  • 3
  • 20

1 Answers1

3

Because your sequence for Pin 4.7 is basically saying:

1) Turn the led on
2) Wait
3) Turn the led off

Since it is done in a loop we can rearrange it:

3) Turn the led off
1) Turn the led on
2) Wait

So there is no delay between (3) and (1). So the time the led is off is negligible.

Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61