• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Led candle with 16f84a

Thread starter #1
Hi All,

I would like to make a flickering candle with leds.

I have seen these but I want to use some rgb leds I have so I can control the colours remotely.

Initially of course the led candle will be flickering yellow and orange but I bought a 5 function remote control from Ebay and I want to use this to control the different colours... eg maybe red/pink... blue/purple..different shades of green..

If anybody has the code, and maybe the schematic, just to control the yellow/orange, that would be great to start.

Any help with the code and schematic for the other effects would be appreciated.


Thread starter #3
Thanks 3vo,
I will get to this soon. It looks like what i'm after.
I would still like to use the rgb led idea so if anyone else has those details, that would be appreciated.
Thread starter #4
Led candle code doesn't work with 16f84a

Thanks again 3v0 for the link but unfortunately the code comes back from my winpic programmer with errors.
I presume that would be because i'm using a 16f84a instead of the original 12f675.
Can anyone help me with the alterations needed to get this to work on my pic.

Here is the hex..


And here is the source code..

; Candle Simulation
; 6/04 Luhan Monat
; Simulate flicker of candle using incandescent lamp

device PIC12F675,intrc_osc,pwrte_on,wdt_off

org 20h

del1 ds 1
del2 ds 1
pcnt ds 1
temp ds 1
lev1 ds 1
lev2 ds 1
level ds 1
rbuf ds 5

LAMP = gp.5

org 0
goto start

org 4

start bsf RP0
movlw 0
movwf GP
movlw 127
movwf OSCCAL
bcf RP0
bsf rbuf,0 ;seed random number
movlw 127
movwf lev1 ;initial light level
movwf lev2

; Main Loop
; Create hi and low power levels
; Switch between levels

candle movf lev1,w
movwf level
call power ;do lev1 power
call rando
andlw 7
btfss z
goto :run ;skip 7 out of 8
call rmid ;generate new hi and low levels
movwf lev1
sublw 0
movwf lev2
:run movf lev2,w ;do lev2 power
movwf level
call power
goto candle

; PWM power control

power movlw 100 ;set flicker rate: higher=slower
movwf pcnt ;set loop count
:p1 movf level,w ;get target level
movwf del1 ;set 1st delay
sublw 0
movwf del2 ;set 2nd delay
bsf LAMP ;power on
:p3 nop
decfsz del1 ;do 1st delay
goto :p3
bcf LAMP ;power off
:p4 nop
decfsz del2 ;second delay
goto :p4
decfsz pcnt
goto :p1

; find sum of 4 random numbers
; skews results around 127

rmid call rando
andlw 3fh
movwf temp
call rando
andlw 3fh
addwf temp
call rando
andlw 3fh
addwf temp
call rando
andlw 3fh
addwf temp,w

; Pseudo Rando Number
; "Chop Suey Machine"

rando movf rbuf,w
addwf rbuf+1,w
movwf rbuf+1
addwf rbuf+2,w
movwf rbuf+2
addwf rbuf+3,w
movwf rbuf+3
addwf rbuf+4,w
movwf rbuf+4
bcf c
rlf rbuf+4
btfsc c
bsf rbuf+4,0
movf rbuf+4,w
addwf rbuf



Thanks in advance....


Coop Build Coordinator
Forum Supporter
1st: When you post code always use code tags to keep formating correct. It is the # icon and generates tags like [CODE][/CODE]. You place your code between them.

2nd: If you want errors fixed you have to tell them what they are. The crystal ball routine was old a long time ago.

3rd: I would use a modern PIC with an internal osc like the 16F88 or 18F1320. It is also about half the price.

4th: I do not program in assembly. Some here do and they can help you if you want. There is no reason this code needs to be written in asm and since you want to modify it anyway you may as well start with c or basic.

5th: If you do not know how to program in any language this is over your head. We all started by blinking a single LED.

Last edited:

Latest threads

EE World Online Articles