ak96 4 Posted April 30, 2016 Share Posted April 30, 2016 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; } Quote Link to post Share on other sites
cubeberg 540 Posted April 30, 2016 Share Posted April 30, 2016 My guess would be because you're not setting the initial state - you should set them explicitly instead of assuming state when your code executes. Try P1OUT = 0x00; when you set P1DIR. or instead of P1OUT ^= 0x01, use P1OUT = 0x01; gsutton, dubnet and tripwire 3 Quote Link to post Share on other sites
ak96 4 Posted April 30, 2016 Author Share Posted April 30, 2016 @@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! cubeberg and tripwire 2 Quote Link to post Share on other sites
cubeberg 540 Posted April 30, 2016 Share Posted April 30, 2016 Glad to help! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.