;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Sequence of LEDs ;
;Author Clayton Bradley ;
;This version cycles through different ;
;possibilities. Also allows selection ;
;of a specific pattern by means of a ;
;momentary switch ;
;Credit due to Nigel Goodwin for various;
;routines borrowed throughout this ;
;program. ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
LightVal ;the lit LED
StrobeCount ;Counter for number of times the LED strobes
StrobeTimes ;number of times the LED strobes
PatternCount ;Choose pattern
endc
SWPORT equ PORTB
SW1 equ 0x00
AllLEDs equ b'11000110' ;Just a bunch of easy to use mnemonics for the LEDs
LeftLEDs equ b'00000110'
RightLEDs equ b'11000000'
TopLEDs equ b'01000010'
BottomLEDs equ b'10000100'
LeftXLEDs equ b'10000010'
RightXLEDs equ b'01000100'
LED1 equ b'00000010'
LED2 equ b'00000100'
LED3 equ b'01000000'
LED4 equ b'10000000'
PatternNumber equ 0x07
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
bsf STATUS, RP0 ;select bank 1
movlw b'00000001' ;set PortB all outputs except port 0
movwf TRISB
bcf STATUS, RP0 ;select bank 0
movlw 0x03 ;moves the number 3 into StrobeTimes
movwf StrobeTimes ;number of times the LEDs strobe
clrf PatternCount ;initialize Pattern Count
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;Start of Program routine;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call EE_Read
CheckSwitch
call EE_Write
CSDelay
call Delay_On ;allow time for debounce
btfss SWPORT, SW1 ;check if momentary switch has returned to open
call CSDelay ;if not, cycle through again
incf PatternCount, 0 ;increase pattern count, so as to cycle through next pattern
xorlw PatternNumber ;check for last entry by xoring value in Pattern Number with Pattern Count
btfsc STATUS, Z ;check status bit to see if set, if so, Pattern Count higher than Pattern Number
clrf PatternCount ;if status set, reset Pattern Count
movfw PatternCount ;move value of Pattern Count to W to be used in choosing from table
incf PatternCount ;increase Pattern Count to next value
call PatternTable ;now got to Pattern Table to select the next pattern
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;CODE TO STROBE LEDS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Strobe_LED ;code for strobing the LEDs
movwf LightVal ;moves the LED code in the W reg into LightVal for safekeeping
movfw StrobeTimes ;moves the value of StrobeTimes into the W register
movwf StrobeCount ;moves the value to the W register into StrobeCount
StrobeLoop
movfw LightVal ;move LightVal into W
movwf PORTB ;move W into PORTB to turn on selected LEDs
btfss SWPORT, SW1
call CheckSwitch
call Delay_On ;call the delay we set for LED on time
movlw 0x00 ;moves value for LEDs off into W
movwf PORTB ;sets PORTB to off
btfss SWPORT, SW1
call CheckSwitch
call Delay_Off ;calls the delay set for time LED off
decfsz StrobeCount, 1 ;decreases StrobeCount, skip if zero
call StrobeLoop ;loops back for another flash
retlw 0x00 ;return code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EEPROM ROUTINE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EE_Write
movf PatternCount, w ; read current value
bsf STATUS, RP0 ; Bank 1
bsf EECON1, WREN ; Enable write
movwf EEDATA ; set EEPROM data
movlw 0x00
movwf EEADR ; set EEPROM address
movlw 0x55
movwf EECON2 ; Write 55h
movlw 0xAA
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit
; begin write
bcf STATUS, RP0 ; Bank 0
btfss PIR1, EEIF ; wait for write to complete.
goto $-1
bcf PIR1, EEIF ; and clear the 'write complete' flag
bsf STATUS, RP0 ; Bank 1
bcf EECON1, WREN ; Disable write
bcf STATUS, RP0 ; Bank 0
retlw 0x00
EE_Read
bsf STATUS, RP0 ; Bank 1
movlw 0x00
movwf EEADR ; Address to read
bsf EECON1, RD ; EE Read
movf EEDATA, W ; W = EEDATA
bcf STATUS, RP0 ; Bank 0
movwf PatternCount ; restore previous value
retlw 0x00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;LED LOOPS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WigWag_Loop ;loop for the WigWag option
call WigWag_LEDs ;calls the actual code of WigWag
goto WigWag_Loop ;continuous loop
X_Loop
call X_LEDs ;calls the actual code of X_LED
goto X_Loop
TopAndBottom_Loop ;loop for TopAndBottom option
call TopAndBottom_LEDs ;calls the actual code of TopAndBottom
goto TopAndBottom_Loop ;continuous loop
Sequence_Loop ;loop for Sequence option
call Sequence_LEDs ;calls the actual code of Sequence
goto Sequence_Loop ;continuous loop
ZigZag_Loop ;loop for ZigZag
call ZigZag_LEDs ;calls the actual code of ZigZag
goto ZigZag_Loop ;continuous loop
All_Loop ;calls a variety of flash patterns
call All_LEDs
call All_LEDs
call WigWag_LEDs
call WigWag_LEDs
call X_LEDs
call X_LEDs
call TopAndBottom_LEDs
call TopAndBottom_LEDs
call Sequence_LEDs
movlw LED1
call Strobe_LED
call ZigZag_LEDs
movlw LED1
call Strobe_LED
goto All_Loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;LED CALLS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
All_LEDs ;code for flashing all LEDs
movlw AllLEDs ;move all LEDs into W
call Strobe_LED ;strobe
retlw 0x00 ;return code
WigWag_LEDs ;code for WigWag pattern
movlw LeftLEDs ;move left LEDs into W
call Strobe_LED ;strobe
movlw RightLEDs ;move right LEDs into W
call Strobe_LED ;strobe
retlw 0x00 ;return code
X_LEDs ;code for flashing an X pattern
movlw LeftXLEDs ;move top left and bottom right LEDs into W
call Strobe_LED ;strobe
movlw RightXLEDs ;move bottom left and top right LEDs into W
call Strobe_LED ;strobe
retlw 0x00 ;return code
TopAndBottom_LEDs ;code for top and bottom pattern
movlw TopLEDs ;move top row of LEDs into W
call Strobe_LED ;strobe
movlw BottomLEDs ;move bottom row of LEDs into W
call Strobe_LED ;strobe
retlw 0x00 ;return code
Sequence_LEDs ;code for sequence of LEDs
movlw LED1 ;move top left LED into W
call Strobe_LED ;strobe
movlw LED2 ;move bottom left LED into W
call Strobe_LED ;strobe
movlw LED3 ;move top right LED into W
call Strobe_LED ;strobe
movlw LED4 ;move bottom right LED into W
call Strobe_LED ;strobe
movlw LED3 ;move top right LED into W
call Strobe_LED ;strobe
movlw LED2 ;move bottom left LED into W
call Strobe_LED ;strobe
retlw 0x00 ;return code
ZigZag_LEDs ;code for zigzagging LEDs
movlw LED1 ;move top left LED into W
call Strobe_LED ;strobe
movlw LED3 ;move top right LED into W
call Strobe_LED ;strobe
movlw LED2 ;move bottom left LED into W
call Strobe_LED ;strobe
movlw LED4 ;move bottom right LED into W
call Strobe_LED ;strobe
movlw LED2 ;move bottom left LED into W
call Strobe_LED ;strobe
movlw LED3 ;move top right LED into W
call Strobe_LED ;strobe
retlw 0x00 ;return code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;DELAY CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Delay_On
movlw d'40' ;delay 40 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
Delay_Off
movlw d'75' ;delay 75 ms (4 MHz clock)
movwf count1
d2 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_1
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_1
decfsz count1, f
goto d2
retlw 0x00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;LED PATTERN TABLE;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PatternTable
addwf PCL, f ;add W from Check Switch to the PCL to select proper pattern
call WigWag_Loop
call TopAndBottom_Loop
call X_Loop
call Sequence_Loop
call ZigZag_Loop
call All_Loop
end
Clayton said:Turns out, I was having some stack overflow issues also.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?