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

📄 ezmain.a51

📁 u-boot for Linux platform. you can test it
💻 A51
字号:
; This module initializes the microcontroller then executes MAIN forever
; It is hardware dependant

Reset:
	MOV	SP, #0DFH		; Initialize the Stack
	MOV	PageReg, #7FH		; Allows MOVX Ri to access EZ-USB memory

	MOV	R0, #Low(USBControl)	; Simulate a disconnect
	MOVX	A, @R0
	ANL	A, #11110011b		; Clear DISCON, DISCOE
	MOVX	@R0, A
	CALL	Wait100msec   		; Give the host time to react

;*Jan's code start
;Use this 10 second delay if you want to run USBCheck. Attach the device,
;then you have about 10 seconds to run USBCheck before the renumeration
;simulates a reattach.
;	CALL	Wait10Seconds		; Allow time for USBCheck
;*Jan's code end

	MOVX	A, @R0			; Reconnect with this new identity
	ORL	A, #00000110b           ; Set DISCOE to enable pullup resistor
	MOVX	@R0, A	 		; Set RENUM so that 8051 handles USB requests
	CLR	A
	MOV	FLAGS, A		; Start in Default state
TurnOffLEDs:
        MOV	LEDValue, A
	MOV	Old_Buttons, A
	INC	A			; = 1
	MOV	LEDstrobe, A
Initialize4msecCounter:
	MOV	Msec_counter, A
InitializeIOSystem:			; Setup for Simmbus A=input, B=output
					; C=External RD#,WR#,TD0,TR0
	MOV	R0, #LOW(PortA_Config)	; PageReg = 7F = HIGH(PortA_Config)
	MOV	R1, #LOW(PortA_OE)
	CLR	A
	MOVX	@R0, A			; No alternate functions
	MOVX	@R1, A			; Enable PortA for Input
	INC	R0			; Point to PortB_Config
	INC	R1			; Point to PortB_OE
	MOVX	@R0, A			; No alternate functions
	CPL	A			; = 0FFH
	MOVX	@R1, A			; Enable PortB for Output
	INC	R0			; Point to PortC_Config
	INC	R1			; Point to PortC_OE
	MOV	A, #11000011b		; 
	MOVX	@R0, A			; Alternate functions on [7,6,1,0]
	MOV	A, #11000010b
	MOVX	@R1, A			; Most alternate functions are outputs
InitializeInterruptSystem:		; First initialize the USB level 
	MOV	A, #00000001b
	MOV	R0, #LOW(IN07IEN)
	MOVX	@R0, A			; Enable interrupts from EP0IN only
	INC	R0

;*Jan's code start
;*The original code used CLR A instead of the MOV instruction
;	CLR	A
	MOV	A, #00000101b
	MOVX	@R0, A			; Disable interrupts from OUT Endpoints 1, 3-7
;*Jan's code end

	INC	R0
	MOV	A, #00000011b
	MOVX	@R0, A			; Enable (Resume, Suspend,) SOF and SUDAV INTs
	INC	R0
	MOV	A, #00000001b
	MOVX	@R0, A			; Enable Auto Vectoring for USB interrupts
	                                ; Now enable the main level
	MOV	EIE, #00000001b		; Enable INT2 = USB Interrupt (only) 		
        MOV	EI, #10010000b		; Enable interrupt subsystem (and Ser0 for dScope)
 
; Initialization Complete.
; 
MAIN:
	NOP				; Not much of a main loop for this example
	JMP	MAIN			; All actions are initiated by interrupts
; We are a slave, we wait to be told what to do

Wait100msec:
	MOV	R7, #100
Wait1msec:				; A delay loop
	MOV	DPS, #0			; Select primary DPTR
	MOV	DPTR, #-1200		
More:	INC	DPTR			; 3 cycles
	MOV	A, DPL                  ; + 2
	ORL	A, DPH                  ; + 2
	JNZ	More                    ; + 3 = 10 cycles x 1200 = 1msec
	DJNZ	R7, Wait1msec
	RET

;*Jan's code start
Wait10Seconds:
	MOV	R7, #200
Wait1msec2:				; A delay loop
	MOV	DPS, #0
	MOV	DPTR, #-65535		
More2:	INC	DPTR			; 3 cycles
	MOV	A, DPL                  ; + 2
	ORL	A, DPH                  ; + 2
	JNZ	More2                    ; + 3 = 10 cycles x 65535 = 54 milliseconds
	DJNZ	R7, Wait1msec2
	RET
;*Jan's code end

ProcessOutputReport:		  	; A Report has just been received
; The report is only one byte long in this first example
; It contains a new value for the LEDs
	MOV	DPTR, #EP0OutBuffer	; Point to the Report
	MOVX	A, @DPTR		; Get the Data
	MOV	LEDValue, A		; Update the local variable
	RET

CreateInputReport:			; Called from TIMER which detected the need
; The report is only one byte long in this first example
; It contains a new value for the Buttons
	MOV	DPTR, #EP1InBuffer	; Point to the buffer 
	MOVX	@DPTR, A		; Update the Report
	MOV	DPTR, #IN1ByteCount
	MOV	A, #1
	MOVX	@DPTR, A		; Endpoint 1 now 'armed', next IN will get data
	RET

⌨️ 快捷键说明

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