📄 f.txt
字号:
;
; Motion commands. +X=north, -X=south; +Y=east, -Y=west.
; These save the command just executed (C) in CMD.
;
_south movlw 255 ; add -1 to LS byte,
addwf _Ylo
btfss C ; if (no) carry,
decf _Yhi ; decrement MS byte,
movlw 3 ; bound to 10 bits
andwf _Yhi, f
goto _movret
_north incf _Ylo ; increment low byte,
btfsc Z
incf _Yhi ; increment high if lo=0
goto _movret
_east incf _Xlo
btfsc Z
incf _Xhi
goto _movret
_west movlw 255 ; add -1 to LS byte,
addwf _Xlo
btfss C ; if (no) carry,
decf _Xhi ; decrement MS byte,
movlw 3 ; bound to 10 bits
andwf _Xhi, f
goto _movret
_ne incf _Ylo ; do north
btfsc Z
incf _Yhi
incf _Xlo ; then east
btfsc Z
incf _Xhi
goto _movret
_se incf _Xlo ; do east
btfsc Z
incf _Xhi
movlw 255 ; then south
addwf _Ylo
btfss C
decf _Yhi
movlw 3
andwf _Yhi, f
goto _movret
_nw incf _Ylo
btfsc Z
incf _Yhi
movlw 255
addwf _Xlo
btfss C
decf _Xhi
movlw 3
andwf _Xhi, f
goto _movret
_sw movlw 255 ; do south
addwf _Ylo
btfss C
decf _Yhi
movlw 3
andwf _Yhi, f
movlw 255
addwf _Xlo
btfss C
decf _Xhi
movlw 3
andwf _Xhi, f
;
; Move the DACs to the new position, save the current
; command for a possible later repeat, and execute
; the step delay, if set.
;
_movret movf _C, w ; save command
movwf _CMD ; for later repeat,
call _outDAC ; make the plotter move,
; movf _stepd, w ; delay time,
; iorwf 0 ; if a step delay is set,
; btfss Z ;
; goto pause@0W ; delay for servo.
goto done
;
; Serial input routines. These build upon the library routines that
; come with the compiler. All routines deassert CTS when a character
; is received (since we have no buffer).
;
; Assert CTS, wait for a character.
_serinw call _serinp ; assert CTS, check for char,
btfss _serflag, 0 ; if serflag LSB = 0,
goto _serinw ; keep waiting.
return
; Assert CTS, check for a character by seeing if a start
; bit is present; if so, drop CTS, receive the character
; into C, set serflag.
_serinp bcf _serflag, 0 ; clear serflag,
bsf portB, _CTS ; assert CTS,
btfss portB, _RXD ; if Rx bit false
goto done ; return, no char avail.
call serin@W ; else read the char,
bcf portB, _CTS ; deassert CTS,
movwf _C ; store char in C,
bsf _serflag, 0 ; set serflag= 1.
goto done
; Initialize the serial input routine; pass the Rx pin to the
; PIC library routine, deassert CTS, clear our flag and return.
_serini bcf portB, _CTS ; deassert CTS,
movlw _RXD ; Rx pin number,
call BP@Pin
movlw _SPEED ; port speed,
movwf GOP ; (local to ass'y code?)
clrf _serflag ; set serflag to zero.
goto done
; Output X and Y to the DACs. Refer to the MAX504 datasheet; each chip,
; wired in series, wants 16 bits total; four 0-fill bits, 10 data bits,
; two dummy LSBs, two trailing bits to round to 16. The dummy LSBs for
; X and the leading 0's for Y are output in one call.
;
; Modifies J, I.
;
_outDAC bcf portB, _DACCS ; assert DAC /CS,
movf _Xhi, w
movwf _J ; X MSBs to J, upper bits 0's,
rlf _J
rlf _J ; now four 0's precede X MSBs,
movlw 6 ; 4 fill + 2 data,
call _outJ ; output those,
movf _Xlo, w
movwf _J
movlw 8
call _outJ ; output 8 LSBs,
; The X DAC still needs two dummy LSBs; we'll output them
; when we issue Y MSBs.
movf _Yhi, w
movwf _J ; Y MSBs to J, upper bits 0's,
movlw 8
call _outJ ; output 2 dummy LSBs, 4 fill, 2 data,
movf _Ylo, w
movwf _J
movlw 8
call _outJ ; output 8 Y LSBs,
clrf _J
movlw 2 ; now final 2 dummy LSBs.
call _outJ
bsf portB, _DACCS ; deassert /CS
goto done
;
; Output (reg. W) bits of (J) to the DAC, starting
; with the MSB.
; Modifies I, J.
;
_outJ movwf _I ; loop counter,
_ok bcf portB, _SD ; data=0...
rlf _J ; (move MSB to carry to test)
btfsc status, 0 ; ...unless MSB is 1...
bsf portB, _SD ; ...data=1.
bsf portB, _DACCLK
bcf portB, _DACCLK ; clock it
decfsz _I
goto _ok
goto done
;
; Disable all output devices as quickly as possible; remove
; drive from the solenoids and output 0V at the DACs. This
; could be done by the slower but more general:
;
; solenoids= 0 : call _out
; X= 0 : Y= 0 : call outDAC
;
; And could be dispensed with if space gets tight.
;
; Modifies J, K.
;
_clrhw bcf portB, _PEN ; lift the plotter pen,
bsf portB, _SD ; 1=no sol drive
bcf portB, _DACCS ; assert DAC /CS
movlw 8
movwf _J ; for 1st loop,
movlw 24
movwf _K ; for 2nd loop,
; This loop clears SRA, SRB and the 1st 8 bits of the DACs.
_ca1 bsf portB, _SD ; 1=no sol. drive,
bsf portB, _SRA ; clock both SRs
bcf portB, _SRA
bsf portB, _SRB ; at once,
bcf portB, _SRB
bcf portB, _SD ; 0= no DAC output,
bsf portB, _DACCLK ; clock DACs,
bcf portB, _DACCLK
decfsz _J
goto _ca1
; Clear the remaining bits of the DACs.
_ca2 bsf portB, _DACCLK
bcf portB, _DACCLK
decfsz _K ; loop count K set at top.
goto _ca2
bsf portB, _DACCS ; deassert DAC /CS
goto done
;
; Outputs the solenoid bits to ports A and B. Solenoid
; bits must be inverted, since the 2003's drive OC drivers.
; Outputs Wlo to the A outputs and Whi to the B outputs.
; A0-A7, B0-B1 are calc solenoids; B2-B7 are lamps, etc.
; Modifies K, J.
;
_out comf _Wlo, w ; Wlo inverted --> W,
movwf _K ; put in temp,
movlw 8
movwf _J ; set bit loop counter,
_oa1 bcf portB, _SD ; set data bit= 0
rlf _K ; move MSB to carry,
btfsc status, 0 ; if carry set (MSB == 1)
bsf portB, _SD ; assert a 1,
bsf portB, _SRA ; clock data bit out,
bcf portB, _SRA
decfsz _J ; repeat.
goto _oa1
; Same as above, but outputs MS solenoid bits plus lamps.
; This is also a faster entry point for outputting the
; lamp bits only; it requires that Whi be cleared, which
; it will be whenever the calculator is not actively
; operating.
;
_outB comf _Whi, w ; Whi inverted --> W,
andlw _LAMPM ; clear lamp bits,
iorwf _lamps, w ; add in lamps,
movwf _K ; store in temp,
movlw 8 ; otherwise
movwf _J ; yup, pretty much
_ob1 bcf portB, _SD ; the same thing
rlf _K ; as above.
btfsc status, 0 ; figure it out.
bsf portB, _SD
bsf portB, _SRB
bcf portB, _SRB
decfsz _J
goto _ob1
goto done
;
; Initialize PA3 as an output, PA4 as an input.
;
_PAinit movf 133, w ; read (WHAT)?
iorlw 16 ; PA3 is input,
andlw 247 ; PA4 is output,
movwf 133 ; write reg.
return
;
; Set PA3 on and off.
;
_PA3lo movf 5, w ; read PA
andlw 247 ; clear PA3
movwf 5
return
_PA3hi movf 5, w ; read PA
iorlw 8 ; set PA3
movwf 5
return
;
; Return in N the state of PA4 (0 or 1).
;
_PA4in movf 5, w ; read PA,
andlw 16 ; mask it off,
movwf _N ; store in N,
rrf _N
rrf _N
rrf _N
rrf _N ; shift to bit 0
return
endasm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -