Software Code

The compiled code, along with the MAKE file can be downloaded below. The code runs at a frequency of 16 Mhz. The output of the random generator is put on PORTB so random numbers of LED channels are switched on. between two port updates, a random amount of delay is executed.

/*
program name: flickering candle
date: 26-oct-2014
author: www.avrprojects.net
target device : ATMEGA328
*/

#include<avr/io.h>
#define F_CPU 1600000UL
#include<util/delay.h>


int main(void)

{
unsigned long lfsr = 1;
unsigned char temp;
DDRB= 0xFF; // set PORTB as output

while(1)
{
lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xd0000001u); // taps 32 31 29 1
temp = (unsigned char) lfsr; //take lowermost eight bits

PORTB = temp;//Give the value of 0 to the pins declared output

temp = (unsigned char) (lfsr >> 24);

_delay_loop_2(temp<<7);
}
}