include "P12F509.INC"
__config _IntRC_OSC & _WDT_OFF & _MCLRE_ON
D equ 0
CP equ 1
cblock 0x07
d1,d2,d3,count,count2,patlen,patrep,temp,anode,offset,fsr1,frames,cathptr
plex,cath1a,cath1b,cath2a,cath2b,cath3a,cath3b,cath4a,cath4b
endc
org 0x000
goto init
patt1 addwf PCL,f
retlw 0x04 ;pattern length - # of frames
retlw 0x0a ;# of reps
retlw 0xf0
retlw 0x00
retlw 0xf0
retlw 0x00
retlw 0xf0
retlw 0x00
retlw 0xf0
retlw 0x00
retlw 0x11
retlw 0x11
retlw 0x11
retlw 0x11
retlw 0x11
retlw 0x11
retlw 0x11
retlw 0x11
retlw 0x00
retlw 0x0f
retlw 0x00
retlw 0x0f
retlw 0x00
retlw 0x0f
retlw 0x00
retlw 0x0f
retlw 0x88
retlw 0x88
retlw 0x88
retlw 0x88
retlw 0x88
retlw 0x88
retlw 0x88
retlw 0x88
patt2 addwf PCL,f
retlw 0x04 ;pattern length - # of frames
retlw 0x0a ;# of reps
retlw 0xf0
retlw 0x00
retlw 0xf0
retlw 0x00
retlw 0xf0
retlw 0x00
retlw 0xf0
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0xff
retlw 0xff
retlw 0x00
retlw 0x0f
retlw 0x00
retlw 0x0f
retlw 0x00
retlw 0x0f
retlw 0x00
retlw 0x0f
retlw 0xff
retlw 0xff
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
retlw 0x00
init movlw b'11001000' ;clear T0CS for output on GPIO2
option
movlw b'00001000' ;set pins to all outs
tris GPIO
clrf GPIO ;zero all pins
movlw 0x08 ;set start level
movwf anode
movlw cathptr ;set cathode pointer
movwf cathptr
clrf plex
bcf GPIO,D ;init MM5451
nop
bsf GPIO,CP
nop
bcf GPIO,CP
main call horiz
call vert
goto main
horiz clrf offset ;point to start of table
movf offset,w ;get pattern length
call patt1
movwf patlen
incf offset,f ;get # of reps
movf offset,w
call patt1
movwf patrep
incf offset,f
horiz1 call isr ;multiplex 256 times
decfsz plex,f
goto horiz1
anim movlw 0x08 ;set bytes per frame counter - 8 bytes
movwf count
movlw cath1a ;cathode pointer storage
movwf FSR
mloop movf offset,w ;get a byte of new pattern
call patt1
movwf INDF
incf offset,f ;increment pointers
incf FSR,f
decfsz count,f ;frame done?
goto mloop
decfsz patlen,f ;pattern done?
goto horiz1
reset movlw 0x02 ;point to start of frames in table
movwf offset
decfsz patrep,f ;# of reps complete?
goto horiz2 ;no, fix patlen and go again
goto bail ;yes, done
horiz2 movlw 0 ;get patlen again
call patt1
movwf patlen
goto horiz1
bail retlw 0
vert clrf offset ;point to start of table
movf offset,w ;get pattern length
call patt2
movwf patlen
incf offset,f ;get # of reps
movf offset,w
call patt2
movwf patrep
incf offset,f
vert1 call isr ;multiplex 256 times
decfsz plex,f
goto vert1
vtanim movlw 0x08 ;set bytes per frame counter - 8 bytes
movwf count
movlw cath1a ;cathode pointer storage
movwf FSR
vtloop movf offset,w ;get a byte of new pattern
call patt2
movwf INDF
incf offset,f ;increment pointers
incf FSR,f
decfsz count,f ;frame done?
goto vtloop
decfsz patlen,f ;pattern done?
goto vert1
vtrst movlw 0x02 ;point to start of frames in table
movwf offset
decfsz patrep,f ;# of reps complete?
goto vert2 ;no, fix patlen and go again
goto vtbail ;yes, done
vert2 movlw 0 ;get patlen again
call patt2
movwf patlen
goto vert1
vtbail retlw 0
;***************************
;"interrupt" service routine
isr rlf anode,f ;change to next level
movlw 2 ;increment cathode pointer
addwf cathptr,f
movlw 0x10 ;is anode > 0x08?
subwf anode,w
btfss STATUS,Z
goto shift ;no, go ahead
movlw 1 ;yes, reset to anode 1
movwf anode
movlw cath1b ;and reset cathode pointer
movwf cathptr
shift movf cathptr,w ;load FSR
movwf FSR
bsf GPIO,D ;shift out start bit
nop
bsf GPIO,CP
nop
bcf GPIO,CP
movlw 0x02 ;set byte counter
movwf count2
shift5 movlw 0x08 ;set loop counter
movwf count
movf INDF,w ;get a byte
movwf temp
shift1 rrf temp,f ;rotate ms-bit into carry
btfsc STATUS,C ;is it 0?
goto shift2 ;no, shift out a 1
goto shift3 ;yes, shift out a 0
shift2 bsf GPIO,D
nop
bsf GPIO,CP ;blip clock
nop
bcf GPIO,CP
goto shift4
shift3 bcf GPIO,D
nop
bsf GPIO,CP ;blip clock
nop
bcf GPIO,CP
shift4 decfsz count,f ;done 8-bits?
goto shift1 ;no, go again
decfsz count2,f
goto shift6
goto shanode ;done cathodes - go do anode
shift6 decf FSR,f
goto shift5
shanode movlw 0x08 ;shift out anode byte
movwf count
movf anode,w
movwf temp
shan1 rrf temp,f
btfsc STATUS,C
goto shan2
goto shan3
shan2 bsf GPIO,D
nop
bsf GPIO,CP
nop
bcf GPIO,CP
goto shan4
shan3 bcf GPIO,D
nop
bsf GPIO,CP
nop
bcf GPIO,CP
shan4 decfsz count,f
goto shan1
last3 movlw 0x0b ;shift out last 11 bits
movwf count
l3loop bcf GPIO,D
nop
bsf GPIO,CP
nop
bcf GPIO,CP
decfsz count,f
goto l3loop
retlw 0
end