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

📄 hiduart.asm

📁 USB2.0原理与工程开发光盘(第二版)
💻 ASM
📖 第 1 页 / 共 2 页
字号:

    msendem:
        mov a,RID_RECEIVE             
	mov [EP1_FIFO.0],a
        mov a,[ep1_byte_count]        
        mov [EP1_FIFO.1], a

	iord EP1_Tx_Config		
	and a,EP1_Tx_Toggle      	
	or a,(EP1_Tx_Respond + EP1_Tx_Enable + (EP1_REPORT_LENGTH + 1))
	iowr EP1_Tx_Config	

        FLOW_ON                         

	jmp main	
	
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SuspendCounter()
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SuspendCounter:
       mov a,[fwcr]                  
       and a,BUSY_TRANSMITTING       
       jnz sc_exit

       iord Timer
       rlc
       jc lookforhigh
   lookforlow:
       mov a,TIMER_SYNC                  
       and a,[fwcr]                      
       jnz sc_exit                   
        
       mov a,TIMER_SYNC
       or [fwcr],a                   
       jmp testactivity              

   lookforhigh:
       mov a,TIMER_SYNC              
       and a,[fwcr]
       jz sc_exit                         

       mov a,~TIMER_SYNC             
       and [fwcr],a                  

   testactivity:    
       iord USB_Control
       and a,USBC_BusActive
       jz .IncCtr                    

       iord Global_Interrupt         
       push a                          
       mov a,0                    
       iowr Global_Interrupt         
       iord USB_Control                    
       and a,~USBC_BusActive         
       iowr USB_Control 
       pop a                         
       iowr Global_Interrupt

       mov a,00h                     
       mov [suspend_counter], a
       jmp sc_exit

   .IncCtr:
       inc [suspend_counter]         

   sc_exit:
       ret
     
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; CheckSuspend()
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CheckSuspend:    
	mov a,[suspend_counter]	     
	sub a,SUSPEND_TIME           
	jc .Ret		             

    	mov a,00h                    
	mov [suspend_counter],a	

	iord P0_Data	             
	push a					
	iord P1_Data				
	push a						

	iord P0_PullUp	        
	push a		                
	iord P1_PullUp				
	push a					

	mov a,ffh		
	iowr P0_Data	        
        iowr P1_Data		         

	mov a,00h		
	iowr P0_PullUp
	iowr P1_PullUp

        mov a,01h
        iowr Cext               

	iord Global_Interrupt       
	and a,SUSPEND_MASK 
	iowr Global_Interrupt

	iord StatusControl		
	or a,SC_SUSPEND
	iowr StatusControl

	nop			        
	                                  
        mov a,00h
        iowr Cext                       

        pop a				
	iowr P1_PullUp				

	pop a						
        mov a,00h                       
	iowr P0_PullUp				

	pop a						
	iowr P1_Data				
	pop a						
	iowr P0_Data				

    	mov a,[interrupt_mask]		
	iowr Global_Interrupt
	
     .Ret:
	ret
	
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; handle_rid_command()
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
handle_rid_command:
       cmp a,(end_baud_table-baud_table)
       jc hrc_lookup                  
       mov a, 0                       
    hrc_lookup:
       index baud_table
       mov [baud_bitdelay],a          
       ret

       XPAGEOFF
    baud_table:
       db BAUD_BITDELAY_DEFAULT
       db BAUD_BITDELAY_2400
       db BAUD_BITDELAY_4800
       db BAUD_BITDELAY_9600
       db BAUD_BITDELAY_19200
       db BAUD_BITDELAY_38400
       db BAUD_BITDELAY_57600
    end_baud_table:
       XPAGEON

    
;***********************************************************************************************
;                串行端口收发程序
;***********************************************************************************************

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SerialReceiveByte()
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        org 302h
SerialReceiveByte:
     XPAGEOFF
	push a                  

        iord EP0_Rx_Status      
        and a,~(EP0_Rx_Setup)   
        iowr EP0_Rx_Status      

        push x                  

	mov a,0                 
	iowr P0_IntEnable       

        mov x,08h               

        mov a,[baud_bitdelay]   
        or a,0                         
        rrc                            
        inc a                          
        BIT_DELAY                      

     SerialReceiveData:
        mov a,[baud_bitdelay]          
        BIT_DELAY                      

        iord EP0_Rx_Status             
        and a,EP0_Rx_Status            
        jnz srx_exit                   

        iord P0_Data                   
        and a,SERIAL0RXBIT             
        mov a,[serial_rx_reg]          
        jnz GotOne                     

   GotZero:
        nop                            
        jmp rotate                     

   GotOne:
        cpl                            
        cpl                            

   rotate:
        rrc                            
        mov [serial_rx_reg],a          

        dec x                          
        jnz SerialReceiveData          
      
    XPAGEON

        push a
        mov a,FLOW_CTL_OFF             
        and a,[fwcr]
        pop a                          
        jnz waitbit                     

        mov x,[rx_inptr]               
        mov [x+RX_BUF_PTR_START],a     

        inc x                          
        swap a,x
        cmp a,SERIAL_BUF_SIZE          
        jnz nextdptr                   
        mov a,0                        
    nextdptr:
        mov [rx_inptr],a
            
        cmp a,[rx_outptr]              
        jnz waitbit                    

        FLOW_OFF                       

   waitbit:
        iord P0_Data                   
        and a,SERIAL0RXBIT
        jz waitbit

        mov a,SERIAL0RXBIT             
	iowr P0_IntEnable              

    srx_exit:                          
        pop x
        mov a,[interrupt_mask]
	ipret Global_Interrupt
	
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SerialTransmitByte()
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SerialTransmitByte:
        push x                         
        mov x,08h                      

        iord P0_Data                   
        and a,~SERIAL0TXBIT            
        or a,SERIAL0RXBIT              
        iowr P0_Data                   

     XPAGEOFF
        mov a,[baud_bitdelay]          
        inc a                          
        BIT_DELAY                      
        nop                            
    
     SerialTransmitBit:
        mov a,[serial_tx_reg]          
        rrc a                          
        mov [serial_tx_reg],a          
        jnc SerialTransmit0            

     SerialTransmit1:
        iord P0_Data                           
        or a,(SERIAL0TXBIT+SERIAL0RXBIT)       
        iowr P0_Data                           
        nop                                    
        jmp txbit                              

     SerialTransmit0:
        iord P0_Data                           
        and a,~SERIAL0TXBIT                    
        or a,SERIAL0RXBIT                      
        iowr P0_Data                           
        nop                                    
    
    txbit:
        mov a,[baud_bitdelay]                  
        inc a
        BIT_DELAY                              

        dec x
        jnz SerialTransmitBit
    XPAGEON

        iord P0_Data                           
        or a,SERIAL0TXBIT                      
        or a,SERIAL0RXBIT              
        iowr P0_Data                   

        mov a,[baud_bitdelay]          
        BIT_DELAY                                
        mov a,[baud_bitdelay] 
        BIT_DELAY                      
        mov a,[baud_bitdelay] 
        BIT_DELAY                      

        pop x
        ret                            

;======================== 串行端口收发程序完毕=======================

include		"usbcode.asm"    

⌨️ 快捷键说明

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