Knight Rider Circuit for AVR Micro controller

I crafted a code snippet which would give us the lighting sequence of famous Knight Rider car. This would work in Atmel ATMega 16 series micro controller and the program consumes only 266 bytes. Following goes the code.

#include <avr/io.h>

typedef unsigned char  u08;

int main( void )
{

u08 led, i, j, k,flag;
DDRC = 0xff;

led = 1;
flag = 1;

for (;;)
{
PORTC = led;
if(flag)
led = led<<1;

else
led = led>>1;

if (!led && flag)
{
led = 128;
flag = 0;
}

if (!led && !flag)
{
led = 1;
flag = 1;
}

for (i=0; i<127; i++)   /* outer delay loop */
for(j=0; j<127;j++) /* inner delay loop */
k++;

}
}
The speed of the lighting sequence can be altered by adjusting the i and j values of the outer or inner loops. These loops will provide some delay for the circuit. If anybody who wishes to improve this code, go ahead and enjoy.

Advertisements

3 thoughts on “Knight Rider Circuit for AVR Micro controller

  1. “Knight Rider Circuit for AVR Micro controller | Lateral Thoughts” honestly got me simply addicted on ur blog!
    I personallydefinitely will wind up being back much more often.

    Many thanks -Dewayne

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s