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

📄 emb_f.asm

📁 mcs51,2051,x86系列MCU
💻 ASM
📖 第 1 页 / 共 5 页
字号:

;-----------------------------------------------
; Data is in ROM, use instrcutions to pull from ROM.
;-----------------------------------------------
DataInROM:
        mov     A,      #00h
        movc    A,      @A+DPTR                     ; Get Data to transmit

        mov     TXDAT , A
        inc     DPTR
        inc     R0                                  ; Increment the number of bytes in FIFO
        djnz    gbFControlBufferBytesLeft+1, ROMCheckMaxPacket        ; If not zero, the continue.

ROMCheckUpper1:
        mov     A,       gbFControlBufferBytesLeft  ; If upper byte of wLength is also zero, buffer is empty.
        jz      ControlTxUpd                        ; Are we done with the buffer
        dec     A                                   ; If it's not zero dec. the upper byte as well.
        mov     gbFControlBufferBytesLeft, A        ; And store it.

ROMCheckMaxPacket:
        cjne    R0,      #EP0_MAX_PACKET_SIZE, DataInROM    ; Loop until FIFO is Full
        jmp     ControlTxUpd                       ; Done with this FIFO.


;-----------------------------------------------
; Data is in RAM, use instrcutions to pull from RAM.
;-----------------------------------------------

DataInRAM:


        movx    A,      @DPTR                       ; Get Data to transmit
        mov     TXDAT , A
        inc     DPTR
        inc     R0                                  ; Increment the number of bytes in FIFO
        djnz    gbFControlBufferBytesLeft+1, RAMCheckMaxPacket        ; If not zero, the continue.

RAMCheckUpper1:
        mov     A,       gbFControlBufferBytesLeft  ; If upper byte of gbFControlBufferBytesLeft is also zero, buffer is empty.
        jz      ControlTxUpd                        ; Are we done with the buffer
        dec     A                                   ; If it's not zero dec. the upper byte as well.
        mov     gbFControlBufferBytesLeft, A        ; And store it.

RAMCheckMaxPacket:
        cjne    R0,      #EP0_MAX_PACKET_SIZE, DataInRAM    ; Loop until FIFO is Full


ControlTxUpd:
        mov     gbFControlBufferLocation+1, DPH      ; Update read pointers.
        mov     gbFControlBufferLocation+2, DPL

ControlArmTx:
        mov     TXCNTL, R0                          ; Write count into TXCNT register
        setb    TXOE                                ; Enable data transmit
ReturnLoadCntl:
        pop     DPX
        pop     R0
        Ret



;COMMENT *------------------------------------------------------------
;Function name     : INIT_FUNCTION_EP0
;Brief Description : Initialize USB SFRs
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
INIT_FUNCTION_EP0:                          ; EP0 Comes up as it should except that
                                   ; all flow control is turned off except for
                                   ; OE bits.  This will turn them on so we can
                                   ; accept all data.
                                   ; All other endpoints should not be configured
                                   ; until a Set Configuration command is given.
        push    EPINDEX
        mov     EPINDEX, #00
        mov     TXCON,   #04h      ; TX FIFO
        mov     RXCON,   #04h      ; RX FIFO
        mov     EPCON,   #03Fh      ; EP Control
        orl     IEN0,    #085h        ; Enable Interrupts
;        orl     IEN1,    #07h       -- already enabled in hub
        orl     FIE,     #0EFh
        orl     SOFH,    #020h        ; Make sure SOFIE is set
        orl     IPL0,    #00h        ; Set interrupt priority
        orl     IPH0,    #00h
        orl     IPL1,    #02h
        orl     IPH1,    #00h
        pop     EPINDEX


ReturnInitUSB:
        Ret



;COMMENT *------------------------------------------------------------
;Function name     : INIT_VARIABLES
;Brief Description : Initializes global variables
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
INIT_VARIABLES:
;Init SETUP VARIABLES

        mov     R0, #00h
        mov     Heart1, R0
        mov     Heart1+1, R0
        mov     gbSetupSeqRX, R0                       ; SetupSeq is set to

        mov     gbSetupSeqTX, R0                       ; STATUS_PHASE
        mov     gbFControlBufferLocation, R0
        mov     gbFControlBufferLocation+1, R0
        mov     gbFControlBufferLocation+2, R0

        mov     gbFControlBufferBytesLeft, R0

        mov     WR0, #0                    ; Zero Out Counter
        mov     WR2, WR0
        mov     EP1_TX_COUNTER,     DR0
        mov     EP2_TX_COUNTER,     DR0
        mov     EP3_TX_COUNTER,     DR0
        mov     EP1_TX_ERR_COUNTER, DR0
        mov     EP2_TX_ERR_COUNTER, DR0
        mov     EP3_TX_ERR_COUNTER, DR0

        mov     EP1_RX_ERR_COUNTER, DR0
        mov     EP2_RX_ERR_COUNTER, DR0
        mov     EP3_RX_ERR_COUNTER, DR0
        mov     RWUTimer,  DR0

        mov      Ep1Tx_ERR, R0
        mov      Ep1Tx_OVF, R0
        mov      Ep1Tx_URF, R0
        mov      Ep1Rx_ERR, R0
        mov      Ep1Rx_OVF, R0
        mov      Ep1Rx_URF, R0

        mov      Ep2Tx_ERR, R0
        mov      Ep2Tx_OVF, R0
        mov      Ep2Tx_URF, R0
        mov      Ep2Rx_ERR, R0
        mov      Ep2Rx_OVF, R0
        mov      Ep2Rx_URF, R0

        mov      Ep3Tx_ERR, R0
        mov      Ep3Tx_OVF, R0
        mov      Ep3Tx_URF, R0
        mov      Ep3Rx_ERR, R0
        mov      Ep3Rx_OVF, R0
        mov      Ep3Rx_URF, R0
; EP1 Loop back varibales
        mov     Ep1BytesInBuffer  , WR0
        mov     WR0, #Ep1LoopBackBuffer
        mov     Ep1WritePointer,  WR0
        mov     Ep1ReadPointer,  WR0

; EP2 Loop back varibales
        xrl     WR0,  WR0
        mov     Ep2BytesInBuffer  , WR0
        mov     WR0, #Ep2LoopBackBuffer
        mov     Ep2WritePointer,  WR0
        mov     Ep2ReadPointer,  WR0

; EP3 Loop back varibales
        xrl     WR0,  WR0
        mov     Ep3BytesInBuffer  , WR0
        mov     WR0, #Ep3LoopBackBuffer
        mov     Ep3WritePointer,  WR0
        mov     Ep3ReadPointer,  WR0

ReturnInit:
        Ret

;COMMENT *------------------------------------------------------------
;Function name     : RightCylon & LeftCylon
;Brief Description : Does a cylong pattern on the LEDs
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

;========================================================================
; Right Cylon Pattern  on Port1
;========================================================================
RightCylon:
        push   WR2
        push   ACC
        mov    WR2, #00
        mov    A,   #80h
CylonRightLoop:
        inc   WR2, #1
        cmp   R2,  #20h
        jne   CylonRightLoop
        srl   R11
        mov   P1, A
        mov   WR2, #00h
        jnb   ACC.0, CylonRightLoop
        pop   ACC
        pop   WR2
        ret
;========================================================================
; Left Cylon Pattern on Port1
;========================================================================

LeftCylon:
        push   WR2
        push   ACC
        mov    WR2, #00
        mov    A,   #01h
CylonLeftLoop:
        inc   WR2, #1
        cmp   R2,  #20h
        jne   CylonLeftLoop
        sll   R11
        mov   P1, A
        mov   WR2, #00h
        jnb   ACC.7, CylonLeftLoop
        pop   ACC
        pop   WR2
        ret
;========================================================================
;========================================================================


;************************************************************************
;------------------------------------------------------------------------
;EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
;EE                   ENDPOINT 1 ISR.
;EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
;------------------------------------------------------------------------
;************************************************************************
;COMMENT *------------------------------------------------------------
;Function name     : EP1_TX_ISR
;Brief Description : Acts as an Infinite source of 32 byte data packets.
;                  : Each data packet has an incremented DWORD varaiable in
;                  : it.
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

;
EP1_TX_ISR:
                  ; First check to see if there is room in the FIFO
EP1TXCheckEveryThing:
        anl     FIFLG,   #EP1_TX_CLR       ; CLear Interrupt Pending Flag
        jb      TXERR,   HandleTX1Error
        jnb     TXFIF0,  RoomAvailable
        jnb     TXFIF1,  RoomAvailable     ; Use if double buffered
        sjmp    NoRoomAvailable

RoomAvailable:

        push    DR0
        mov     DR0,     EP1_TX_COUNTER
        mov     A,       #(EP1_TX_FIFO_SIZE/8)
DWORD_LOOP:
        mov     TXDAT,   R3
        mov     TXDAT,   R2
        mov     TXDAT,   R1
        mov     TXDAT,   R0
        mov     TXDAT,   R3
        mov     TXDAT,   R2
        mov     TXDAT,   R1
        mov     TXDAT,   R0
        djnz    ACC,     DWORD_LOOP
        mov     TXCNTH,  #HIGH (EP1_TX_FIFO_SIZE)              ; Write the high byte first.  This only needs to
                                          ; be done on EP1
        mov     TXCNTL,  #LOW (EP1_TX_FIFO_SIZE)
        inc     DR0,     #01
        mov     EP1_TX_COUNTER, DR0
        pop     DR0
        sjmp    EP1TXCheckEveryThing     ; Since this is a bulk EP, go see if we need to do more stuff.

HandleTX1Error:
        orl     EPCON,   #SET_IN_STALL_MASK
NoRoomAvailable:                           ; At this point the stack needs to be cleaned up.
        ret


;************************************************************************
;------------------------------------------------------------------------
;EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
;EE                   ENDPOINT 2 ISR.
;EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
;------------------------------------------------------------------------
;************************************************************************
;COMMENT *------------------------------------------------------------
;Function name     : EP2_TX_ISR
;Brief Description : Acts as an Infinite source of 8 byte ISOC data packets.
;                  : Each data packet has an incremented DWORD varaiable in
;                  : it along with the current SOF Value.
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

;
EP2_TX_ISR:

;************************************************************************
;------------------------------------------------------------------------
;EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
;EE                   ENDPOINT 3 ISR.
;EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
;------------------------------------------------------------------------
;************************************************************************
;COMMENT *------------------------------------------------------------
;Function name     : EP3_TX_ISR
;Brief Description : Acts as an Infinite source of 32 byte data packets.
;                  : Each data packet has an incremented DWORD varaiable in
;                  : it.
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

;
EP3_TX_ISR:
                  ; First check to see if there is room in the FIFO
EP3TXCheckEveryThing:
        a

⌨️ 快捷键说明

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