On my development board, I am trying to make 8 LEDs (0 - 7) blink one by one.
Here, is my code. What do I need to change to get my desired output, Please help.

int main (void)
{
	int a,b;
	DDRC = 0xFF;
	PORTC = 0xFF;
	num = PORTC;
	for (;;)
	{
		for (a=1;a<=8;a++)
		{
			num = num >> a;
			for (b=0;b<4;b++)
			{
				PORTC = num;
				num = num | 0xFF;
				delay();
			}
			num = 0xFF;
		}
		PORTC = 0xFF;
	}
	return;
}

void delay()
{
	unsigned char i,j,k;

	for (i=0;i<255;i++)
	{
		for (j=0;j<255;j++)
		{
			for (k=0;k<109;k++)
			{
				;
			}
		}
	}
	return ;
}

"Glow an LED" is too vague a description. You need to provide more details. I had worked on such boards once. There, sending a 0 bit to the LED used to glow the LED.

In your case, assuming sending a 0 to an LED glows it, this is what you can try:

Take an 8 bit char, equate it to 1.
So, this is 0 0 0 0 0 0 0 1

Let num = 0 0 0 0 0 0 0 1
Now, keep left shifting this, take compliment and pass it to your PORT. So, in the second iteration, you get ~(0 0 0 0 0 0 1 0) = (1 1 1 1 1 1 0 1).

That glows the second LED. So you could loop through it. Is this what you were looking for? If not, provide more details about your problem.

I want them to blink one by one. Lets say 5 blinks for the first LED then off. Then the next one does 5 blinks and so on. Only 1 should blink at a time and rest should be off.
~ will turn ON the rest when it gets executed, I don't want that. Hope this is more clear. Thanks in advance.

>>Only 1 should blink at a time and rest should be off.

So, the method i had suggested should be fine right? Except, you need to pass the same value 5 times(for the blink). So, shift + compliment should be fine in your case right? Of course with a loop that iterates 5 times for the blink.

But taking the compliment and passing it to the PORT will turn on rest of them as well as they all become 0. I just that 1 LED blinking at a time. I managed to get them all going by using ^ XOR not the ~ compliment. But I don't know how to do 1 at a time?

>>But taking the compliment and passing it to the PORT will turn on rest of them as well as they all become 0

I'm sorry, i didn't get you. How will all be 0 if you take the compliment?

Take an 8 bit char, equate it to 1.
So, this is 0 0 0 0 0 0 0 1

Let num = 0 0 0 0 0 0 0 1
Now, keep left shifting this, take compliment and pass it to your PORT. So, in the second iteration, you get ~(0 0 0 0 0 0 1 0) = (1 1 1 1 1 1 0 1).

That glows the second LED. So you could loop through it. Is this what you were looking for? If not, provide more details about your problem.

That is what i had posted. Am i missing something here?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.