Jump to content
ak96

Trying to alternate blinking of two LEDs

Recommended Posts

Sometimes when I run this code, the LEDs will blink alternatingly, while other times they will blink synchronously. Why is that?  

  

#include <msp430.h>
 
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
P1DIR |= 0x40;
 
for(;; ) {
volatile unsigned int i; // volatile to prevent optimization
 
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
 
for(i=0;i<10000;i++){} // SW Delay
P1OUT ^= 0x40;
}
 
return 0;
}

Share this post


Link to post
Share on other sites

@@cubeberg

 

Yep, that's right. After I set all pins to 0 it started working. The bits are assigned random states every time I run it, and whenever the two LEDs start with the same state it works fine, but when they start with different states they blink synchronously. 

 

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×