Zone of Eranda

select * from LIFE where category=computers

Knight Rider Circuit for AVR Micro controller

Posted by eranda on August 3, 2008

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.

Advertisement

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 )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.