Christmas Light Flasher

Here is a Christmas Light Flasher!

I blew up the controller for a battery operated LED based christmas lights, so here is a really simple flasher to replace the controller.


It uses a PIC16F84A using an RC oscillator, clocking the PIC at 22kHz. Adjust the values of R1 and C1 to suit, or adjust the constant at the start of the delay routine. value

The PIC can sink 25mA per pin, so make R3 limit the current to 25mA max.

The code for the flasher is found in st.zip. The LEDs at the top of this page are flashed by some JavaScript in a similar way that the PIC chip flashes them.

 ;**********************************************************************
 ;                                                                     *
 ;    Filename:	    st001.asm  - christmas LED  flasher                *
 ;    Date:          14/12/2002                                        *
 ;    File Version:                                                    *
 ;                                                                     *
 ;    Author:        Doug Rice                                         *
 ;                                                                     *
 ;**********************************************************************
 ;                                                                     *
 ;    Files required:                                                  *
 ;                                                                     *
 ;**********************************************************************
 ;                                                                     *
 ;    Notes:                                                           *
 ;                                                                     *
 ;**********************************************************************
 
 
 	list      p=16F84             ; list directive to define processor
 	#include <p16F84.inc>         ; processor specific variable definitions
 
 	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC
 
 ; '__CONFIG' directive is used to embed configuration data within .asm file.
 ; The lables following the directive are located in the respective .inc file.
 ; See respective data sheet for additional information on configuration word.
 
 ;**********************************************************************
 		ORG     0x000             ; processor reset vector
   		goto    main              ; go to beginning of program
 
 
 		ORG     0x004             ; interrupt vector location
 
    cblock 0x0c
 	countL		; counter used for a delay
 	ptr		; pointer into the data
 
    endc
 
 main
 
 ; remaining code goes here
 ; define bit in Port B
 
 r	equ 	4
 y	equ 	2
 g	equ 	1
 
 	clrf	PORTB
 	clrf	ptr
 loop1
 	CALL	nextSample
 	
 	; Now turn on the LED's by making the PORTB pins Outputs
 	xorlw	0xff
 	TRIS	PORTB
 	; Force any outputs low
 	movlw	0
 	movwf	PORTB
 
 	; delay
 	call	delay1
 
 
 	; Turn off all the LEDS 
 	movlw	0xFF
 	TRIS	PORTB
 	movlw	0
 	movwf	PORTB
 
 	; delay for two delays
 	call	delay1
 	call	delay1
 
 	; loop around
 	goto loop1
 
 
 delay	; delay the code
 	; return
 	movlw	25
 	movwf	countL
 delay1
 	decfsz	countL,f
 	goto	delay1
 	return
 
 
 nextSample
 	; This uses a table read.
 	; no attempt is made to check if PCLATH is correctly set.
 	;
 	incfsz	ptr,f
 	nop
 	movfw	ptr
 	; limit the index to 64 bytes
 	andlw	0x3F
 	addwf	PCL,F
 table
 
 
 	RETLW 	0
 	RETLW 	0
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	         g        
 
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	         g        
 
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	         g        
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	         g        
 
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	         g        
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	         g        
 
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	         g        
 
 	RETLW 	0
 	RETLW 	0
 	RETLW 	r        
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	    y        
 	RETLW 	         g        
 	RETLW 	         g        
 	RETLW 	0
 	RETLW 	0
 	RETLW 	r        
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	    y        
 	RETLW 	         g        
 	RETLW 	         g        
 	RETLW 	0
 	RETLW 	0
 	RETLW 	r        
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	    y        
 	RETLW 	         g        
 	RETLW 	         g        
 	RETLW 	0
 	RETLW 	0
 	RETLW 	r        
 	RETLW 	r        
 	RETLW 	    y        
 	RETLW 	    y        
 	RETLW 	         g        
 
 	; at the end zero ptr and return a value to loop around again.
 	clrf	ptr
 	RETLW 	         g        
 
 	clrf	ptr
 
 	END                     ; directive 'end of program'
 

Updated by Doug Rice,