Problem With The C Code !

This C Code , to me , logically seems correct , but doesnt seem to work accordingly .

I am new to c coding so please correct me where i am wrong and in places where a better implementation is possible .

Looking forward to your precious comments and opinions !










/*****************************************************
Project : Use a single switch to produce 4 different LED patterns
Version : V666.a1
Date : 7/28/2011
Author : Freeware, for evaluation and non-commercial use only
Company : SinetCorp.
Comments:


Chip type : ATmega16
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/

#include

#include

int i,count=0;


void main(void)
{
int arr1[5]={0x81,0x42,0x24,0x18}; /* Converge */
int arr2[5]={0x18,0x24,0x42,0x81}; /* Diverge */
int arr3[9]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; /* Increasing */


DDRA=0xff; /* Connected To LEDs */
DDRB.0=0x00; /* Connected To A Single Switch

*/



while (1)
{
if(count>3)

{
count=count-2;
}

if(count==2)
{
goto loop1;
}


if(count==3)
{
goto loop2;
}
else
{
if(PINB.0==1||count==1)
{
while(count!=1)
{
count=count+1;
}
for(i=0;i<4;i++)
{
if(PINB.0==1||count==2)
{
while(count!=2)
{
count=count+1;
}
loop1: for(i=0;i<4;i++)
{
if(PINB.0==1||count==3)
{
while(count!=3)
{
count =count+1;
}


loop2: for(i=0;i<8;i++)
{
PORTA=arr3[i];
delay_ms(600);
}
}

PORTA=arr2[i];
delay_ms(600);

}
}

PORTA=arr1[i];
delay_ms(600);

}
}
}

if(PINB.0==0)
{
PORTA=0x00;
}

}
}



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories