Flickering LED's

program and circuit


The C program I use for my flickering LED's was written by Jason Netzly who at one time maintained a website named R4NDOM which has since gone 404. Jason had put together a very compact circuit to simulate a flickering candle flame using 5 LED's and a PIC12F675 microcontroller. Here's Jason's program. Note you will need the XC compiler used with MPLAB X IDE to compile it.

#include <xc.h>

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
  & UNPROTECT & BORDIS);
                             
int i, j, k;
int fourBitLFSR, sixBitLFSR;

main()
{
    fourBitLFSR = 20;                      //  Start at 1
    sixBitLFSR = 1000;                       //  Start at 1
    GPIO = 0;
    ANSEL = 0;                 				//  Turn off ADC
    TRISIO = 0;
    while(1 == 1)               				//  Loop Forever
    {
        for (k = 0; k < fourBitLFSR; k++)  //  Delay 0.1s x 4 Bit LFSR
            for (i = 0; i < 255; i++)
                for (j = 0; j < 2; j++);

        GPIO = sixBitLFSR | fourBitLFSR;  //  Maximize Number of LEDs on

        fourBitLFSR = ((fourBitLFSR << 1) & 0x0F) + ((fourBitLFSR >> 3) ^ ((fourBitLFSR >> 2) & 1));

        sixBitLFSR = ((sixBitLFSR << 1) & 0x3F) + ((sixBitLFSR >> 5) ^ ((sixBitLFSR >> 4) & 1));
    }
}	


Here is the circuit I currently use for my flickering LED's. At first I just soldered circuits up from scratch as I needed them but later when I began putting them in the andons that I sold I had some printed circuit boards made to order.

flickering leds schematic



What's up?