Code addendum:
So, here it is... don't do step 5 from my previous code post
Do step 1 through 4. And do step 6
![Smiley :)](https://www.eevblog.com/forum/Smileys/default/smiley.gif)
.
And you will get a error because I added a few lines of code to page 400f-600f. And this pushed "dummy" across a half page boundary. So to fix it, I have reclaimed 4 lines of code with these changes.
1.
timeout1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; incf counter_lo,f
; btfss status,zer
incfsz counter_lo,f ;saves one line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
goto timend
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; decf counter_hi,f
; btfss status,zer
decfsz counter_hi,f ;saves one line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
goto timend
bcf mode_byte,7
bcf mode_byte,0
bsf mode_byte,5 ; incf/decf affect status Z. But...
timend retlw 00 ; incfsz doesn't affect status,Z. But timeout1 is called from extimeout, and I see no checks of Z after the return. So I think it's ok.
2.
sequence1
bsf counter_lo,7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; incf counter_lo,f
; btfss status,zer
incfsz counter_lo,f ;save one line of code. against have to figure out is status,Z is importance after the return. So maybe ok.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
goto sequend
incf counter_hi,f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;insert this code
movlw .1 ;this is the 3 lines I added in the previous post
btfsc counter_hi,4
xorwf new_byte,f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bcf counter_hi,4 ;this must go back to the original bcf counter_hi,4
movf credit_count,f
btfsc status,zer
goto sequend
bcf mode_byte,7
bcf mode_byte,5
bsf mode_byte,0
sequend retlw 00 ;sequence1 is a branch from sequence, and this is called from exsequence,
; and I see no checks of Z after this return. So I think it's fine that incfsz doesn't affect Z like incf does.
3.
start3
clrf fsr
bcf mode_byte,0
bsf mode_byte,1
bcf portC,2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; clrw
; movwf counter_hi
; movwf counter_lo
clrf counter_hi ;save 1 line
clrf counter_lo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bcf function_byte,7
starend retlw 00 ;and retlw 00 loads 0 in W register. So clrw should not be missed for this reason. RETLW doesn't affect status Z;
;the clrw instruction sets Z bit. But... clrf also sets Z. So absolutely no worries on this one.
These changes bring "dummy" subroutine back to 0x4FE in program memory to stay on the same page as it is supposed to be, which I believe is page 2 (starting from 0). So now we have room for one more line of additional code in the future!!!
![Phew :phew:](https://www.eevblog.com/forum/Smileys/default/phew.gif)
Also, I chanced upon STATUS, <6,5> are how pages are selected, and pages are 512 "words" which is simply more confusing to me. So yes, pages have to be selected, and it will be nice to keep everything on the page it started with, esp if you are a hack like me that can't figure out this nonsense. (Took me long enough to figure out the midrange).