12DIGIT RUNNING
SIGN
for PIC16F628
;****************************************************************
;* 12 Digit RUNNING SIGN Started 23/8/2010 *
;****************************************************************
;list P = 16F628 ;microcontroller
include ;registers for F628
errorlevel -302 ;remove message about using proper bank
__Config _cp_off & _lvp_off & _pwrte_on &
_wdt_off & _intRC_osc_noclkout & _mclre_off
;code protection - off
;low-voltage programming - off
;power-up timer - on
;watchdog timer - off
;use internal RC for 4MHz - all pins for in-out
;****************************************************************
; variables - names and files
;****************************************************************
;Files for F628 start at 20h
temp1 equ 20h
temp2 equ 21h
store equ 22h ;for storing data for first 10 digits in Sw3
timera equ 23h ;
timerb equ 24h ;
Sw_Flag equ 25h ;
count equ 26h ;loops of discharge time for 100n
flags equ 27h ;
Jump_1 equ 28h ;jump counter for table1
Run equ 29h ;used in RUN (Sw5) routine
temp_sw equ 2Ah
ScanLoops equ 2Bh
RunLoops equ 70h
Save equ 71h
Ghost equ 72h
GhostTemp equ 73h
Window equ 74h
WindowTemp equ 75h
_12loops equ 76h
;****************************************************************
;Equates
;****************************************************************
status equ 0x03
cmcon equ 0x1F
rp1 equ 0x06
rp0 equ 0x05
;****************************************************************
;Beginning of program
;****************************************************************
reset org 00 ;reset vector address
SetUp bsf status,rp0
movlw b'00000000' ;A in/out
movwf 05h
movlw b'00000000' ;B output
movwf 06h
movlw b'10000000' ;Turn off T0CKI, prescale for TMR0 = 1
movwf option_reg
bcf status,rp0 ;select programming area - bank0
movlw 07h ;turn comparators off and enable
movwf cmcon ; pins for I/O functions
call Clear
call Attract
call Clear
goto Main
;**************************
;* Tables *
;**************************
table1
addwf 02h,1 ;add W to program counter
nop
retlw 06h ;1
retlw 5Bh ;2
retlw 4Fh ;3
retlw 66h ;4
retlw 6Dh ;5
retlw 7Dh ;6
retlw 07h ;7
retlw 7Fh ;8
retlw 6Fh ;9
retlw 3Fh ;0
retlw 77h ;A
retlw 7Ch ;b
retlw 39h ;C
retlw 5Eh ;d
retlw 79h ;E
retlw 71h ;F
retlw 6Fh ;g
retlw 76h ;H
retlw 06h ;I
retlw 1Eh ;J
retlw 38h ;L
retlw 37h ;N
retlw 3Fh ;O
retlw 73h ;P
retlw 67h ;q
retlw 50h ;r
retlw 6Dh ;S
retlw 78h ;t
retlw 3Eh ;U
retlw 6Eh ;y
retlw 80h ;dot
retlw 40 ;-
retlw 08h ;_space
retlw 1 ;line on top
retlw 48h ;equals . . . . . .24h chars
retlw 0ffh ;end of table
;****************************************
;* Delay sub-routines *
;****************************************
;Delay 10uS
_10uS nop
nop
nop
nop
nop
nop
retlw 00
_500uS decfsz temp1,f
goto $-1
retlw 00
_1mS nop
decfsz temp1,f
goto _1mS
retlw 00
_4mS movlw 04h
movwf temp2
_b nop
decfsz temp1,f
goto _b
decfsz temp2,f
goto _b
retlw 00
_10mS movlw 0Ah
movwf temp2
_c nop
decfsz temp1,f
goto _c
decfsz temp2,f
goto _c
retlw 00
Delay1 movlw 1
movwf timerb
Del_a decfsz timera,1
goto Del_a
decfsz timerb,1
goto Del_a
retlw 00
Delay2 Decfsz timera,1
goto Delay2
Decfsz timerb,1
goto Delay2
retlw 00
;************************************
;* sub-routines
;*
;************************************
;12DIGIT_RUNNING_SIGN_BY_TE
;Attract calls Sw5 RUN sub-routine (Sw_Flag is empty)
Attract movlw 06h ;1
movwf 40h
movlw 5Bh ;2
movwf 41h
movlw 40 ;-
movwf 42h
movlw 5Eh ;d
movwf 43h
movlw 06h ;I
movwf 44h
movlw 6Fh ;g
movwf 45h
movlw 06h ;I
movwf 46h
movlw 78h ;t
movwf 47h
movlw 08h ;_
movwf 48h
movlw 50h ;r
movwf 49h
movlw 3Eh ;U
movwf 4Ah
movlw 37h ;N
movwf 4Bh
movlw 37h ;N
movwf 4Ch
movlw 06h ;I
movwf 4Dh
movlw 37h ;N
movwf 4Eh
movlw 6Fh ;g
movwf 4Fh
movlw 08h ;_
movwf 50h
movlw 6Dh ;S
movwf 51h
movlw 06h ;I
movwf 52h
movlw 6Fh ;g
movwf 53h
movlw 37h ;N
movwf 54h
movlw 08h ;_
movwf 55h
movlw 7Ch ;b
movwf 56h
movlw 6Eh ;y
movwf 57h
movlw 08h ;_
movwf 58h
movlw 78h ;t
movwf 59h
movlw 79h ;E
movwf 5Ah
call Set4017
call Transfer
call sw5
retlw 00
Clear ;all files from 21h to 6Fh are cleared
movlw 4Fh ;number of files to be cleared =loops
movwf temp1
movlw 21h
movwf fsr
movlw 0
movwf 00h
incf fsr,1
decfsz temp1,1
goto $-4
retlw 00
;Clock the 4017
clock bsf 05h,4 ;clock the 4017 via RA4
call _10uS
bcf 05h,4
call _10uS
retlw 00
;12 digits are scanned by making first output of 4017 HIGH
;and making appropriate digits LOW via PIC chip.
;Data is taken from files 60h - 6Bh.
;"1" in bit0 becomes segmentA etc. "1" in bit7=dot.
;move the 12 files to the right and use bit0 again.
;Repeat 8 times.
Scan movlw 08
movwf ScanLoops
clrf portA
decf portA,1 ;make bits 0 to 3 HIGH to turn off segments
clrf portB
decf portB,1 ;make bits 0 to 7 HIGH to turn off segments
btfsc 60h,0
bcf portA,0
btfsc 61h,0
bcf portA,1
btfsc 62h,0
bcf portA,2
btfsc 63h,0
bcf portA,3
btfsc 64h,0
bcf portB,0
btfsc 65h,0
bcf portB,1
btfsc 66h,0
bcf portB,2
btfsc 67h,0
bcf portB,3
btfsc 68h,0
bcf portB,4
btfsc 69h,0
bcf portB,5
btfsc 6Ah,0
bcf portB,6
btfsc 6Bh,0
bcf portB,7
call clock ;to advance 4017 to output "0"
call _500uS
rrf 60h,1
rrf 61h,1
rrf 62h,1
rrf 63h,1
rrf 64h,1
rrf 65h,1
rrf 66h,1
rrf 67h,1
rrf 68h,1
rrf 69h,1
rrf 6Ah,1
rrf 6Bh,1
decfsz ScanLoops,1
goto Scan+2
movlw 0ffh
movwf PortA ;prevents bright dot
movwf PortB ;prevents bright dot
retlw 00
Set4017 bsf status,rp0
movlw b'00100000' ;Set TRISA in for RA5
movwf 05h
bcf status,rp0
call clock
btfss 05h,5 ;see if 4017 is at 9th output
goto $-2
call clock
retlw 00 ;output "10" on 4017 HIGH = before start of scan
;to prevent anything appearing on screen
;detect switches & generates bit 1,2,3,4,5 in Sw_Flag file
Sw bsf status,rp0
bcf trisA,6 ;Make bit 6 output
bcf status,rp0
bsf portA,6 ;make bit 6 HIGH
call _1mS ;create delay to charge 100n
bsf status,rp0
bsf trisA,6 ;Make bit 6 input
bcf status,rp0
call _10mS
call _1mS
btfss portA,6 ;if set, no sw pushed
goto $+3 ;sw pushed
clrf Sw_Flag ;no sw pressed
retlw 00 ;
btfsc Sw_Flag,0 ;test "first-pass" sw flag
retlw 00
clrf count
bsf status,rp0
bcf trisA,6 ;Make bit 3 output
bcf status,rp0
bsf portA,6 ;make bit 3 HIGH
call _1mS ;create delay to charge 100n
bsf status,rp0
bsf trisA,6 ;Make bit 3 input
bcf status,rp0
call _1mS ;count until cap discharged
call _1mS
incf count,f
btfsc portA,6 ;is input HIGH?
goto $-4 ;count exits with 1-5
decfsz count,f
goto $+3
bsf Sw_Flag,1 ;set a flag-bit for first sw
retlw 00
decfsz count,f
goto $+3
bsf Sw_Flag,2 ;set a flag-bit for second sw
retlw 00
decfsz count,f
goto $+3
bsf Sw_Flag,3 ;set a flag-bit for third sw
retlw 00
decfsz count,f
goto $+3
bsf Sw_Flag,4 ;set a flag-bit for fourth sw
retlw 00
bsf Sw_Flag,5 ;set a flag-bit for fifth sw
retlw 00
;Sw1 increments data on display12
sw1 btfsc Sw_Flag,0 ;first pass? If no, return
retlw 00
bsf Sw_Flag,0 ;set sw flag (clr in Sw routine)
incf Jump_1,1 ;incr jump value
movf Jump_1,0 ;set-up jump value for table 1
call table1 ;get display data
movwf 5Bh ;display-12 holds the image to be incremented
xorlw 0FFh ;see if end of table 1
btfss 03,2
retlw 00
clrf 5Bh
clrf Jump_1
goto sw1+3
;Sw2 decrements data on display12
sw2 btfsc Sw_Flag,0 ;first pass? If no, return
retlw 00
bsf Sw_Flag,0 ;set sw flag (clr in Sw routine)
movf Jump_1,0
xorlw 1 ;see if start of table1 is reached
btfss 03,2
goto $+4
movlw 24h ;number of values in table1
movwf Jump_1
goto sw2
decf Jump_1,1 ;decr jump value
movf Jump_1,0 ;set-up jump value for table 1
call table1 ;get display data
movwf 5Bh ;display-12 holds the image to be incremented
retlw 00
;sw3 store
sw3 btfsc Sw_Flag,0 ;first pass? If no, return
retlw 00
bsf Sw_Flag,0 ;set sw flag (clr in Sw routine)
movlw 0Ah
movwf store ;.10 loops
movlw 50h ;start of display
movwf 04h ;load FSR
movf 00h,0 ;move value looked at by FSR into W
xorlw 00h ;see if display is empty
btfsc 03,2
goto $+5 ;display empty
incf 04h,1 ;display not empty
decfsz store,1
goto $-6
goto $+5 ;go to section that moves display left
movf Jump_1,0
call table1
movwf 00h
retlw 00
movf 40h,0 ;look at file 40h
xorlw 00h ;see if it is empty
btfss 03,2
retlw 00
movlw 1Ah
movwf store ;1Ah loops
movlw 40h ;start of block move
movwf 04h ;load FSR
movf 00h,0 ;move value looked at by FSR into W
decf 04h,1 ;decr fsr to 2Fh
movwf 00h ;put value into 2Fh
incf 04h,1
incf 04h,1
decfsz store,1
goto $-6
movf 5Bh,0 ;move character from 12th to 10th display
movwf 59h ;put value into 10th display
retlw 00
sw4 btfsc Sw_Flag,0 ;first pass? If no, return
retlw 00
bsf Sw_Flag,0 ;set sw flag (clr in Sw routine)
;movlw 1Ch ;not yet completed
;movwf 12h ;not yet completed
retlw 00
;RUN Runs characters across display
;files 60h-6Fh get destroyed after SCAN, so
;a 12-file wide window looks at 35h to 40h
;and transfers to 60h-6Bh for scan routine.
sw5 clrf 3Fh ;remove unwanted shifted data
clrf 5Bh ;remove unwanted data
movlw 35h ;start of Ghost files
movwf Ghost
movlw 60h ;window 60h-6Bh
movwf Window
movlw 20h ;creates shift timing
movwf RunLoops ;loops of scan
movf Ghost,0
movwf GhostTemp ;for incrementing
movf Window,0
movwf WindowTemp ;for incrementing
movlw 0Ch ;shift 12 bits of data
movwf _12loops ;12 loops
movf GhostTemp,0 ;look at first Ghost file
movwf fsr
movf 00h,0 ;move value looked at by FSR into W
movwf Save ;save it
movf WindowTemp,0 ;load first window file
movwf fsr ;put into pointer
movf Save,0
movwf 00h ;put value into 60h
incf GhostTemp,1
incf WindowTemp,1
decfsz _12loops,1
goto $-.11
call Set4017
call Scan
decfsz RunLoops,1
goto Sw5+8
incf Ghost,1
movf Ghost,0
xorlw 54h ;end of Ghost files? + spaces
btfss 03,2
goto Sw5+6
movf Sw_Flag,1
btfss 03,2
goto Sw5+2
retlw 00 ;Sw_Flag is empty so return to Attract
;Transfer the data in files 50h - 5Bh to 60h - 6Bh
Transfer
movlw 0Ch
movwf temp1 ;no of loops
movlw 50h ;start of 1st block
movwf 04h ;load FSR
movf 00h,0 ;move value looked at by FSR into W
bcf 04h,4
bsf 04h,5 ;turns FSR 50h to 60h
movwf 00h
bsf 04h,4
bcf 04h,5 ;turns FSR 60h to 50h
incf 04h,1
decfsz temp1,1
goto $-8
retlw 00
;************************************
;* Main *
;************************************
Main call Set4017
call Transfer
call Scan
call Sw ;see if a button has been pressed
movf Sw_Flag,1
btfsc 03,2 ;see if Sw_Flag is clear
goto Main
btfss Sw_Flag,1
goto $+3
call sw1 ;increment data for display12.
goto Main
btfss Sw_Flag,2
goto $+3
call sw2 ;decrement data for display12.
goto Main
btfss Sw_Flag,3
goto $+3
call sw3 ;store
goto Main
btfss Sw_Flag,4
goto $+3
call sw4 ;to the used for future effects
goto Main
btfsc Sw_Flag,5
goto sw5 ;RUN
goto Main
END |