Need to run 2 for loops simultaneously in C. Microprocessor Class. MSP430 TI
In my Microprocessors class we have been tasked with creating 2 different displays with a string of 8 LED lights depending on different buttons presses. The first display was simple on the second display 2 lights must start at the center and bounce to the outside and return to the center. Basically 0001_1000 then 0010_0100 so on until 1000_0001, then return to the original 0001_1000 in the same fashion.
To accomplish this I have tried 2 for loops, but the problem is having them run simultaneously.
If it helps any the Hardware is TI MSP430 Launchpad.
Also, the for loops in question are in bold and italics.
Code:
#include <MSP430G2553.h>
#define DELAY 250000
#define DELAY2 150000
void main()
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0x00;
P2REN |= (BIT3|BIT4);
P2OUT &= (~(BIT3&BIT4));
unsigned int i, j;
while(1)
{
if(P2IN&BIT3)
{
P1DIR = 0xFF;
while(1)
{
P1OUT = 0xA0;
for(i=0;i<6;i++)
{
_delay_cycles(DELAY);
P1OUT = P1OUT>>1;
}
P1OUT = 0x05;
for(i=0;i<6;i++)
{
_delay_cycles(DELAY);
P1OUT = P1OUT<<1;
}
}
}
if(P2IN&BIT4)
{
P1DIR = 0xFF;
while(1)
{
P1OUT = 0x10;
for(i=0;i<1;i++)
{
_delay_cycles(DELAY2);
P1OUT = P1OUT>>1;
}
P1OUT = 0x08;
for(j=0;j<3;j++)
{
_delay_cycles(DELAY2);
P1OUT = P1OUT<<1;
}
}
}
}
}
}
Thank You,
Taylor Hamilton