📄 usbrw.a51
字号:
;*********************************************************************************
; Module description:
; This file is used to read/write USB regs,
; It is written in ASM in order to fast the access
;
;
;Author : Yu Lu ,
; luyu1974@gmail.com
;
;*********************************************************************************/
NAME USBRW_MD
PUBLIC _read_usb, _write_usb, _bunch_read_usb, _bunch_write_usb
USING 0
SUB_USBRW SEGMENT CODE
DAT_USBRW SEGMENT DATA OVERLAYABLE
;AUXR1 EQU 0A2H // this is old control register of dual DPTRs in AT89C51RB2
DPS EQU 86H ; this is control register of dual DPTRs in DS89C420
; ID1: DPS.7
; ID0: DPS.6
; TSL: DPS.5
; AID: DPS.4
; SEL: DPS.0
DPH1 EQU 85H
DPL1 EQU 84H
EXTRN CODE (ser_dispchar)
RSEG DAT_USBRW
TEMP: DS 1
RSEG SUB_USBRW
;***************************************************************
; This subroutine is used to access USBN9603 regs , read
; USAGE: char read_usb(unsigned int usbadr);
; Argument :
; INPUT: R6&R7: address of USBN9603's reg
; OUTPUT: R7: value of that reg
;***************************************************************
_read_usb:
PUSH DPH
PUSH DPL
MOV DPH, R6
MOV DPL, R7
MOVX A, @DPTR
MOV R7,A
POP DPL
POP DPH
RET
;***************************************************************
; This subroutine is used to access USBN9603 regs ,write
; USAGE: write_usb(unsigned int usbadr, char dta);
; Argument :
; INPUT:
; R6&R7: address of USBN9603's reg
; R5 : value to be written
; OUTPUT:
; none;
;***************************************************************
_write_usb:
PUSH DPH
PUSH DPL
MOV DPH, R6
MOV DPL, R7
MOV A,R5
MOVX @DPTR, A
POP DPL
POP DPH
RET
;***************************************************************
;This subroutine is used to read a bundle of data from USBN9603's reg
;usually from the data FIFO
; USAGE : bunch_read_usb( unsigned int usbadr, unsigned int datadd, unsigned char count)
; Argument :
; INPUT:
; R6&R7 : address of USBN9603's reg
; R3 : count of data
;; OUTPUT:
; R4&R5 : address of the data array
;***************************************************************
_bunch_read_usb:
PUSH DPH
PUSH DPL
CJNE R3, #00, BUN_R1 ; if the count is 0, do nothing
RET
BUN_R1:
MOV DPS, #04
MOV DPH, R6 ; set the address of USBN9603
MOV DPL, R7
INC DPS ; toggle DPTR
MOV DPH1, R4 ;set address of xram
MOV DPL1, R5
BUN_R0:
INC DPS ; back to USBN9603
MOVX A, @DPTR ; read from fifo
INC DPS ; back to xram
MOVX @DPTR, A ; write data to xram
INC DPTR ; point to next xram addr
DJNZ R3, BUN_R0 ; if not done,
INC DPS
POP DPL
POP DPH
RET
;***************************************************************
;This subroutine is used to write a bundle of data to USBN9603's reg
; usually to the data FIFO
; USAGE : bunch_write_usb( unsigned int usbadr, unsigned int datadd, unsigned char count)
; Argument :
; INPUT:
; R6&R7: address of USBN9603's reg
; R4&R5: address of the data array
; R3: count of data
;***************************************************************
_bunch_write_usb:
PUSH DPH
PUSH DPL
CJNE R3, #00, BUN_S1 ; if the count is 0 , do nothing
RET
BUN_S1:
MOV DPS, #04
MOV DPH,R6 ; set the address of USBN9603
MOV DPL,R7
INC DPS ; toggle DPTR
MOV DPH1, R4 ; set the address of xram
MOV DPL1, R5
BUN_S0:
MOVX A, @DPTR ; get the data from xram
INC DPTR ; xram DPTR ++
INC DPS ; toggle back DPTR
MOVX @DPTR, A ; send data to USBN9603
INC DPS ; toggle back DPTR
DJNZ R3, BUN_S0
INC DPS ; recover the original DPTR
POP DPL
POP DPH
RET
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -