⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sio.asm

📁 VCP201_CODE is a FPGA source code.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	
        call	ADD_nop6	; 5th byte :
	movlw	0x01		; 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:
	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	0x01
	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	0x01		; actuator function classification "1"
	spi_transmit

	clrw
	btfsc	f_data1_is_0
	movlw	0x02
	btfsc	f_data1_is_1
	movlw	0x01	
				; 4th byte :
	spi_transmit		; actuator sub_divide class
        
	clrw
	btfsc	f_data1_is_1
	movlw	0x01
	        		; 5th byte :
	spi_transmit		; data length
	
	call	ADD_nop6
	clrw			; 6th byte : current in 10mA
	btfsc	f_data1_is_0
	movlw	0x0a		; 0x0a = 100mA
	btfsc	f_data1_is_1
	movlw	0x14		; 0x14 = 200mA
	spi_transmit       

	goto	end_SPI

;---------------------------------------------------
; command = 47
; Simultaneously operable actuator list acquisition.
;---------------------------------------------------
ps2_command_47:
	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	0x02		; 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	0x01		; 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:
	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	0x01
	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	0x01
	btfsc	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
	bsf	STATUS,RP0
	movf	sm_cmd,W	; actuator 0
	bcf	STATUS,RP0
	
	btfsc	f_data1_is_1
	clrw
	bsf	STATUS,RP0
	movf	lm_cmd,W	; actuator 1
	bcf	STATUS,RP0
	
	spi_transmit    	; 6th byte : actuator parameter

	goto	end_SPI
		

;-------------------------------------------
; command = 49
; Setting actuator parameters.
;----------------------------------
ps2_command_49:
	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	0x01
	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:
	goto	com_4b_send_4th	

;        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:
	clrw			; 1st data : must be 0
	spi_transmit

	bcf	f_synchronous
	btfsc	STATUS,Z
	goto	send_4a_2nd_data ; Synchronous = OFF
	xorlw	0x01
	btfsc	STATUS,Z
	bsf	f_synchronous	; Synchronous = ON
	
send_4a_2nd_data:
	goto	com_4b_send_2nd

;	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:
	clrw			; 1st data
	spi_transmit
	
	call	ADD_nop6
com_4b_send_2nd:
	clrw			; 2nd data
	spi_transmit
	
        call	ADD_nop6
com_4b_send_3rd:
	clrw			; 3rd data
	spi_transmit
	
	call	ADD_nop6
com_4b_send_4th:
        clrw			; 4th data
	spi_transmit
	
        call	ADD_nop6
com_4b_send_5th:
	clrw			; 5th data
	spi_transmit
	
	call	ADD_nop6
com_4b_send_6th:
	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:
	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	0x01
	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
	
        clrw
        btfsc	f_data1_is_0
        movlw	0x04		; ID = 4
        btfsc	f_data1_is_1
        movlw	0x07		; ID = 7

	spi_transmit		; 4th data : ID
	
        call	ADD_nop6
	goto	com_4b_send_5th
	
;	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:
	btfsc	D_A_mode	; if anlog mode, always x3
	goto	com_4d_send_1st
	
	movf	pad_id,W
	andlw	0xf0
	iorlw	0x01
	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:
	btfss	D_A_mode
	goto	ps2_command_4b
		
	bsf	STATUS,RP0
	movf	data1_4f,W
	bcf	STATUS,RP0
	spi_transmit		; 1st data
	
	bsf	STATUS,RP0
	movf	data2_4f_t,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:
	btfss	D_A_mode
	goto	ps2_command_4b

	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	0xfc
	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	0xf0
	andwf	pad_id,F
	
	bsf	STATUS,RP0
	movf	sio_tmp1,W
	movwf	data1_4f
	movf	sio_tmp2,W
	movwf	data2_4f
        movwf	data2_4f_t
	movf	sio_tmp3,W
	movwf	data3_4f

	clrf	sio_tmp1
	movlw	d'25'	;xxxxxxxxx
	movwf	sio_tmp2
	bcf	STATUS,C

sio_4f_count:
	rrf	data3_4f,F
	rrf	data2_4f,F
	rrf	data1_4f,F
	btfsc	STATUS,C
	incf	sio_tmp1,F
	decfsz	sio_tmp2,F
	goto	sio_4f_count
	
	incf	sio_tmp1,F	;(sio_temp+1)/2
	bcf	STATUS,C
	rrf	sio_tmp1,W

	andlw	0x0f

	bcf	STATUS,RP0
	iorwf	pad_id,F	; 7x	


	bsf	STATUS,RP0
	movf	data2_4f,W
        movwf   sio_tmp1
        movlw   0x08
        movwf   sio_tmp2
rev1:
        rrf     sio_tmp1,F
        rlf     sio_tmp3,F
        decfsz  sio_tmp2,F
        goto    rev1
        movf    sio_tmp3,W
	movwf	data2_4f
	bcf	STATUS,RP0

end_com_4f:
	goto	end_SPI

;-------------------------------
; common interrupt-exit
;-------------------------------
end_SPI:
	bsf     STATUS,RP0      ; bank -> 1
	clrf	m_reset		; reset mode flag
	bcf     STATUS,RP0      ; bank -> 0
	
	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   sdo
      	clrf	dsr
        call	Add_nop6

wait_spi_data:
	btfsc	scist,DTRB
	goto    exit_dtr        ; Yes
	btfss   scist,TBF	; data received?
	goto    wait_spi_data  	; No

	bcf	STATUS,C
	goto	end_spi_transmit
	
exit_dtr:
	bsf	STATUS,C
end_spi_transmit:
        movf    sdi,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	sdi,W
	bsf	STATUS,RP0
	movwf	sm_cmd
	goto	end_of_save_motor_data
not_small_data:
	xorlw	0x01
	btfss	STATUS,Z
	goto	end_of_save_motor_data
	movf	sdi,W
	bsf	STATUS,RP0
	movwf	lm_cmd
        
end_of_save_motor_data:
	bcf	STATUS,RP0
	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	0x01
	btfss	STATUS,Z
	goto	pad_id_x2_get_ssp
	
pad_id_is_x2:
	movf	pad_id,W
	andlw	0xf0
	iorlw	0x02
	movwf	pad_id		; set pad_id = x2
pad_id_x2_get_ssp:	
	movf	sdi,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	0x01
	btfss	STATUS,Z
	goto	pad_id_x3_get_ssp
	
pad_id_is_x3:
	movf	pad_id,W
	andlw	0xf0
	iorlw	0x03
	movwf	pad_id		; set pad_id = x3
pad_id_x3_get_ssp:	
	movf	sdi,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 + -