📄 sio.asm
字号:
;-----------------------------------
ps2_command_45:
movlw 005ah ; ack
spi_transmit
call ADD_nop6 ; 1st byte :
movlw 0xc0 ; revision code
spi_transmit
call ADD_nop6 ; 2nd byte :
ifndef SLIDE_SW
movlw 0x40 ; no of mode can be set by software
else
clrw
endif
spi_transmit
call ADD_nop6 ; 3rd byte :
clrw ; present controller mode
btfsc D_A_mode
movlw 0x80
spi_transmit
call ADD_nop6 ; 4th byte :
movlw 0x40 ; no of actuator
spi_transmit
call ADD_nop6 ; 5th byte :
movlw 0x80 ; no of combination lists of actuator
spi_transmit
call ADD_nop6 ; 6th byte :
clrw ; must be 0
spi_transmit
goto end_SPI
;---------------------------------------------------------
; command = 46
; Actuator types and set parameter data length acquisition
;---------------------------------------------------------
ps2_command_46:
movlw 005ah ; ack
spi_transmit
call ADD_nop6
clrw ; 1st byte : must be 0
spi_transmit
bcf f_data1_is_0
btfsc STATUS,Z
bsf f_data1_is_0 ; received 1st byte = 0
bcf f_data1_is_1
xorlw 0x80
btfsc STATUS,Z
bsf f_data1_is_1 ; received 1st byte = 1
clrw ; 2nd byte : must be 0
spi_transmit
call ADD_nop6 ; 3rd byte :
movlw 0x80 ; actuator function classification
spi_transmit
clrw
btfsc f_data1_is_0
movlw 0x40
btfsc f_data1_is_1
movlw 0x80
; 4th byte :
spi_transmit ; actuator sub_divide class
clrw
btfsc f_data1_is_1
movlw 0x80
; 5th byte :
spi_transmit ; data length
call ADD_nop6
clrw ; 6th byte : current in 10mA
btfsc f_data1_is_0
movlw 0x50 ; 0x0a = 100mA
btfsc f_data1_is_1
movlw 0x28 ; 0x14 = 200mA
spi_transmit
goto end_SPI
;---------------------------------------------------
; command = 47
; Simultaneously operable actuator list acquisition.
;---------------------------------------------------
ps2_command_47:
movlw 005ah ; ack
spi_transmit
call ADD_nop6
clrw ; 1st byte : must be 0
spi_transmit
bcf f_data1_is_0
btfsc STATUS,Z
bsf f_data1_is_0 ; received 1st byte = 0
call ADD_nop6
clrw ; 2nd byte : must be 0
spi_transmit
call ADD_nop6
clrw
btfsc f_data1_is_0
movlw 0x40 ; 3rd byte : list length
spi_transmit
call ADD_nop6
clrw ; 4th byte : actuator 0
spi_transmit
call ADD_nop6
clrw
btfsc f_data1_is_0
movlw 0x80 ; 5th byte : actuator 1
spi_transmit
call ADD_nop6
clrw ; 6th byte : must be 0
spi_transmit
goto end_SPI
;----------------------------------
; command = 48
; Actuator status acquisition.
;----------------------------------
ps2_command_48:
movlw 005ah ; ack
spi_transmit
call ADD_nop6
clrw ; 1st byte : must be 0
spi_transmit
bcf f_data1_is_0
btfsc STATUS,Z
bsf f_data1_is_0 ; received 1st byte = 0
bcf f_data1_is_1
xorlw 0x80
btfsc STATUS,Z
bsf f_data1_is_1 ; received 1st byte = 1
clrw ; 2nd data : must be 0
spi_transmit
call ADD_nop6
clrw ; 3rd data : must be 0
spi_transmit
call ADD_nop6
clrw ; 4th data : must be 0
spi_transmit
movlw 0x80
btfss f_data1_is_0
goto send_48_5th_data
btfss f_data1_is_1
clrw
send_48_5th_data: ; 5th data : data length
spi_transmit
clrw
btfsc f_data1_is_0
clrw
; movf sm_cmd,W ; actuator 0
btfsc f_data1_is_1
clrw
; movf lm_cmd,W ; actuator 1
spi_transmit ; 6th byte : actuator parameter
goto end_SPI
;----------------------------------
; command = 49
; Setting actuator parameters.
;----------------------------------
ps2_command_49:
movlw 005ah ; ack
spi_transmit
call ADD_nop6
clrw ; 1st data : must be 0
spi_transmit
bcf f_data1_is_0
btfsc STATUS,Z
bsf f_data1_is_0 ; received 1st byte = 0
bcf f_data1_is_1
xorlw 0x80
btfsc STATUS,Z
bsf f_data1_is_1 ; received 1st byte = 1
call ADD_nop6
clrw ; 2nd data : must be 0
spi_transmit
call ADD_nop6
clrw ; 3rd data : must be 0
spi_transmit
btfsc f_data1_is_0
goto set_49_actuator0
btfss f_data1_is_1
goto send_49_4th_data
bsf STATUS,RP0
; movwf lm_buffer ; save to large motor buffer
bcf STATUS,RP0
goto send_49_4th_data
set_49_actuator0:
bsf STATUS,RP0
; movwf sm_buffer ; save to small motor buffer
bcf STATUS,RP0
send_49_4th_data:
clrw ; 4th data : must be 0
spi_transmit
call ADD_nop6
clrw ; 5th data : must be 0
spi_transmit
call ADD_nop6
clrw ; 6th data : must be 0
spi_transmit
goto end_SPI
;-----------------------------------------------------
; command = 4a
; Actuator parameter synchronous update mode ON/OFF,
; updating buffered actuator parameters synchronously.
;-----------------------------------------------------
ps2_command_4a:
movlw 005ah ; ack
spi_transmit
call ADD_nop6
clrw ; 1st data : must be 0
spi_transmit
bcf f_synchronous
btfsc STATUS,Z
goto send_4a_2nd_data ; Synchronous = OFF
xorlw 0x80
btfsc STATUS,Z
bsf f_synchronous ; Synchronous = ON
send_4a_2nd_data:
clrw ; 2nd data : must be 0
spi_transmit
call ADD_nop6
clrw ; 3rd data : must be 0
spi_transmit
call ADD_nop6
clrw ; 4th data : must be 0
spi_transmit
call ADD_nop6
clrw ; 5th data : must be 0
spi_transmit
call ADD_nop6
clrw ; 6th data : must be 0
spi_transmit
goto end_SPI
;----------------------------------
; command = 4b
; Communication continuation.
;----------------------------------
ps2_command_4b:
movlw 005ah ; ack
spi_transmit
call ADD_nop6
clrw ; 1st data
spi_transmit
call ADD_nop6
clrw ; 2nd data
spi_transmit
call ADD_nop6
clrw ; 3rd data
spi_transmit
call ADD_nop6
clrw ; 4th data
spi_transmit
call ADD_nop6
clrw ; 5th data
spi_transmit
call ADD_nop6
clrw ; 6th data
spi_transmit
goto end_SPI
;-----------------------------------------------
; command = 4c
; Acquisition of controller mode (controller ID)
; that can be set in terms of software.
;-----------------------------------------------
ps2_command_4c:
movlw 005ah ; ack
spi_transmit
call ADD_nop6
clrw ; 1st data : must be 0
spi_transmit
bcf f_data1_is_0
btfsc STATUS,Z
bsf f_data1_is_0 ; received 1st byte = 0
bcf f_data1_is_1
xorlw 0x80
btfsc STATUS,Z
bsf f_data1_is_1 ; received 1st byte = 1
clrw ; 2nd data : must be 0
spi_transmit
call ADD_nop6
clrw ; 3rd data : must be 0
spi_transmit
ifndef SLIDE_SW
clrw
btfsc f_data1_is_0
movlw 0x20 ; ID = 4
btfsc f_data1_is_1
movlw 0xe0 ; ID = 7
else
swapf pad_id,W
andlw 0xf0 ; set ID = pad_id
btfss f_data1_is_0
clrw
endif
spi_transmit ; 4th data : ID
call ADD_nop6
clrw ; 5th data : must be 0
spi_transmit
call ADD_nop6
clrw ; 6th data : must be 0
spi_transmit
goto end_SPI
;-------------------------------------------
; command = 4d
; Setting actuator parameter alignment to be
; sent at button acquisition.
;-------------------------------------------
ps2_command_4d:
movlw 005ah ; ack
spi_transmit
btfsc D_A_mode ; if anlog mode, always x3
goto com_4d_send_1st
movf pad_id,W
andlw 0x0f
iorlw 0x80
movwf pad_id ; set default pad_id = x1
com_4d_send_1st:
bsf STATUS,RP0
movf pre_data1,W
bcf STATUS,RP0
spi_transmit ; 1st data : previous data1
bsf STATUS,RP0
movwf pre_data1 ; save data1
movf pre_data2,W
bcf STATUS,RP0
spi_transmit ; 2nd data : previous data2
bsf STATUS,RP0
movwf pre_data2 ; save data2
movf pre_data3,W
bcf STATUS,RP0
spi_transmit ; 3rd data : previous data3
btfss D_A_mode ; if anlog mode, always x3
call check_if_4d_x2
com_4d_send_3rd:
bsf STATUS,RP0
movwf pre_data3 ; save data3
movf pre_data4,W
bcf STATUS,RP0
spi_transmit ; 4th data : previous data4
btfss D_A_mode ; if analog mode, always x3
call check_if_4d_x2
com_4d_send_4th:
bsf STATUS,RP0
movwf pre_data4 ; save data4
movf pre_data5,W
bcf STATUS,RP0
spi_transmit ; 5th data : previous data5
btfss D_A_mode ; if anlog mode, always x3
call check_if_4d_x3
com_4d_send_5th:
bsf STATUS,RP0
movwf pre_data5 ; save data5
movf pre_data6,W
bcf STATUS,RP0
spi_transmit ; 6th data : previous data6
bsf STATUS,RP0
movwf pre_data6 ; save data6
bcf STATUS,RP0
btfss D_A_mode ; if analog mode, always x3
call check_if_4d_x3
end_of_com_4d:
goto end_SPI
;----------------------------------
; command = 4e
; Reserved
;----------------------------------
ps2_command_4e:
movlw 005ah ; ack
spi_transmit
bsf STATUS,RP0
movf data1_4f,W
bcf STATUS,RP0
spi_transmit ; 1st data
bsf STATUS,RP0
movf data2_4f,W
bcf STATUS,RP0
spi_transmit ; 2nd data
bsf STATUS,RP0
movf data3_4f,W
bcf STATUS,RP0
spi_transmit ; 3rd data
call ADD_nop6
clrw ; 4th data
spi_transmit
call ADD_nop6
clrw ; 5th data
spi_transmit
call ADD_nop6
movlw 0x5a ; 6th data
spi_transmit
goto end_SPI
;----------------------------------
; command = 4f
; Reserved
;----------------------------------
ps2_command_4f:
movlw 005ah ; ack
spi_transmit
bcf f_sio_ack
bcf f_4f_all_0
call ADD_nop6
clrw ; 1st data
spi_transmit
btfss STATUS,Z
bsf f_4f_all_0
bsf STATUS,RP0
movwf sio_tmp1
bcf STATUS,RP0
clrw ; 2nd data
spi_transmit
btfss STATUS,Z
bsf f_4f_all_0
bsf STATUS,RP0
movwf sio_tmp2
bcf STATUS,RP0
clrw ; 3rd data
spi_transmit
btfss STATUS,Z
bsf f_4f_all_0
bsf STATUS,RP0
movwf sio_tmp3
bcf STATUS,RP0
andlw 0x3f
btfss STATUS,Z
bsf f_sio_ack
com_4f_4th:
clrw ; 4th data
spi_transmit
btfss STATUS,Z
bsf f_sio_ack
call ADD_nop6
clrw ; 5th data
spi_transmit
btfss STATUS,Z
bsf f_sio_ack
clrw ; 6th data
btfss D_A_mode
goto com_4f_6th
btfss f_4f_all_0 ; if all zero ?
bsf f_sio_ack
movlw 0x5a
btfsc f_sio_ack
movlw 0xff
com_4f_6th:
spi_transmit
btfss D_A_mode
goto end_com_4f
btfsc f_sio_ack
goto end_com_4f
movlw 0x0f
andwf pad_id,F
bsf STATUS,RP0
movf sio_tmp1,W
movwf data1_4f
movf sio_tmp2,W
movwf data2_4f
movf sio_tmp3,W
movwf data3_4f
clrf sio_tmp1
movlw d'25'
movwf sio_tmp2
bcf STATUS,C
sio_4f_count:
rlf data3_4f,F
rlf data2_4f,F
rlf data1_4f,F
btfsc STATUS,C
incf sio_tmp1,F
decfsz sio_tmp2,F
goto sio_4f_count
incf sio_tmp1,F
bcf STATUS,C
rrf sio_tmp1,F
movlw 0x08
movwf sio_tmp2
bcf STATUS,C
sio_4f_reverse:
rrf sio_tmp1,F
rlf sio_tmp3,F
decfsz sio_tmp2,F
goto sio_4f_reverse
movf sio_tmp3,W
andlw 0xf0
bcf STATUS,RP0
iorwf pad_id,F ; 7x
end_com_4f:
goto end_SPI
;-------------------------------
; common interrupt-exit
;-------------------------------
end_SPI:
bcf SSPCON,WCOL
bsf STATUS,RP0 ; bank -> 1
clrf m_reset ; reset mode flag
bsf TRIS_SDO ; SDO -> input
bsf TRIS_DSR ; DSR -> input
bcf STATUS,RP0 ; bank -> 0
bcf SSPCON,SSPEN ; disable SSP
bsf DSR ; high DSR
bcf SSPCON,WCOL
; bsf f_siointr
movf pclath_save,W ; restore
movwf PCLATH
movf fsr_save,W
movwf FSR
swapf status_save,W
movwf STATUS
swapf w_save,F ; restore W
swapf w_save,W
retfie
;-----------------------------------------------
; spi_comm:
; description : this routine send the DSR pulse,
; and start the TX/RX.
; input : put the TX data in W,
; output: the RX data will be placed in W.
; C will set if DTR high.
;-----------------------------------------------
spi_comm:
movwf SSPBUF
bcf PIR1,SSPIF
DSR_shot
wait_spi_data:
btfsc DTR ; DTR high?
goto exit_dtr ; Yes
btfss PIR1,SSPIF ; data received?
goto wait_spi_data ; No
bcf SSPCON,WCOL
bcf STATUS,C
goto end_spi_transmit
exit_dtr:
bsf STATUS,C
end_spi_transmit:
movf SSPBUF,W
return
;-----------------------------------------------------
; save_motor_data:
; description: check if the large/small motor
; data is received in this data (in command 42),
; which is set the location in 4d.
; input : pre_data of 4d place into W.
; output : sm_cmd or lm_cmd.
;-----------------------------------------------------
save_motor_data:
btfss STATUS,Z
goto not_small_data
movf SSPBUF,W
; movwf sm_cmd
goto end_of_save_motor_data
not_small_data:
xorlw 0x80
btfss STATUS,Z
goto end_of_save_motor_data
movf SSPBUF,W
; movwf lm_cmd
end_of_save_motor_data:
return
;----------------------------------------------
; check_if_4d_x2
; check if pad id is x2 in button report mode.
; used by command 4d's 3rd & 4th bytes.
;----------------------------------------------
check_if_4d_x2:
btfsc STATUS,Z ; 0 ?
goto pad_id_is_x2
xorlw 0x80
btfss STATUS,Z
goto pad_id_x2_get_ssp
pad_id_is_x2:
movf pad_id,W
andlw 0x0f
iorlw 0x40
movwf pad_id ; set pad_id = x2
pad_id_x2_get_ssp:
movf SSPBUF,W
return
;----------------------------------------------
; check_if_4d_x3
; check if pad id is x3 in button report mode.
; used by command 4d's 5th & 6th bytes.
;----------------------------------------------
check_if_4d_x3:
btfsc STATUS,Z ; 0 ?
goto pad_id_is_x3
xorlw 0x80
btfss STATUS,Z
goto pad_id_x3_get_ssp
pad_id_is_x3:
movf pad_id,W
andlw 0x0f
iorlw 0xc0
movwf pad_id ; set pad_id = x3
pad_id_x3_get_ssp:
movf SSPBUF,W
return
;-----------------------------------
;ADD_nop6:
; add 6 nop for delay
;-----------------------------------
ADD_nop6:
nop
nop
nop
nop
nop
nop
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -