;****************************************************************
;Started 10-1-2010 Lego Chaser 12F629.asm
;Two displays of 10 LEDs in a "LEGO BLOCK"
;100k pot serves two purposes. Chip detects position of pot (1-10)
;when switched on. Pot adjusts speed of scan for each routine
;****************************************************************
list p=12F629
radix dec
include "p12f629.inc"
errorlevel -302 ; Don't complain about BANK 1
errorlevel -301
__CONFIG _MCLRE_OFF & _CP_OFF
& _WDT_OFF & _INTRC_OSC_NOCLKOUT ;Internal osc.
;****************************************************************
; variables - names files and bit equates
;****************************************************************
;Files for 12F629 start at 20h
; globals
loops equ 20h ;used in "Al-TO" and "All" subroutines
tempA equ 21h ;used in _XmS delay
tempB equ 22h ;used in Fire sub-routine
tempC equ 23h ;used in Fire sub-routine
tempD equ 24h ;used in Hole sub-routine
tempE equ 25h ;used in Hole sub-routine
tempF equ 26h ;used in Hole sub-routine
tempG equ 27h
tempH equ 28h
fetch equ 29h ;used in Join sub-routine
fileA equ 2Ah ;used for Show3_8 and hole
fileB equ 2Bh ;pot
fileC equ 2Ch ;pot
fileD equ 2Dh
DelA equ 2Eh ;used for delay sub-routines
DelB equ 2Fh ;used for delay sub-routines
DelC equ 3Ah ;used for delay sub-routines
temp equ 3Bh ;used for Join sub-routine
temp1_5 equ 3Ch ;used for Join sub-routine
temp6_10 equ 3Dh ;used for Join sub-routine
filezz equ 5Fh ;last available file
status equ 03h
option_reg equ 81h
; bits on GPIO
pin7 equ 0 ;GP0
pin6 equ 1 ;GP1
pin5 equ 2 ;GP2 and T0CkI
pin4 equ 3 ;GP3 input only
pin3 equ 4 ;GP4
pin2 equ 5 ;GP5
;bits
rp0 equ 5 ;bit 5 of the status register
;****************************************************************
;Beginning of program
;****************************************************************
Start org 0x00 ;program starts at location 000
SetUp bsf status,rp0 ;Bank 1
movlw b'10000110' ;Turn off T0CKI, prescaler for TMR0=1:128
movwf option_reg
bcf status,rp0 ;bank 0
movlw 07h ;Set up W to turn off Comparator ports
movwf CMCON ;must be placed in bank 0
movlw 03fh
movwf temp1_5 ;to turn off LEDs 1,2,3,4,5 at start
movwf temp6_10 ;to turn off LEDs 6,7,8,9,10 at start
clrf GPIO ;Clear GPIO of junk
goto Main
;*************************************
;* Tables *
;*************************************
Table1 addwf 02,1 ;Add W to the Program Counter to create a jump
;No LEDs on bit 7 is 0 & file cannot be 0ffh
;When bit7=1 delay for LEDs 1,2,3,4,5 is skipped
retlw b'01111111' ;outputs LEDs 5,6,7,8,9,10 OFF
retlw b'00111110' ;LED1 on bit 6=0 = LEDs 1,2,3,4,5,
; bit 6 = 1 = LEDs 6,7,8,9,10
retlw b'00111101' ;LED2 on
retlw b'00111011' ;LED3 on
retlw b'00101111' ;LED4 on
retlw b'00011111' ;LED5 on
retlw b'10111111' ;LED5 off
retlw b'01111110' ;LED6 on
retlw b'01111101' ;LED7 on
retlw b'01111011' ;LED8 on
retlw b'01101111' ;LED9 on
retlw b'01011111' ;LED10 on
retlw b'00111110' ;LED1 on
retlw b'00111101' ;LED2 on
retlw b'00111011' ;LED3 on
retlw b'00101111' ;LED4 on
retlw b'00011111' ;LED5 on
retlw b'10111111' ;LED5 off
retlw b'01011110' ;LED6&10 on
retlw b'01011101' ;LED7&10 on
retlw b'01011011' ;LED8&10 on
retlw b'01001111' ;LED9&10 on
retlw b'00111110' ;LED1 on
retlw b'00111101' ;LED2 on
retlw b'00111011' ;LED3 on
retlw b'00101111' ;LED4 on
retlw b'00011111' ;LED5 on
retlw b'10111111' ;LED5 off
retlw b'01001110' ;LED6,9,10 on
retlw b'01001101' ;LED7,9,10 on
retlw b'01001011' ;LED8,9,10 on
retlw b'00111110' ;LED1 on
retlw b'00111101' ;LED2 on
retlw b'00111011' ;LED3 on
retlw b'00101111' ;LED4 on
retlw b'00011111' ;LED5 on
retlw b'10111111' ;LED5 off
retlw b'01001010' ;LED6,8,9,10 on
retlw b'01001001' ;LED7,8,9,10 on
retlw b'00111110' ;LED1 on
retlw b'00111101' ;LED2 on
retlw b'00111011' ;LED3 on
retlw b'00101111' ;LED4 on
retlw b'00011111' ;LED5 on
retlw b'10111111' ;LED5 off
retlw b'01001000' ;LED6,7,8,9,10 on
retlw b'00111110' ;LED1 on
retlw b'00111101' ;LED2 on
retlw b'00111011' ;LED3 on
retlw b'00101111' ;LED4 on
retlw b'00011111' ;LED5 on
retlw b'00011110' ;LED1,5 on
retlw b'00011101' ;LED2,5 on
retlw b'00011011' ;LED3,5 on
retlw b'00001111' ;LED4,5 on
retlw b'00001110' ;LED1,4,5 on
retlw b'00001101' ;LED2,4,5 on
retlw b'00001011' ;LED3,4,5 on
retlw b'00001010' ;LED1,3,4,5 on
retlw b'00001001' ;LED2,3,4,5 on
retlw b'00001000' ;LED1,2,3,4,5 on
retlw b'11111111'
retlw b'11111111'
Table2 addwf 02,1 ;Add W to the Program Counter to create a jump
retlw b'00001000' ;all LEDs on bit 6=0 = LEDs 1,2,3,4,5,
retlw b'01001000' ;bit 6 = 1 = LEDs 6,7,8,9,10
retlw b'00001001' ;LED1 off
retlw b'00001010' ;LED2 off
retlw b'00001100' ;LED3 off
retlw b'00011000' ;LED4 off
retlw b'00101000' ;LED5 off
retlw b'00001000' ;all on
retlw b'01001001' ;LED6 off
retlw b'01001010' ;LED7 off
retlw b'01001100' ;LED8 off
retlw b'01011000' ;LED9 off
retlw b'01101000' ;LED10 off
retlw b'01011000' ;LED9 off
retlw b'01001100' ;LED8 off
retlw b'01001010' ;LED7 off
retlw b'01001001' ;LED6 off
retlw b'00101000' ;LED 5 off
retlw b'01001000' ;all on
retlw b'00011000' ;LED 4 off
retlw b'00001100' ;LED 3 off
retlw b'00001010' ;LED2 off
retlw b'11111111'
retlw b'11111111'
;*************************************
;* Delays *
;*************************************
;Delay 1-10mS
_5mS movf fileB,w ;get value of pot to create delay-value
movwf DelB
nop
decfsz DelA,1
goto $-2
decfsz DelB,1
goto $-4
retlw 00
;Delay 0.05 sec (50mS)
_XmS movf tempA,0 ;value from pot position
movwf DelB ;value for DelB from pot position
decfsz DelA,1
goto $-1
decfsz DelB,1
goto $-3
retlw 00
;Delay 0.15 sec (150mS)
_150mS decfsz DelA,1
goto $-1
decfsz DelB,1
goto $-3
retlw 00
;Delay 0.2 sec (200mS)
_200mS nop
decfsz DelA,1
goto $-2
decfsz DelB,1
goto $-4
retlw 00
;************************************
;* Sub routines *
;************************************
;All the routines 1-10
;Routine10 displays all routines 1-9 three times then repeats
All call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
movlw 03
movwf loops
call Show1 ;ScanLRL routine
call Show2
call Show3
call Show4
call Show5
call Show6
call Show7
call Show8
call Show9
call Show10
call Show9
call Show8
call Show7
call Show6
call Show5
call Show4
call Show3
call Show2
decfsz loops,1
goto $-19
call Pot ;fileB will hold a value 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
movlw 03
movwf loops
call Show1_2 ;Scan2 routine
call Show2_3
call Show3_4
call Show4_5
call Show6_7
call Show7_8
call Show8_9
call Show9_10
call Show8_9
call Show7_8
call Show6_7
call Show4_5
call Show3_4
call Show2_3
decfsz loops,1
goto $-15
movlw 03
movwf loops
call Show1_10 ;Bump routine
call Show2_9
call Show3_8
call Show4_7
call Show5_6
call Show5_6
call Show5_6
call Show4_7
call Show3_8
call Show2_9
decfsz loops,1
goto $-11
movlw 03
movwf loops
call Show1_10 ;Cross-over routine
call Show2_9
call Show3_8
call Show4_7
call Show5_6
call Show4_7
call Show3_8
call Show2_9
decfsz loops,1
goto $-9
call Pot ;fileB will hold a value 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
movlw 05 ;Fire routine
movwf tempC
movlw 05
movwf tempB
bsf status, rp0 ;Bank 1
movlw b'11111000' ;Set GP0,1,2 as output
movwf TRISIO
bcf status, rp0 ;bank 0
movlw b'00000000' ;make GP0,1,2 low
movwf GPIO ;turn on LEDs1,2,3
call _XmS
bsf status, rp0 ;Bank 1
movlw b'11111111' ;Set GP0,1,2 as input
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00000000' ;make GP0,1,2 low
movwf GPIO ;turn off LEDs1,2,3
call _XmS
decfsz tempB,1
goto $-15
movlw 05
movwf tempB
bsf status, rp0 ;Bank 1
movlw b'11001011' ;Set GP2,4,5 as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00110100' ;make GP2,4,5 high
movwf GPIO ;turn on LEDs8,9,10
call _XmS
bsf status, rp0 ;Bank 1
movlw b'11111111' ;Set GP0,1,2 as input
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00000000' ;make GP0,1,2 low
movwf GPIO ;turn off LEDs8,9,10
call _XmS
decfsz tempB,1
goto $-15
decfsz tempC,1
goto $-37
movlw 05
movwf tempB
call Show1
call Show2
call Show3
call Show4
call Show5
call Show6
call Show7
call Show8
call Show9
call Show10
call Show9
call Show8
call Show7
call Show6
call Show5
call Show4
call Show3
call Show2
decfsz tempB,1
goto $-19
call Pot ;fileB will hold a value 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
movlw 03 ;Hole routine
movwf loops
call Hole
decfsz loops,1
goto $-2
movlw 03 ;Join routine
movwf loops
call Join
decfsz loops,1
goto $-2
goto All
;At Turn-On, project will detect pot position
;and flash LED 1-10 three times
At_TO movlw 03
movwf loops
call Pot ;fileB will hold a value 1-10
call PotValue ;PotValue will display LED 1-10 for 50mS
call _150mS
bsf status, rp0 ;Bank 1
movlw b'11111111' ;Set all GPIO as input
movwf TRISIO ;turn off all LEDs
bcf status, rp0 ;bank 0
call _150mS
decfsz loops,1
goto $-9
retlw 00
;LEDs bump in middle
Bump call Show1_10
call Show2_9
call Show3_8
call Show4_7
call Show5_6
call Show5_6
call Show5_6
call Show4_7
call Show3_8
call Show2_9
goto Routine3
;Fire 3 left, 3 right, scan back/forth
Fire movlw 05
movwf tempC
movlw 05
movwf tempB
bsf status, rp0 ;Bank 1
movlw b'11111000' ;Set GP0,1,2 as output
movwf TRISIO
bcf status, rp0 ;bank 0
movlw b'00000000' ;make GP0,1,2 low
movwf GPIO ;turn on LEDs1,2,3
call _XmS
bsf status, rp0 ;Bank 1
movlw b'11111111' ;Set GP0,1,2 as input
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00000000' ;make GP0,1,2 low
movwf GPIO ;turn off LEDs1,2,3
call _XmS
decfsz tempB,1
goto $-15
movlw 05
movwf tempB
bsf status, rp0 ;Bank 1
movlw b'11001011' ;Set GP2,4,5 as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00110100' ;make GP2,4,5 high
movwf GPIO ;turn on LEDs8,9,10
call _XmS
bsf status, rp0 ;Bank 1
movlw b'11111111' ;Set GP0,1,2 as input
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00000000' ;make GP0,1,2 low
movwf GPIO ;turn off LEDs8,9,10
call _XmS
decfsz tempB,1
goto $-15
decfsz tempC,1
goto $-37
movlw 05
movwf tempB
call Show1
call Show2
call Show3
call Show4
call Show5
call Show6
call Show7
call Show8
call Show9
call Show10
call Show9
call Show8
call Show7
call Show6
call Show5
call Show4
call Show3
call Show2
decfsz tempB,1
goto $-19
retlw 00
;Get Routine
GetRoutine
decfsz fileB,1
goto $+2
goto Routine1
decfsz fileB,1
goto $+2
goto Routine2
decfsz fileB,1
goto $+2
goto Routine3
decfsz fileB,1
goto $+2
goto Routine4
decfsz fileB,1
goto $+2
goto Routine5
decfsz fileB,1
goto $+2
goto Routine6
decfsz fileB,1
goto $+2
goto Routine7
decfsz fileB,1
goto $+2
goto Routine8
decfsz fileB,1
goto $+2
goto Routine9
decfsz fileB,1
goto $+2
goto Routine10
retlw 00 ;no value to be shown
;Hole All LEDs are illuminated and a hole runs RLR
Hole clrf fetch ;used to fetch down the table
movlw 05h ;a
movwf fileA ;5 loops for multiplexing
movf fetch,w ;_b
call Table2 ;bit6=0=LEDs 1,2,3,4,5
movwf temp ;is bit 6=0?
btfsc temp,6
goto $+2
movwf temp1_5 ;temp storage
movf temp1_5,w ;reclaim previous value
bsf status, rp0 ;Bank 1
movwf TRISIO ;Set GPIO's as in/out
bcf status, rp0 ;bank 0
clrf GPIO ;turn on LEDs 1,2,3,4,5
btfsc temp,7 ;when bit7=1 delay is skipped
goto $+.17
call _5mS ;
movf fetch,w
call Table2
movwf temp ;is bit 6=1?
btfss temp,6
goto $+2
movwf temp6_10 ;temp storage
movf temp6_10,w ;reclaim previous value
bsf status, rp0 ;Bank 1
movwf TRISIO ;Set GPIO's as in/out
bcf status, rp0 ;bank 0
movlw 0ffh
movwf GPIO ;turn on LEDs 6,7,8,9,10
call _5mS
decfsz fileA,1
goto $-.28 ;_b
incf fetch,1
movf temp,0
xorlw 0ffh
btfsc status,z
retlw 00
goto $-.36 ;_a
;Join LEDS run across screen and join at right hand side
Join clrf fetch ;used to fetch down the table
movlw 05h ;_a
movwf fileA ;5 loops for multiplexing
movf fetch,w ;_b
call Table1 ;bit6=0=LEDs 1,2,3,4,5
movwf temp ;is bit 6=0?
btfsc temp,6
goto $+2
movwf temp1_5 ;temp storage
movf temp1_5,w ;reclaim previous value
bsf status, rp0 ;Bank 1
movwf TRISIO ;Set GPIO's as in/out
bcf status, rp0 ;bank 0
clrf GPIO ;turn on LEDs 1,2,3,4,5
btfsc temp,7 ;when bit7=1 delay is skipped
goto $+.17
call _5mS
movf fetch,w
call Table1
movwf temp ;is bit 6=1?
btfss temp,6
goto $+2
movwf temp6_10 ;temp storage
movf temp6_10,w ;reclaim previous value
bsf status, rp0 ;Bank 1
movwf TRISIO ;Set GPIO's as in/out
bcf status, rp0 ;bank 0
movlw 0ffh
movwf GPIO ;turn on LEDs 6,7,8,9,10
call _5mS
decfsz fileA,1
goto $-.28 ;_b
incf fetch,1
movf temp,0
xorlw 0ffh
btfsc status,z
retlw 00
goto $-.36 ;_a
;Detects position of 100k pot - produces a result 1-10
;for routines or speed of scanning
Pot clrf fileB ;create value for 1-5 routines
incf fileB,1 ;to enable 1 on display
bsf status, rp0 ;Bank 1
movlw b'11101111' ;Set GP4 as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00010000' ;make GP4 high
movwf GPIO ;to discharge 100n
movlw 38h ;short delay
movwf DelA
nop
decfsz DelA,1
goto $-2
movlw b'00000000' ;make GP4 low
movwf GPIO ;
bsf status, rp0 ;Bank 1
movlw b'11111111' ;Set GP3,4 as input
movwf TRISIO ;
bcf status, rp0 ;bank 0
btfsc GPIO,3 ;see if 100n has charged
goto $+3
incf fileB,1 ;incr loops
goto $-.14
retlw 00 ;fileB will hold a value 1-10
;Show pot value on display, 1-10
PotValue decfsz fileB,1
goto $+2
goto show1
decfsz fileB,1
goto $+2
goto show2
decfsz fileB,1
goto $+2
goto show3
decfsz fileB,1
goto $+2
goto show4
decfsz fileB,1
goto $+2
goto show5
decfsz fileB,1
goto $+2
goto show6
decfsz fileB,1
goto $+2
goto show7
decfsz fileB,1
goto $+2
goto show8
decfsz fileB,1
goto $+2
goto show9
decfsz fileB,1
goto $+2
goto show10
retlw 00 ;no value to be shown
;Scan back/forth
ScanLRL call Show1
call Show2
call Show3
call Show4
call Show5
call Show6
call Show7
call Show8
call Show9
call Show10
call Show9
call Show8
call Show7
call Show6
call Show5
call Show4
call Show3
call Show2
goto Routine1
;Scan back/forth 2 LEDs
Scan2 call Show1_2
call Show2_3
call Show3_4
call Show4_5
call Show6_7
call Show7_8
call Show8_9
call Show9_10
call Show8_9
call Show7_8
call Show6_7
call Show4_5
call Show3_4
call Show2_3
goto Routine2
Show1 movlw b'11111110' ;Set GP0 as output
goto GPIOlow
Show2 movlw b'11111101' ;Set GP1 as output
goto GPIOlow
Show3 movlw b'11111011' ;Set GP2 as output
goto GPIOlow
Show4 movlw b'11101111' ;Set GP4 as output
goto GPIOlow
Show5 movlw b'11011111' ;Set GP5 as output
goto GPIOlow
Show6 movlw b'11111110' ;Set GP0 as output
goto GPIOhi
Show7 movlw b'11111101' ;Set GP1 as output
goto GPIOhi
Show8 movlw b'11111011' ;Set GP2 as output
goto GPIOhi
Show9 movlw b'11101111' ;Set GP4 as output
goto GPIOhi
Show10 movlw b'11011111' ;Set GP5 as output
goto GPIOhi
GPIOlow tris gpio ;
movlw b'00000000'
movwf GPIO ;
goto _XmS
GPIOhi tris gpio
movlw b'11111111'
movwf GPIO ;
goto _XmS
Show1_2 movlw b'11111100' ;Set GP0,1 as output
goto GPIOlow
Show2_3 movlw b'11111001' ;Set GP1,2 as output
goto GPIOlow
Show3_4 movlw b'11101011' ;Set GP2,4 as output
goto GPIOlow
Show4_5 movlw b'11001111' ;Set GP4,5 as output
goto GPIOlow
Show5_6 bsf status, rp0 ;Bank 1
movlw b'11011110' ;Set GP0,5 as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00000001' ;make GP5 low GP0 HIGH
movwf GPIO ;turn on LED5&6
goto _XmS
Show6_7 movlw b'11111100' ;Set GP0,1 as output
goto GPIOhi
Show7_8 movlw b'11111001' ;Set GP1,2 as output
goto GPIOhi
Show8_9 movlw b'11101011' ;Set GP2,4 as output
goto GPIOhi
Show9_10 movlw b'11001111' ;Set GP4,5 as output
goto GPIOhi
;subroutines for Cross-over
Show1_10 bsf status, rp0 ;Bank 1
movlw b'11011110' ;Set GP0,5 as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00100000' ;make GP0 low GP5 high
movwf GPIO ;turn on LED1&10
goto _XmS
Show2_9 bsf status, rp0 ;Bank 1
movlw b'11101101' ;Set GP1,4 as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00010000' ;make GP1 low GP4 high
movwf GPIO ;turn on LED2&9
goto _XmS
Show3_8 movlw 05h
movwf fileA
bsf status, rp0 ;Bank 1
movlw b'11111011' ;Set GP2, as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00000000' ;make GP0 low
movwf GPIO ;turn on LED3
call _5mS
bsf status, rp0 ;Bank 1
movlw b'11111011' ;Set GP2, as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00000100' ;make GP0 high
movwf GPIO ;turn on LED8
call _5mS
decfsz fileA,1
goto $-.15
retlw 00
Show4_7 bsf status, rp0 ;Bank 1
movlw b'11101101' ;Set GP4,1 as output
movwf TRISIO ;
bcf status, rp0 ;bank 0
movlw b'00000010' ;make GP0 low
movwf GPIO ;turn on LED4&7
goto _XmS
;Cross-over LEDs cross-over in the middle
Xover call Show1_10
call Show2_9
call Show3_8
call Show4_7
call Show5_6
call Show4_7
call Show3_8
call Show2_9
goto Routine4
;*************************************
;* Main *
;*************************************
Main call At_TO ;at Turn-On LED 1-10 will flash 3 times
call Pot ;fileB will hold a value 1-10
goto getRoutine ;returns with Routine 1-10
Routine1
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
goto ScanLRL
Routine2
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
goto Scan2
Routine3
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
goto Bump
Routine4
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
goto Xover
Routine5
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
call Fire
goto $-1
Routine6
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
call Hole
goto $-1
Routine7
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
call Join
goto Routine7
Routine8
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
call Hole
goto $-1
Routine9
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
call Hole
goto $-1
Routine10
call Pot ;get value of pot in fileB 1-10
swapf fileB,0 ;swap nibbles = x8 and put in w
movwf tempA
goto All
;oscillator calibration
call 03ffh
movwf OSCCAL
end
|