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

📄 sio.asm

📁 VCP201_CODE is a FPGA source code.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;=======================================================
; File Name : sio.asm	2109 ASIC
;
;Rev.:  Date:    Author:     Reason:
;============================================================

	ORG     0x04
si:
	movwf   w_save          ; save W
	swapf   STATUS,W
	clrf    STATUS          ; to bank 0
	movwf   status_save     ; save STATUS

	movf    FSR,W           ; save FSR
        movwf   fsr_save
        
	movf    PCLATH,W
	movwf   pclath_save     ; save PCLATH
	clrf    PCLATH

	movlw	0xff
        movwf	sdo
        call	wait_spi_data
        btfsc	STATUS,C
        goto	end_SPI
	
	xorlw   0x01           ; 01h ?
	btfss   STATUS,Z
	goto    end_SPI         ; No

        btfss   f_nmode
        goto    button_report_mode	;41,79
        btfsc   f_setting_mode
        goto    parameter_setting_mode	;43

;---------------------------
; button report mode
;---------------------------
button_report_mode:
	movf	pad_id,W	; Controller ID

	spi_transmit

	movwf   last_command    ; save data
	xorlw   0x42           ; 42h ?
	btfss   STATUS,Z
	goto    command_43	; No

	movlw   0x05a           ; ack
        btfss   f_nmode         ; old mode ?
        goto    report_42_send_ack    ; Yes 

        btfsc   mode_ch         ; mode change ?
        clrw                    ; Yes

report_42_send_ack:
 	spi_transmit		;out 5A
 		
        call	ADD_nop6

	bsf	STATUS,RP0
        movf    finadata1,W     ; 1st Pad data
        bcf	STATUS,RP0
	spi_transmit

	bsf	STATUS,RP0
	movwf	sonycmd0
	movf	pre_data1,W
	bcf	STATUS,RP0
	call	save_motor_data
	
	bsf	STATUS,RP0
        movf    finadata2,W     ; 2nd Pad data
	bcf	STATUS,RP0
	spi_transmit

	bsf	STATUS,RP0
	movwf	sonycmd1
	movf	pre_data2,W
	bcf	STATUS,RP0
	call	save_motor_data
	
	movf	pad_id,W
	andlw	0x0f
	xorlw	0x01
	btfsc	STATUS,Z
	goto	end_SPI		; = x1 mode
	
	bsf	STATUS,RP0
        movf    finadata3,W     ; 3rd Pad data
	bcf	STATUS,RP0
	spi_transmit
	
	bsf	STATUS,RP0
	movf	pre_data3,W
	bcf	STATUS,RP0
	call	save_motor_data

	bsf	STATUS,RP0
        movf    finadata4,W     ; 4th Pad data
	bcf	STATUS,RP0
	spi_transmit

	bsf	STATUS,RP0
	movf	pre_data4,W
	bcf	STATUS,RP0
	call	save_motor_data
	        
	movf	pad_id,W
	andlw	0x0f
	xorlw	0x02
	btfsc	STATUS,Z
	goto	end_SPI		; = x2 mode	

	bsf	STATUS,RP0
        movf    finadata5,W     ; 5th Pad data
	bcf	STATUS,RP0
	spi_transmit

	bsf	STATUS,RP0
	movf	pre_data5,W
	bcf	STATUS,RP0
	call	save_motor_data

	bsf	STATUS,RP0
        movf    finadata6,W     ; 6th Pad data
	bcf	STATUS,RP0
	spi_transmit

	bsf	STATUS,RP0
	movf	pre_data6,W
	bcf	STATUS,RP0
	call	save_motor_data
	
	movf	pad_id,W
	andlw	0x0f
	xorlw	0x03
	btfsc	STATUS,Z
	goto	end_SPI		; = x3 mode

com_42_data7:
	bsf	STATUS,RP0
        movf    finadata7,W     ; 7th Pad data
	bcf	STATUS,RP0
	spi_transmit

        call	ADD_nop6	
	bsf	STATUS,RP0
        movf    finadata8,W     ; 8th Pad data
	bcf	STATUS,RP0
	spi_transmit

	movf	pad_id,W
	andlw	0x0f
	xorlw	0x04
	btfsc	STATUS,Z
	goto	end_SPI		; = x4 mode

	bsf	STATUS,RP0
        movf    finadata9,W     ; 9th Pad data
	bcf	STATUS,RP0
	spi_transmit

        call	ADD_nop6
	bsf	STATUS,RP0
        movf    finadata10,W    ; 10th Pad data
	bcf	STATUS,RP0
	spi_transmit

	movf	pad_id,W
	andlw	0x0f
	xorlw	0x05
	btfsc	STATUS,Z
	goto	end_SPI		; = x5 mode

	bsf	STATUS,RP0
        movf    finadata11,W    ; 11th Pad data
	bcf	STATUS,RP0
	spi_transmit

        call	ADD_nop6
	bsf	STATUS,RP0
        movf    finadata12,W    ; 12th Pad data
	bcf	STATUS,RP0
	spi_transmit

	movf	pad_id,W
	andlw	0x0f
	xorlw	0x06
	btfsc	STATUS,Z
	goto	end_SPI		; = x6 mode
	
	bsf	STATUS,RP0
	movf    finadata13,W    ; 13th Pad data
	bcf	STATUS,RP0
	spi_transmit

        call	ADD_nop6
	bsf	STATUS,RP0
        movf    finadata14,W    ; 14th Pad data
	bcf	STATUS,RP0
	spi_transmit

	movf	pad_id,W
	andlw	0x0f
	xorlw	0x07
	btfsc	STATUS,Z
	goto	end_SPI		; = x7 mode

	bsf	STATUS,RP0
        movf    finadata15,W    ; 15th Pad data
	bcf	STATUS,RP0
	spi_transmit

        call	ADD_nop6
	bsf	STATUS,RP0
        movf    finadata16,W    ; 16th Pad data
	bcf	STATUS,RP0
	spi_transmit

	movf	pad_id,W
	andlw	0x0f
	xorlw	0x08
	btfsc	STATUS,Z
	goto	end_SPI		; = x8 mode

	bsf	STATUS,RP0
        movf    finadata17,W    ; 17th Pad data
	bcf	STATUS,RP0
	spi_transmit

        call	ADD_nop6
	bsf	STATUS,RP0
        movf    finadata18,W    ; 18th Pad data
	bcf	STATUS,RP0
	spi_transmit

	goto    end_SPI

;-------------------------------------------
command_43:
	movf    last_command,W  ; get saved data
	xorlw   0x43           ; 43h ?
	btfss   STATUS,Z
	goto    end_SPI         ; No

	movlw   0x5a           ; ack
        btfss   mode_ch
        goto    report_43_send_ack
        btfsc   f_nmode         ; old mode ?
        clrw                    ; No
        bcf     mode_ch
        
report_43_send_ack:
	spi_transmit

	btfss	STATUS,Z
	goto	end_SPI
	
        call	ADD_nop6

	bsf	STATUS,RP0
        movf    finadata1,W     ; 1st Pad data
	bcf	STATUS,RP0

	spi_transmit
	
	bcf	f_setting_mode
        xorlw   0x01           ; 01h ?
        btfss   STATUS,Z
       	goto	report_43_send_2nd
       	
        bsf	f_nmode         ; psx mode 2.0
        bsf	f_setting_mode	; parameter setting mode
	
	
report_43_send_2nd:
	call	ADD_nop6
	bsf	STATUS,RP0
        movf    finadata2,W     ; 2nd Pad data
	bcf	STATUS,RP0
	spi_transmit

	movf	pad_id,W
	andlw	0x0f
	xorlw	0x01
	btfsc	STATUS,Z
	goto	end_SPI		; = x1 mode

	bsf	STATUS,RP0	
        movf    finadata3,W     ; 3rd Pad data
	bcf	STATUS,RP0
	spi_transmit

	bsf	STATUS,RP0
        movf    finadata4,W     ; 4th Pad data
	bcf	STATUS,RP0
	spi_transmit
        
	movf	pad_id,W
	andlw	0x0f
	xorlw	0x02
	btfsc	STATUS,Z
	goto	end_SPI		; = x2 mode	

	bsf	STATUS,RP0
        movf    finadata5,W     ; 5th Pad data
	bcf	STATUS,RP0
	spi_transmit

	bsf	STATUS,RP0
        movf    finadata6,W     ; 6th Pad data
	bcf	STATUS,RP0
	spi_transmit

	movf	pad_id,W
	andlw	0x0f
	xorlw	0x03
	btfsc	STATUS,Z
	goto	end_SPI		; = x3 mode

	goto	com_42_data7
	        

;------------------------------------------
;psx mode 2.0
;parameter setting mode
;------------------------------------------
parameter_setting_mode:         ; 
	movlw   0xf3           ; f3

	spi_transmit
	
        movwf   last_command	; 4x ?
        andlw	0xf0
        xorlw	0x40
        btfss	STATUS,Z
        goto	end_SPI

	movlw	0x5a		; ack	5A
	spi_transmit
	
	btfsc	STATUS,Z	; only 42 accept 00,
	goto	send_command	; all others not reply

	movlw	0x42
	xorwf	last_command,W
	btfss	STATUS,Z
	goto	end_SPI

send_command:
	movlw	HIGH command_table
	movwf	PCLATH
	        
        movf	last_command,W
	andlw	0x0f

command_table:
	addwf	PCL,F
        nop				;specif for ASIC VCP201 ***
	goto	ps2_command_40
	goto	ps2_command_41
	goto	ps2_command_42
	goto	ps2_command_43
	goto	ps2_command_44
	goto	ps2_command_45
	goto	ps2_command_46
	goto	ps2_command_47
	goto	ps2_command_48
	goto	ps2_command_49
	goto	ps2_command_4a
	goto	ps2_command_4b
	goto	ps2_command_4c
	goto	ps2_command_4d
	goto	ps2_command_4e
	goto	ps2_command_4f
	        
;----------------------------------
; command = 40
; Reserved
;----------------------------------
ps2_command_40:
	btfss	D_A_mode
	goto	ps2_command_4b

	bsf	f_sio_ack		
	movlw	ana_sen_1
	movwf	FSR
	clrw			; 1st data
	spi_transmit

	bsf	STATUS,RP0
	movwf	sio_tmp3
;        clrf	sio_tmp1

	sublw	d'11'		;>11?
        bcf	STATUS,RP0
	btfsc	STATUS,C
	bcf	f_sio_ack

com_40_2nd_data:
	bcf	STATUS,RP0
	clrw			; 2nd data
	spi_transmit

	bsf	STATUS,RP0
	movwf	sio_tmp1
	bcf	STATUS,RP0

	movlw	0xff		; previous data > 11
	btfsc	f_sio_ack
	goto	com_40_3rd_data
	
	bsf	STATUS,RP0
	bcf	STATUS,C
	rrf	sio_tmp3,W	; add half of it
	addwf	FSR,F

	movf	INDF,W		; 3rd data
	btfsc	sio_tmp3,0
	swapf	INDF,W
	andlw	0x0f
        bcf	STATUS,RP0

com_40_3rd_data:
	spi_transmit

	btfss	STATUS,Z
	bsf	f_sio_ack
	
	bsf	STATUS,RP0
	movf	sio_tmp1,W
	xorlw	0xff
	btfsc	STATUS,Z
	goto	com_40_4th_data
	movf	sio_tmp1,W
	bcf	STATUS,RP0
	andlw	0xfc
	btfss	STATUS,Z
	bsf	f_sio_ack
	
com_40_4th_data:
	bcf	STATUS,RP0
	clrw
	spi_transmit		; 4th data

com_40_5th_data:
	bcf	STATUS,RP0	
	movf	sdi,W
	btfss	STATUS,Z
	bsf	f_sio_ack
	clrw			; 5th data
	spi_transmit

	btfss	STATUS,Z
	bsf	f_sio_ack
	
	clrw			; 6th data
	btfss	D_A_mode
	goto	com_40_6th_data
	movlw	0x5a
	btfsc	f_sio_ack
	movlw	0xff

com_40_6th_data:
	spi_transmit       

	btfsc	f_sio_ack
	goto	com_40_end_data
	bsf	STATUS,RP0
	movf	sio_tmp1,W
	xorlw	0xff
	btfsc	STATUS,Z
	goto	com_40_end_data
	
	movf	INDF,W		
	btfsc	sio_tmp3,0
	swapf	INDF,W
	andlw	0xf0		; 0000 xxxx
	iorwf	sio_tmp1,W
	
	movwf	INDF
	btfsc	sio_tmp3,0
	swapf	INDF,F
	
com_40_end_data:
	bcf	STATUS,RP0
	goto	end_SPI
	
;----------------------------------
; command = 41
; Reserved
;----------------------------------
ps2_command_41:
	btfss	D_A_mode
	goto	ps2_command_4b

	clrw			; 1st data
	btfsc	D_A_mode
	movlw	0xff
	spi_transmit
	
	call	ADD_nop6
	clrw			; 2nd data
	btfsc	D_A_mode
	movlw	0xff
	spi_transmit
	
        call	ADD_nop6
	clrw			; 3rd data
	btfsc	D_A_mode
	movlw	0x03		; 03
	spi_transmit
	
	call	ADD_nop6
        clrw			; 4th data
	spi_transmit
	
        call	ADD_nop6
	clrw			; 5th data
	spi_transmit
	
	call	ADD_nop6
	clrw			; 6th data
	btfsc	D_A_mode
	movlw	0x5a
	spi_transmit       

	goto	end_SPI
	
;------------------------------------
; command = 42
; Button and analog level acquisition
; and actuator parameter setting.
;------------------------------------
ps2_command_42:
 	bsf	STATUS,RP0       
	movf	finadata1,W	; 1st data
	bcf	STATUS,RP0
	spi_transmit
	
	call	ADD_nop6
	bsf	STATUS,RP0	
	movf	finadata2,W	; 2nd data
	bcf	STATUS,RP0
	spi_transmit
	
        call	ADD_nop6
	bsf	STATUS,RP0
	movf	finadata3,W	; 3rd data
	bcf	STATUS,RP0
	spi_transmit
	
	call	ADD_nop6
	bsf	STATUS,RP0	
        movf	finadata4,W	; 4th data
	bcf	STATUS,RP0
	spi_transmit
	
        call	ADD_nop6
	bsf	STATUS,RP0        
	movf	finadata5,W	; 5th data
	bcf	STATUS,RP0
	spi_transmit
	
	call	ADD_nop6
	bsf	STATUS,RP0
	movf	finadata6,W	; 6th data
	bcf	STATUS,RP0
	spi_transmit       

	goto	end_SPI
	
;------------------------------------------
; command = 43
; Controller parameter setting mode ON/OFF,
; the uninitialized state resetting.
;------------------------------------------
ps2_command_43:
	clrw			; 1st data
	spi_transmit
		
	bcf	f_setting_mode
        xorlw   0x01           ; 01h ?
        btfss   STATUS,Z
       	goto	ps2_43_0
       	
        bsf	f_nmode         ; psx mode 2.0
        bsf	f_setting_mode	; parameter setting mode	        

ps2_43_0:
	call	ADD_nop6
	clrw			; 2nd data
	spi_transmit

        call	ADD_nop6
	goto	com_4b_send_3rd

;	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 = 44
; Controller mode setup
;----------------------------------
ps2_command_44:
	bsf	STATUS,RP0	
	clrf	sio_tmp1
	bcf	STATUS,RP0
			
	clrw			; 1st byte : must be 0
	spi_transmit

	
	btfss	STATUS,Z
	goto	command_44_not_digital
	bcf	D_A_mode	; set to 4x mode
	bsf	f_44_chmode
	goto	com_44_mode_accept
	
command_44_not_digital:	
	xorlw	0x01		;01?
	btfss	STATUS,Z
	goto	send_44_2nd_byte
	bsf	D_A_mode	; set to 7x mode
	bsf	f_44_chmode

com_44_mode_accept:
	bsf	STATUS,RP0
	incf	sio_tmp1,F
	bcf	STATUS,RP0
	
send_44_2nd_byte:
	clrw			; 2nd byte : must be 0
	spi_transmit
	
        btfss	sdi,1
        goto	send_44_3rd_byte ; lock unchange
	bsf	f_44_lock
	btfss	sdi,0
	bcf	f_44_lock	; unlock
        
send_44_3rd_byte:
	bsf	STATUS,RP0
	movf	sio_tmp1,F
	bcf	STATUS,RP0

	movlw	0xff
	btfss	STATUS,Z      
	clrw			; 3rd byte : must be 0
	spi_transmit
	
;	call	ADD_nop6
	goto	com_4b_send_4th

;        clrw			; 4th byte : must be 0
;	spi_transmit
;	
;        call	ADD_nop6
;	clrw			; 5th byte : must be 0
;	spi_transmit
;	
;	call	ADD_nop6
;	clrw			; 6th byte : must be 0
;	spi_transmit       
;
;	goto	end_SPI
	
;-----------------------------------
; command = 45
; Controller information acquisition
;-----------------------------------
ps2_command_45:
	movlw	0x03		; revision code. 03?
	spi_transmit

	call	ADD_nop6	
	movlw	0x02		; no of mode can be set by software

	spi_transmit
	
        call	ADD_nop6	; 3rd byte :
	clrw			; present controller mode
	btfsc	D_A_mode
	movlw	0x01		;01?
	spi_transmit
	
	call	ADD_nop6	; 4th byte :
        movlw	0x02		; no of actuator =2
	spi_transmit

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -