I am asking this because the code below is what I'm using to make the 2 two leds perfectly alternate their flashing. But it doesn't really make sense as to why this works. This loop with 2 xor's has 2 states one with pin1(red lit only) active and another with both pin 6 and pin 1 active(both red and green lit). But the lights flash like they are alternating on and off perfectly between each other.
#include <msp430g2553.h>
// counter as a global variable
unsigned int i = 0;
void main(void)
{
// stop the watchdog timer
WDTCTL = WDTPW + WDTHOLD;
// set the direction register for LED1 and LED2
P1DIR |= 0x41;
// initialize LED1 and LED2 to off
P1OUT &= 0xBE;
//empty for loop is an infinite loop
for (;;)
{
P1OUT ^= 0x01;
// create a delay between toggles
for(i=0; i< 20000; i++)
{
// empty statement, do nothing
}
P1OUT ^= 0x40;
}
}
Is it possible the delay for the main for loop is causing this illusion?