Hi all,
Does anyone have any code ideas on how I can increment through specific ports in a while loop? This is the code:
I have tried an array:
but still no luck. I could hard code this but surely there's a way to implement it into a loop?? I just want to control specific PORT bits so I can have control over the others..
Ben.
Does anyone have any code ideas on how I can increment through specific ports in a while loop? This is the code:
Code:
while (p<8)
{
int j = 0;
int k = 200;
while (j < 500 && k > 0)
{
for(i=0;i<j;i++)
{
PORTDbits.RD0 = 1; // THIS IS THE PORT I WANT TO INCREMENT WITH EACH LOOP, RD0, RD1, RD2 etc
__delay_us(100);
}
for(i=0;i<k;i++)
{
PORTDbits.RD0 = 0; // THIS IS THE PORT I WANT TO INCREMENT WITH EACH LOOP, RD0, RD1, RD2 etc
__delay_us(100);
}
j++;
k--;
}
p++;
}
Code:
int array[8];
array[0] = PORTDbits.RD0;
array[1] = PORTDbits.RD1;
array[2] = PORTDbits.RD2;
array[3] = PORTDbits.RD3;
array[4] = PORTDbits.RD4;
array[5] = PORTDbits.RD5;
array[6] = PORTDbits.RD6;
array[7] = PORTDbits.RD7;
while (p<8)
{
int j = 0;
int k = 200;
while (j < 500 && k > 0)
{
for(i=0;i<j;i++)
{
array[m] = 1;
__delay_us(100);
}
for(i=0;i<k;i++)
{
array[m] = 0;
__delay_us(100);
}
j++;
k--;
}
m++;
p++;
}
Ben.