Part #2 of 2 of the code (the same file)
; ***** RIGHT SCANNING DISPLAY
; --- blank display and check for direction change from left to right
waitforright clrf PORTB ; blank display after stop-pos
btfss PORTA,1 ; check if right-swing is registered
goto waitforright
endlscan movf TMR0,W
movwf scantime ; new scantime (or rather, the one just finished..)
rscaninit clrf TMR0 ; clear timer
clrf PORTB ; Initially clear display
clrf scanpos
clrf row
clrf nextrtime
; TEST *****
bcf PORTA,2
bcf PORTA,3 ;Set / Clear display during this scan
movf totsize,W
movwf divident
movf scantime,W
movwf value
call divide ; subcounter = scantime / totsize
movf subcounter,W
movwf rowtime ; find time allowed pr. row
movwf nextrtime ; set initial delay
rscan movf nextrtime,W
subwf TMR0,W ; W = TMR0 - nextrtime
btfsc STATUS,C ; skip if nextrtime < TMR0
goto rrowdisp
btfss PORTA,0 ; check if left-swing is registered (END R-SCAN)
goto rscan
goto endrscan
rrowdisp incf scanpos,F ; next row abs. position
movf rowtime,W
addwf nextrtime,F ; next row time-start in TMR0-steps
movf delay,W
subwf scanpos,W ; W = scanpos - delay
btfss STATUS,C ; skip if scanpos > delay
goto rscan
movf stopdisp,W
subwf scanpos,W ; W = scanpos - stopdisp
btfsc STATUS,C ; skip if stopdisp > scanpos
goto waitforleft
;-- read EEPROM
bcf STATUS,RP0
movf row,W
movwf EEADR
bsf STATUS,RP0
bsf EECON1,RD ;initiate read
bcf STATUS,RP0
movf EEDATA,W
movwf PORTB ; Display it..
;--
incf row,F ; next row pointer
goto rscan
; ***** LEFT SCANNING DISPLAY
; --- blank display and check for direction change from right to left
waitforleft clrf PORTB ; blank display after stop-pos
btfss PORTA,0 ; check if left-swing is registered
goto waitforleft
endrscan movf TMR0,W ; Direction-change detected
movwf scantime ; new scantime (or rather, the one just finished..)
lscaninit clrf TMR0 ; clear timer
clrf PORTB ; Initially clear display
clrf nextrtime
clrf scanpos
; TEST *****
bsf PORTA,2
bcf PORTA,3 ;Set / Clear display during this scan
movf matrixsize,W
movwf row
decf row,F ; initial row-nr backwards
movf totsize,W
movwf divident
movf scantime,W
movwf value
call divide ; scantime / totsize
movf subcounter,W
movwf rowtime ; find time allowed pr. row
movwf nextrtime ; set initial delay
lscan movf nextrtime,W
subwf TMR0,W ; W = TMR0 - nextrtime
btfsc STATUS,C ; skip if nextrtime < TMR0
goto lrowdisp
btfss PORTA,1 ; check if right-swing is registered (END L-SCAN)
goto lscan
goto endlscan
lrowdisp incf scanpos,F ; next row abs. position
movf rowtime,W
addwf nextrtime,F ; next row time-start in TMR0-steps
movf delay,W
subwf scanpos,W ; W = scanpos - delay
btfss STATUS,C ; skip if scanpos > delay
goto lscan
movf stopdisp,W
subwf scanpos,W ; W = scanpos - stopdisp
btfsc STATUS,C ; skip if stopdisp > scanpos
goto waitforright
;-- read EEPROM
bcf STATUS,RP0
movf row,W
movwf EEADR
bsf STATUS,RP0
bsf EECON1,RD ;initiate read
bcf STATUS,RP0
movf EEDATA,W
movwf PORTB ; Display it..
;--
decf row,F ; next row pointer backwards
goto lscan
; ********************** SUB ROUTINES ********************************
; --- un-accurate division, answear is within + 1 / - 0 or something
; of correct answear, all integers if course...
divide movlw 0x00
movwf subcounter ;clear answear
movf divident,W
btfsc STATUS,Z ;check for divide-by-zero
goto divideby0
subloop movf divident,W
subwf value,W ; W = value - divident
btfss STATUS,C ; did a borrow occur?
RETURN ; yes, value < divident, answear is OK..
movwf value
incf subcounter,F
goto subloop
divideby0 incf subcounter,F ; here, div-by-zero equals 1 :-)
RETURN ; dont know why, but it feels good
; --- Time-waist routine
timerwait movlw 0x00
movwf TMR0 ; clear timer
tloop movf TMR0,W
subwf wait,W ; W = wait - timer
btfss STATUS,Z ; W = 0 ?
goto tloop ; no, wait more
RETURN
END ; directive 'end of program'