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

📄 main.a51

📁 演示了如何开发WINDOES下I/O口驱动
💻 A51
字号:
; This module initializes the microcontroller then executes MAIN forever
;

Reset:
	MOV	SP, #235		; Initialize the Stack at top of internal memory
	MOV	PageReg, #7FH		; Needed to use MOVX @Ri

	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
	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
InitializeIOSystem:			; This example uses PortA an OUT and 
					; the lower 4 bits of PortC as IN
; Assume a pre-existing configuration (ie Dscope)	
	MOV	R0, #LOW(PortA_Config)	; PageReg = 7F = HIGH(PortA_Config)
	CLR	A
	MOVX	@R0, A			; No alternate functions
	MOV	R1, #LOW(PortA_OE)
	CPL	A			; = 0FFH
	MOVX	@R1, A			; Enable PortA for Output
	MOV	R0, #LOW(PortC_Config)	; PageReg = 7F = HIGH(PortC_Config)
	MOV	R1, #LOW(PortC_OE)
	MOVX	A, @R0			; Get current configuration
	ANL	A, #0F0H
	MOVX	@R0, A			; No alternate functions on lower nibble
	MOVX	A, @R1			; Get current configuration
	ANL	A, #0F0H
	MOVX	@R1, A			; Enable PortC_Bits[3:0] for Input
; Need to initialize Timer 0 to generate 40 microsecond interrupts
	MOV	Timer0High, #80		; Reload Value
	MOV	A, TimerMode		; Set up Timer 0 without changing Timer 1
	ANL	A, #0F0H		; Clear lower 4 bits
	SETB	ACC.1			; Set No Gate, Timer, Mode 2
	MOV	TimerMode, A
	MOV	A, TimerControl
	ORL	A, #00110000b		; Turn on Timer 0
	MOV	TimerControl, A

InitializeInterruptSystem:		; First initialize the USB level
	MOV	R0, #LOW(IN07IEN)
	MOVX	@R0, A			; Disable interrupts from IN Endpoints 0-7
	INC	R0
	MOVX	@R0, A			; Disable interrupts from OUT Endpoints 0-7
	INC	R0
	MOV	A, #00000001b
	MOVX	@R0, A			; Enable (Resume, Suspend) and SUDAV INTs
	INC	R0
	MOV	A, #00000001b
	MOVX	@R0, A	     		; Enable Auto Vectoring for USB interrupts
	MOV	R0, #LOW(OUT07IRQ)
	MOV	A, #0FFH
	MOVX	@R0, A			; Clear out any pending interrupts
	                                ; Now enable the main level
	MOV	EIE, #00000001b		; Enable INT2 = USB Interrupt (only) 		
        MOV	EI, #11000010b		; Enable interrupt subsystem: Timer 0 overflow
					;   (and Ser1 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	Temp, #100
Wait1msec:				; A delay loop
	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	Temp, Wait1msec
	RET

ProcessOutputReport:		  	; A Report has just been received
; The report is six bytes long
; Save the values for the INTERRUPT service routine
	MOV	R0, #LightValues	; Initialize the pointers to be used
	MOV	DPTR, #EP0OutBuffer	; Point to the Report
	MOV	R7, #6
CopyOR:	MOVX	A, @DPTR		; Retrieve Report Byte 1
	MOV	@R0, A
	INC	DPTR
	INC	R0
	DJNZ	R7, CopyOR
	RET

CreateInputReport:
; Not used in this example


⌨️ 快捷键说明

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