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

📄 usb_id_key.asm

📁 USB ID KEY 通过USB口送数据给pc自动弹网页
💻 ASM
📖 第 1 页 / 共 5 页
字号:
  .ENDIF 
  
  .IF (Time+0=8) 
        goto $ + 1
        goto $ + 1
  	goto $ + 1
  	goto $ + 1 
        goto $ + 1
  	goto $ + 1
  	goto $ + 1
        goto $ + 1
  	goto $ + 1
  	goto $ + 1 
        goto $ + 1 
        .EXITMAC 
  .ENDIF   
  
  
  .IF (Time%2=0) 
        movlw 	Time
        movwf	DelayCount_us
	decfsz	DelayCount_us,F
	goto	$ - 1
       .EXITMAC 
  .ENDIF 

  .IF (Time%2=1) 
        movlw 	Time
        movwf	DelayCount_us
	decfsz	DelayCount_us,F
	goto	$ - 1
;       .EXITMAC 
  .ENDIF 

.ENDM 
	
;==================================================================================================
		org	0000h	;Reset Vector	
;==================================================================================================

		goto	Start

;==================================================================================================
		org	0001h	;Interrupt Vector	
;==================================================================================================
		
		movwf	StateTemp0
		movfw	Psw
		movwf	StateTemp1  
		
		btfsc	Rsti
		goto	RstiTask
	
		btfsc	Rc0i
     		goto	Rc0iTask
      		
		btfsc	Tx0i
		goto	Tx0iTask
				
		btfsc	Tx1i
		goto	Tx1iTask
		
		btfsc	Tx2i
		goto	Tx2iTask
		
		btfsc	Suspi
		goto	SuspiTask	
			
		btfsc	Kbdi
		goto	KbdiTask
		
		btfsc	Pb0i
		goto	Pb0iTask
		
		btfsc	Rsmi
		goto	RsmiTask
		
		goto	EndInt

;==============================================================================
;Function:Rc0iTask
;  Set RcoFlag and prepare to check receive data.  
;==============================================================================	

Rc0iTask:
		bcf	Rc0i
		bcf	Ep0Stall
		bcf	Tx0Rdy	
		bsf	Rc0Flag
		goto	EndInt
		
;==============================================================================
;Function:Tx0iTask
;  When host got data from device then we will get Tx0i interrupt.  
;==============================================================================	

Tx0iTask:
		bcf	Tx0i	
		bcf	Tx0Rdy	
		bsf	Tx0Flag
		goto	EndInt
				
;==============================================================================
;Function:Tx1iTask
;  1.Host receive data then send Tx1i back to MCU
;==============================================================================	

Tx1iTask:
		movlw	00h
		movwr	Tx1Fifo0
  		movwr	Tx1Fifo1
  		movwr	Tx1Fifo2	
  		movwr	Tx1Fifo3
  		movwr	Tx1Fifo4
  		movwr	Tx1Fifo5
    		movwr	Tx1Fifo6
  		movwr	Tx1Fifo7
		bcf	senddatm
		bcf	Tx1i
		goto	EndInt

;==============================================================================
;Function:Tx2iTask
;  1.Host receive data then send Tx2i back to MCU
;==============================================================================	

Tx2iTask:
		bcf	Tx2i	
		goto	EndInt

;==============================================================================
;Function:RstiTask
;  1.Host request bus reset
;==============================================================================

RstiTask:
		bcf	Rsti
		call	UsbReset		
;		bsf	Rc0Rdy									
		goto	EndInt	

;==============================================================================
;Function:SuspiTask
;  1.Host want keyboard into power down mode
;==============================================================================	

SuspiTask:	
		bcf	Suspi		
  		bsf	SuspendFlag  			
  		goto	EndInt

;==============================================================================
;Function:RsmiTask
;  1.Host wake keyboard up
;==============================================================================	

RsmiTask:	
		bcf	Rsmi
		bcf	Suspend
		bcf	SuspendFlag
		
		movlw	ffh
		movwr	KbdMask
		
		movlw	fch
		movwr	IntEn0	
		movlw	00h
		movwr	IntEn1	
				
		goto	EndInt		
		
;==============================================================================
;Function:KbdiTask
;  1.Keyboard wake up by itself. 
;==============================================================================

KbdiTask:
		bcf	Kbdi	
		bsf	Resume	
		
		movlw	28h
		movwf	UsbResumeCount
		
  KbdiDelay:					;Delay for 10ms....
  		decfsz	AnyCountTemp,F
  		goto	KbdiDelay
  		
  		decfsz	UsbResumeCount,F
  		goto	KbdiDelay
  		
		bcf	Resume  
;		bsf	Rc0Rdy							
		goto	EndInt
		
;==============================================================================
;Function:Pb0iTask
;  1.Keyboard wake up only by Pb0 io port.
;==============================================================================

Pb0iTask:
		bcf	Pb0i				
		bsf	Resume
		
		movlw	28h
		movwf	UsbResumeCount
		
  Pb0iDelay:					;Delay for 10ms....
  		decfsz	AnyCountTemp,F
  		goto	Pb0iDelay
  		
  		decfsz	UsbResumeCount,F
  		goto	Pb0iDelay
  		
		bcf	Resume
;		bsf	Rc0Rdy		

;================================================
;Function:EndInt
;  Recover regisiter Status.
;================================================	

EndInt:
		movfw	StateTemp1
		movwf	Psw
		movfw	StateTemp0	
		reti					
	
;==================================================================================================
		org	0100h	;Main Program Vector
;==================================================================================================	

Start:
		call	SystemReset
    		movlw	10000001B
    		movwr	PDMODE03
    UsbStart:
        	movlw	10000001B
    		movwr	PDMODE03
		call	Ep0IntCheck

		btfsc	SuspendFlag

		call	SuspendTask

		clrwdt

		btfsc	keyup_1
		goto	sendbaishatohost
		btfsc	Pdd,3
		goto	nokey
		goto	checkoutkey

checkoutkey:
		call	redelay
		call	redelay
		call	redelay
		call	redelay
		call	redelay								
		btfsc	Pdd,3
		goto	nokey
		goto	havekey
nokey:
		bcf	keyup
		goto	sendbaishatohost
havekey:
		btfsc	keyup
		goto	sendbaishatohost
		bsf	keyup
 		bcf	lastshowled_0
		bcf	midshowled
		bcf	lastshowled
   		bcf	usbshowled
;		bcf	host_send_data
		bcf	senddatm

sendbaishatohost:
		btfss	senddatm

		call	send_00

		goto	UsbStart

;==============================================================================
redelay:				;delay 10ms 
		movlw	0FFh
		movwf	delay
		movwf	delay_0		
redelay_0:
		clrwdt
		decfsz	delay,1
		goto	redelay_0
redelay_1:
		clrwdt
		decfsz	delay_0,1
		goto	redelay_1
		RET
;==============================================================================
delay1s:
;		bcf	Tx1Rdy
;		bcf	Tx1i
		movlw	00fh
		movwf	delay
;		movwf	delay_0
;		movwf	delay_1
delay1s_0:
		clrwdt
		movlw	0FFh
		movwf	delay_0
		movwf	delay_1
		decfsz	delay,1
		goto	delay1s_1
		ret
delay1s_1:
		clrwdt
		movlw	0FFh
		movwf	delay_1
		decfsz	delay_0,1
		goto	delay1s_2
		goto	delay1s_0
delay1s_2:
		clrwdt
		decfsz	delay_1,1
		goto	delay1s_2
		goto	delay1s_1
		
		
;==============================================================================
;Function:SystemReset
;  1.Disable all Interrupts Flag
;  2.Clear all ram buffers in MCU
;  3.Turn off leds
;  4.Determine whitch interface plug in
;===============================================================================

SystemReset:

		movlw	00h
		movwr	Tm0Pscl
		movwr	IntEn0
		movwr	IntEn1
		
    		movlw	10000001B
    		movwr	PDMODE03
		bcf	Pdd,0
		bcf	send_08_15_0
		bcf	send_08_15
		bcf	keyup_1
		bcf	keyup
		bcf	usbdelaytime
		bcf	usbdelaytime_0
  		bcf	lastshowled_0
		bcf	midshowled
		bcf	lastshowled
    		bcf	usbshowled
		bcf	host_send_data
		bcf	senddatm
		clrf	Gpr0
		clrf	Gpr1 
		clrf	UsbFun
		clrf	Int0
		clrf	Int1
		clrf	Int2
		clrf	Tx0Reg
		clrf	Tx1Reg
;		clrf	Tx2Reg
		
		movlw	ffh
		movwr	KbdMask
		movwf	Led

		bsf	RamBank
  ClearRamBank1:		
		movlw	20h
		movwf	Fsr		
    ClearLoop1:		
		clrf	Indf
		incf	Fsr,F
		movlw	80h
		subwf	Fsr,W
		btfss	Zero
		goto	ClearLoop1
		
		bcf	RamBank
  ClearRamBank0:		
		movlw	20h
		movwf	Fsr
    ClearLoop0:		
		clrf	Indf
		incf	Fsr,F
		movlw	80h
		subwf	Fsr,W
		btfss	Zero
		goto	ClearLoop0

		goto	Usb			;USB Only

    Usb:
    		bsf	UsbEn

    		clrf	Int0
		clrf	Int1

		movlw	c8h
		movwr	IntEn0	

		movlw	01h
		movwr	Tm0Pscl	
		clrf	Timer0	
		ret

		
;==============================================================================
;Function:UsbReset
;  1.Enable USBEn flag
;  2.Enable Rc0int,Tx0int,Rstint,Suspint,Timer0int flags 
;  3.Enable Tx1,Tx2 toggle
;  4.Enable Timer0
;==============================================================================	

UsbReset:
		movlw	80h
		andwf	UsbFun,F
		
		clrf	Gpr0
		clrf	Gpr1 
		clrf	Int0
		clrf	Int1
		clrf	Int2
		clrf	Tx0Reg
		clrf	Tx1Reg

		movlw	ffh
		movwf	Pad
		movwf	Ksol
		movwf	Ksoh

  UsbClearRamBank0:
		movlw	20h
		movwf	Fsr		
    UsbClearLoop0:		
		clrf	Indf
		incf	Fsr,F
		movlw	80h
		subwf	Fsr,W
		btfss	Zero
		goto	UsbClearLoop0
                                        		
		ret

;==============================================================================
;Function:KeyScanInitial
;Set Debounce key buffer to ffh
;==============================================================================	


;==============================================================================
;Function:Ep0IntCheck
;  1.Check two kinds of interrupts:Tx0i and Rc0i
;==============================================================================		
	
Ep0IntCheck:					
                btfsc	Rc0Flag
      		goto	Rc0Task
      		
		btfsc	Tx0Flag
		goto	Tx0Task	
			
		ret

;==============================================================================
;Function:SuspendTask
;  1.Check two kinds of interrupts:Tx0i and Rc0i
;==============================================================================	

SuspendTask:
		movlw	ffh		
		movwf	Led	
		testz	RemoteWakeupStatus
		btfsc	Zero
		goto	SuspendDisable

  SuspendEnable:
  		movlw	00h	
		movwr	KbdMask			;Let any key can wake host up    		 
  
		movlw	fch
		andwf	Pad,F
		andwf	Ksol,F
		andwf	Ksoh,F
				
		movlw	f3h
		andwf	Ksol,F
		andwf	Ksoh,F
		
		movlw	3fh
		andwf	Ksol,F
		andwf	Ksoh,F	
		
		movlw	cfh
		andwf	Ksol,F
		andwf	Ksoh,F

  SuspendDisable:
  		movlw	00h		
		movwr	IntEn0			;Disable all interrupts		
		movlw	0ch
		movwr	IntEn1			;Only 
				
		bsf	Suspend
		
		nop
		nop
		nop

		sleep
			
		nop
				
		ret	

;==============================================================================
;Function:CheckLength
;  1.Check how many data want to send
;==============================================================================	

CheckLength:
		movfw	DataLength
		movwf	WLengthTemp	
		testz	WLengthHi
		btfss	Zero
		ret
		
  CheckLenTask:	
  		bcf	Carry
  		movfw	DataLength
  		subwf	WLength,W
  		btfsc	Carry
  		ret
  		
  		movfw	WLength
  		movwf	WLengthTemp
  		ret

;==============================================================================
;Function:Tx0Transfer
;  1.Transfer data to host
;==============================================================================	

Tx0Transfer:
		clrf	LengthCnt		
		testz	WLengthTemp
		btfsc	Zero
		goto	SetTgl
			
		movfw	TableCnt		
		call	DeviceDescTable
		btfss	TableSelBit
		goto	Sendbyte0
		movfw	TableCnt
		call	Report1DescTable		
  Sendbyte0:
		movwr	Tx0Fifo0
		incf	TableCnt,F
		incf	LengthCnt,F
		decf	WLengthTemp,F
		testz	WLengthTemp
		btfsc	Zero
		goto	SetTgl
	
		movfw	TableCnt
		call	DeviceDescTable
		btfss	TableSelBit
		goto	Sendbyte1
		movfw	TableCnt
		call	Report1DescTable		
  Sendbyte1:		
		movwr	Tx0Fifo1
		incf	TableCnt,F
		incf	LengthCnt,F
		decf	WLengthTemp,F
		testz	WLengthTemp
		btfsc	Zero
		goto	SetTgl
			
		movfw	TableCnt
		call	DeviceDescTable
		btfss	TableSelBit
		goto	Sendbyte2
		movfw	TableCnt
		call	Report1DescTable		
  Sendbyte2:	
		movwr	Tx0Fifo2
		incf	TableCnt,F
		incf	LengthCnt,F
		decf	WLengthTemp,F
		testz	WLengthTemp
		btfsc	Zero
		goto	SetTgl

		movfw	TableCnt
		call	DeviceDescTable
		btfss	TableSelBit
		goto	Sendbyte3
		movfw	TableCnt
		call	Report1DescTable		
  Sendbyte3:	
		movwr	Tx0Fifo3
		incf	TableCnt,F
		incf	LengthCnt,F
		decf	WLengthTemp,F
		testz	WLengthTemp
		btfsc	Zero
		goto	SetTgl

		movfw	TableCnt
		call	DeviceDescTable
		btfss	TableSelBit
		goto	Sendbyte4
		movfw	TableCnt
		call	Report1DescTable		
  Sendbyte4:		
		movwr	Tx0Fifo4

⌨️ 快捷键说明

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