CD-PC Website AVR running light


Description:
Test code for running on any avr. Maybe it needs some disabling of the outputs, not every avr has 32 outputs.

Code:

/*****************************************
* Copyright damic 2014 cd-pc.mazda-club.be
******************************************/

//#define OSCCAL 16000001UL;
#define F_CPU 8000000uL 
#include <util/delay.h>
#include <avr/io.h>

#define PAUSE_THRESHOLD 10
int main(void)
{
//in- and outputs
	DDRA = DDRB = DDRC = DDRD = 255;        //Ports as output 0b11111111
    PORTA = PORTB = PORTC = PORTD = 0;          //all off
	unsigned int bRight=1;
	unsigned int iWhere=0;
	while(1)
	{
		if(bRight==1){iWhere++;}else{iWhere--;}
		PORTA=(1<<iWhere);
		PORTB=(1<<iWhere);
		PORTC=(1<<iWhere);
		PORTD=(1<<iWhere);
		if(iWhere==7 && bRight==1)
		{
			iWhere--;
			bRight=0;
		}else if(iWhere==0&&bRight==0){
			iWhere++;
			bRight=1;
		}
		_delay_ms(PAUSE_THRESHOLD);
	}
}

Youtube video:
AT90CAN64 running light

Status: Final.

Last page update: 15-07-2014