📄 3100_2interface.asm
字号:
;==================================================================================================
;
; Include Definitions
;
;==================================================================================================
;==================================================================================================
;
; Register Definitions
;
;==================================================================================================
;--------F-Plane Register Files---------------------------------------
Indf equ 00h
Timer0 equ 01h
Pc equ 02h
Psw equ 03h
Status equ 03h
Fsr equ 04h ;file select register bit6 ~ bit0
Pae equ 05h ;port a output enable bit7 ~ bit4 1:out 0:in
Pad equ 05h ;port a output data bit3 ~ bit0
Pbd equ 06h ;port b output data bit3 ~ bit0
Led equ 07h ;led output
Ksol equ 08h ;key scan output[07 ~ 00]
Ksoh equ 09h ;key scan output[15 ~ 08]
Ksi equ 0ah ;key scan input[07 ~ 00] //R
Pdd equ 0dh
Gpr0 equ 0eh ;general purpose register0
Gpr1 equ 0fh ;general purpose register1
UsbFun equ 10h ;USB function address bit6 ~ bit0 bit7 is USB function enable
Int0 equ 11h
Int1 equ 12h
Int2 equ 13h
UsbCtr equ 13h
Rc0Cnt equ 14h ;received data byte count bit3 ~ bit0
Tx0Reg equ 15h
Tx0Cnt equ 15h ;endpoint 0 transmit byte count bit3 ~ bit0
Tx1Reg equ 16h
Tx1Cnt equ 16h ;endpoint 1 transmit byte count bit3 ~ bit0
Tx2Reg equ 17h
Tx2Cnt equ 17h ;endpoint 2 transmit byte count bit3 ~ bit0
Rc0Fifo equ 18h ;18h ~ 1fh endpoint 0 receive buffer(8 bytes)
;definitions for SETUP packets
Rc0Fifo0 equ 18h
Rc0Fifo1 equ 19h
Rc0Fifo2 equ 1ah
Rc0Fifo3 equ 1bh
Rc0Fifo4 equ 1ch
Rc0Fifo5 equ 1dh
Rc0Fifo6 equ 1eh
Rc0Fifo7 equ 1fh
;--------R-Plane Register Files---------------------------------------
Tm0Reload equ 01h ;Timer0 overflow reload value
Tm0Pscl equ 02h ;Timer0 Pre-Scale, 0:div2,7:div256,8:div1
PwrDown equ 03h ;write this register to enter Power-Down Mode
WdtEn equ 04h ;write this register to clear WDT and enable WDT
KbdMask equ 05h ;mask KSI[7:0] interrupt function while the corresponding bit is "1"
TestReg equ 0fh ;Test Mode option
IntEn0 equ 11h
IntEn1 equ 12h
Tx0Fifo equ 18h ;18h ~ 1fh endpoint 0 transmit buffer(8 bytes)
Tx0Fifo0 equ 18h
Tx0Fifo1 equ 19h
Tx0Fifo2 equ 1ah
Tx0Fifo3 equ 1bh
Tx0Fifo4 equ 1ch
Tx0Fifo5 equ 1dh
Tx0Fifo6 equ 1eh
Tx0Fifo7 equ 1fh
Tx1Fifo equ 20h ;20h ~ 27h endpoint 1 transmit buffer(8 bytes)
Tx1Fifo0 equ 20h
Tx1Fifo1 equ 21h
Tx1Fifo2 equ 22h
Tx1Fifo3 equ 23h
Tx1Fifo4 equ 24h
Tx1Fifo5 equ 25h
Tx1Fifo6 equ 26h
Tx1Fifo7 equ 27h
Tx2Fifo equ 28h ;28h ~ 2fh endpoint 2 transmit buffer(8 bytes)
Tx2Fifo0 equ 28h
Tx2Fifo1 equ 29h
Tx2Fifo2 equ 2ah
Tx2Fifo3 equ 2bh
Tx2Fifo4 equ 2ch
Tx2Fifo5 equ 2dh
Tx2Fifo6 equ 2eh
Tx2Fifo7 equ 2fh
;==================================================================================================
;
; Define Bit Definitions
;
;==================================================================================================
;--------F-Plane Register Files---------------------------------------
RomPage defstring 03h,6
RamBank defstring 03h,4
Zero defstring 03h,2
DCarry defstring 03h,1
Carry defstring 03h,0
Data defstring 06h,0
Clock defstring 06h,1
UsbEn defstring 10h,7
Rc0i defstring 11h,7 ;endpoint 0 receive interrupt flag,write 0 to clear flag
Tx0i defstring 11h,6 ;endpoint 0 transmit interrupt flag,write 0 to clear flag
Tx1i defstring 11h,5 ;endpoint 1 transmit interrupt flag,write 0 to clear flag
Tx2i defstring 11h,4 ;endpoint 2 transmit interrupt flag,write 0 to clear flag
Rsti defstring 11h,3 ;usb bus reset interrupt flag,write 0 to clear flag
Suspi defstring 11h,2 ;usb suspend interrupt flag,write 0 to clear flag
Rsmi defstring 12h,3 ;usb resume interrupt flag,write 0 to clear flag
Kbdi defstring 12h,2 ;keyboard interrupt flag,write 0 to clear flag
Pb0i defstring 12h,1 ;mouse interrupt flag,write 0 to clear flag
Tm0i defstring 12h,0 ;timer0 interrupt flag,write 0 to clear flag
Suspend defstring 13h,7 ;s/w force usb interface into suspend mode
Resume defstring 13h,6 ;s/w force usb interface send RESUME signal in suspend mode
Ep1Cfg defstring 13h,5 ;set endpoint 1 configed
Ep2Cfg defstring 13h,4 ;set endpoint 2 configed
CtrRdy defstring 13h,3 ;H/W will stall an invalid out token during control read transfer
Rc0Rdy defstring 13h,0 ;endpoint 0 ready for receive,clear by H/W while RC0I occurs
Rc0Tgl defstring 14h,7 ;1:received DATA1 packet; 0:received DATA0 packet //R
Rc0Err defstring 14h,6 ;endpoint 0 received data error //R
Ep0Dir defstring 14h,5 ;1:in transfer; 0:out/setup transfer //R
Ep0Set defstring 14h,4 ;SETUP Token indicator //R
Tx0Rdy defstring 15h,7 ;endpoint 0 ready for transmit,clear by H/W while TX0I occurs
Tx0Tgl defstring 15h,6 ;endpoint 0 transmit DATA1/DATA0 packet
Ep0Stall defstring 15h,5 ;endpoint 0 will stall OUT/IN packet
Tx1Rdy defstring 16h,7 ;endpoint 1 ready for transmit,clear by H/W while TX1I occurs
Tx1Tgl defstring 16h,6 ;endpoint 1 transmit DATA1/DATA0 packet
Ep1Stall defstring 16h,5 ;endpoint 1 will stall IN packet
Tx2Rdy defstring 17h,7 ;endpoint 2 ready for transmit,clear by H/W while TX2I occurs
Tx2Tgl defstring 17h,6 ;endpoint 2 transmit DATA1/DATA0 packet
Ep2Stall defstring 17h,5 ;endpoint 2 will stall IN packet
;--------R-Plane Register Files---------------------------------------
Rc0ie defstring 11h,7 ;RC0I interrupt enable
Tx0ie defstring 11h,6 ;TX0I interrupt enable
Tx1ie defstring 11h,5 ;TX1I interrupt enable
Tx2ie defstring 11h,4 ;TX2I interrupt enable
Rstie defstring 11h,3 ;RSTI interrupt enable
Suspie defstring 11h,2 ;SUSPI interrupt enable
Ps2Sel defstring 12h,4
Rsmie defstring 12h,3 ;RSMI interrupt enable
Kbdie defstring 12h,2 ;KeyBoard interrupt enable
Pb0ie defstring 12h,1 ;Mouse interrupt enable
Tm0ie defstring 12h,0 ;Timer0 interrupt enable
;--------Gpr0 Bit Definitions------------------------------
NewAdrFlag defstring 0eh,7 ;
TableSelBit defstring 0eh,6 ;
SystemKeyFlag defstring 0eh,5 ;
SuspendFlag defstring 0eh,4 ;
Rc0Flag defstring 0eh,3 ;
Tx0Flag defstring 0eh,2 ;
; defstring 0eh,1 ;
StartScanFlag defstring 0eh,0 ;
;--------Gpr1 Bit Definitions------------------------------
DataInFlag defstring 0fh,7 ;
CommandOutFlag defstring 0fh,6 ;
DataOutFlag defstring 0fh,5 ;
; defstring 0fh,4 ;
; defstring 0fh,3 ;
; defstring 0fh,2 ;
; defstring 0fh,1 ;
; defstring 0fh,0
;==================================================================================================
;
; Constant Definition
;
;==================================================================================================
;------------------------------------------------------------------------
; Normal Constant Definition
;------------------------------------------------------------------------
W equ 00h
F equ 01h
ScanInterval equ 3ch
;------------------------------------------------------------------------
; For USB Constant Definition
;------------------------------------------------------------------------
;--------Rc0Fifo Types Files-----------------------------------------
BmRequestType equ 18h
BRequest equ 19h
WValue equ 1ah ;default wValue (8-bits)
WValueHi equ 1bh
WIndex equ 1ch ;default wIndex (8-bits)
WIndexHi equ 1dh
WLength equ 1eh ;default wLength (8-bits)
WLengthHi equ 1fh
;--------Define BmRequestType Types Files----------------------------
HostToDevice equ 00h
HostToInterface equ 01h
HostToEndpoint equ 02h
DeviceToHost equ 80h
InterfaceToHost equ 81h
EndpointToHost equ 82h
;--------Define BRequest Types Files---------------------------------
GetStatus equ 00h
ClearFeature equ 01h
;GetIdle equ 02h
SetFeature equ 03h
SetAddress equ 05h
GetDescriptor equ 06h
GetConfiguration equ 08h
SetConfiguration equ 09h
GetInterface equ 0ah
SetInterface equ 0bh
;--------Standard Descriptor Types-----------------------------------
Device equ 01h
Configuration equ 02h
String equ 03h
Interface equ 04h
Endpoint equ 05h
HidClass equ 21h
HidReport equ 22h
String0 equ 00h
String1 equ 01h
String2 equ 02h
String3 equ 03h
Report1 equ 00h
Report2 equ 01h
;------------------------------------------------------------------------
; For HID Constant Definition
;------------------------------------------------------------------------
;-class specific descriptor types from section 7.1 Standard Requests-
HidGetRequest equ a1h
HidSetRequest equ 21h
;-class specific request codes from section 7.2 Class Specific Requests
GetReport equ 01h
GetIdle equ 02h
GetProtocol equ 03h
SetReport equ 09h
SetIdle equ 0ah
SetProtocol equ 0bh
;--------------------------------------
UnConfig equ 00h
Config equ 01h
;ReportType
InputValue equ 01h
OutputValue equ 02h
FeatureValue equ 03h
StallValue equ 01h
DisableRemoteWakeup equ 00h
EnableRemoteWakeup equ 02h
Endpoint0 equ 80h
Endpoint1 equ 81h
Endpoint2 equ 82h
Interface1 equ 00h
Interface2 equ 01h
BootProtocol equ 00h
ReportProtocol equ 01h
SystemKeyID equ 02h
DefaultIdlePeriod equ 7dh
DeviceLen equ 12h
String0Len equ 04h
HidClass1Len equ 09h
ConfigLen defstring (String0Table-ConfigDescTable)
String2Len defstring (EndDeviceInfoTable-String2Table)
HidReport1Len defstring (Report2DescTable-Report1DescTable)
HidReport2Len defstring (EndDeviceReportTable-Report2DescTable)
ConfigIndex defstring (ConfigDescTable-DeviceDescTable)
Strind0Index defstring (String0Table-DeviceDescTable)
Strind2Index defstring (String2Table-DeviceDescTable)
HidClass1Index defstring (Class1DescTable-DeviceDescTable)
HidReport2Index defstring (Report2DescTable-Report1DescTable)
;------------------------------------------------------------------------
; For Gamepad Constant Definition
;------------------------------------------------------------------------
Columns equ 04h
DebounceBufferEmpty equ ffh
UsbNoReport equ 00h
UsbReportError equ 01h
UsbReport equ 02h
DebounceTimes equ 04h
KeyPress equ ffh
KeyRelease equ 00h
;--------Rambank0 Register Files (20h~7fh)---------------------------
;================== For USB Only===========================
StateTemp0 equ 20h
StateTemp1 equ 21h
;CountTemp equ 22h
WLengthTemp equ 23h
LengthCnt equ 24h
TableCnt equ 25h
DataLength equ 26h
RemoteWakeupStatus equ 27h
ConfigurationStatus equ 28h
Endpoint1Status equ 29h
Endpoint2Status equ 2ah
HidProtocolStatus equ 2bh
IdlePeriodStatus equ 2ch
UsbCountTemp equ 2dh
UsbRequireState equ 2eh
UsbDataTemp equ 2fh
IdlePeriodTemp equ 30h
UsbLedDataTemp equ 31h
DelayCount_us equ 32h
AnyCountTemp equ 33h
Function0Temp equ 34h
Function1Temp equ 35h
ReportDataLength equ 36h
InOutBuffer equ 38h
InOutBuffer0 equ 38h
InOutBuffer1 equ 39h
InOutBuffer2 equ 3ah
InOutBuffer3 equ 3bh
InOutBuffer4 equ 3ch
InOutBuffer5 equ 3dh
InOutBuffer6 equ 3eh
InOutBuffer7 equ 3fh
DataBuffer equ 40h ;40h~4fh
;--------Rambank1 Register Files (20h~7fh)---------------------------
;==============================================================================
;Macro:Delay_us Macro Files
;
;
;==============================================================================
Delay_us .MAC Time ;Delay "Cycles" instruction cycles
.IF (Time+0=1)
goto $ + 1
nop
.EXITMAC
.ENDIF
.IF (Time+0=2)
goto $ + 1
goto $ + 1
nop
.EXITMAC
.ENDIF
.IF (Time+0=3)
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
.EXITMAC
.ENDIF
.IF (Time+0=4)
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
nop
.EXITMAC
.ENDIF
.IF (Time+0=5)
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
.EXITMAC
.ENDIF
.IF (Time+0=6)
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
.EXITMAC
.ENDIF
.IF (Time+0=7)
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
goto $ + 1
nop
.EXITMAC
.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 Kbdi
goto KbdiTask
btfsc Pb0i
goto Pb0iTask
btfsc Rsmi
goto RsmiTask
btfsc Suspi
goto SuspiTask
goto EndInt
;==============================================================================
;Function:Rc0iTask
; Set RcoFlag and prepare to 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -