📄 usb.asm
字号:
;*********************************************
;读取字符串3描述符
;*********************************************
mov a,(USBStringDescription3 -USBSendROMBufferBase)
mov [gbUSBSendBuffer],a
mov a,8h
mov [gbUSBSendBytes],a
call USBSendDescriptorCheckLength
call USBSendROMBuffer
jmp USBEventEP0End
USBEventEP0SetupGetDescriptorEnd:
jmp USBEventEP0Stall
;********************************************************
; USBSendDescriptorCheckLength()
;********************************************************
USBSendDescriptorCheckLength:
mov a,[EP0_FIFO.7]
cmp a,0
jnz USBSendDescriptorCheckLengthEnd
mov a,[EP0_FIFO.6]
cmp a,[gbUSBSendBytes]
jz USBSendDescriptorCheckLengthEnd
jnc USBSendDescriptorCheckLengthEnd
mov [gbUSBSendBytes],a
USBSendDescriptorCheckLengthEnd:
ret
;********************************************************
; USBSendROMBuffer()
;********************************************************
USBSendROMBuffer:
mov a,0h
iowr EP0_Rx_Status
mov a,USBC_StatusOuts
iowr USB_Control
mov a,0h
mov [gbUSBSendSequence],a
mov a,[gbUSBSendBytes]
USendROMBufferLoop:
cmp a,08h
jz USendROMBufferLoopDone
jc USendROMBufferLoopDone
push a
mov a,08h
mov [gbUSBSendBytes],a
call _USBSendROMBuffer
iord EP0_Rx_Status
and a,EP0_Rx_Out
pop a
jnz USendROMBufferLoopExit
sub a,08h
mov [gbUSBSendBytes],a
jmp USendROMBufferLoop
USendROMBufferLoopDone:
call _USBSendROMBuffer
USendROMBufferLoopExit:
ret
;********************************************************
; _USBSendROMBuffer()
;********************************************************
_USBSendROMBuffer:
push x
mov x,0h
_USendROMBufferLoop:
mov a,0h
cmp a,[gbUSBSendBytes]
jz _USendROMBufferLoopDone
dec [gbUSBSendBytes]
mov a,[gbUSBSendBuffer]
index USBSendROMBufferBase
mov [x +EP0_FIFO],a
inc x
inc [gbUSBSendBuffer]
jmp _USendROMBufferLoop
_USendROMBufferLoopDone:
mov a,0h
iowr EP0_Rx_Status
mov a,EP0_Tx_Toggle
xor [gbUSBSendSequence],a
push x
pop a
or a,[gbUSBSendSequence]
or a,EP0_Tx_Respond
iowr EP0_Tx_Config
call USBSendWaitForComplete
_USendROMBufferEnd:
pop x
ret
;********************************************************
;USBEventEP0VendorRqst()
;********************************************************
USBEventEP0VendorRqst:
push x
mov a,[EP0_FIFO.1]
USBEventEP0VendorRqstReadROM:
cmp a,01h
jnz USBEventEP0VendorRqstReadRAM
;***********************************************************
;读取程序存储器ROM的数据代码段(描述符部分),命令代码为:01h
;***********************************************************
mov a,[EP0_FIFO.2]
index USBSendROMBufferBase
mov [EP0_FIFO.1],a
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstReadRAM:
cmp a,02h
jnz USBEventEP0VendorRqstWriteRAM
;*********************************************
;读取数据存储器RAM的内容,命令代码为:02h
;*********************************************
mov a,[EP0_FIFO.2]
push a
pop x
mov a,[x +0]
mov [EP0_FIFO.1],a
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstWriteRAM:
cmp a,03h
jnz USBEventEP0VendorRqstReadPort
;*********************************************
;把数据写入数据存储器RAM中,命令代码为:03h
;*********************************************
mov a,[EP0_FIFO.2]
push a
pop x
mov a,[EP0_FIFO.4]
mov [x +0],a
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstReadPort:
cmp a,04h
jnz USBEventEP0VendorRqstWritePort
;*********************************************
;读取CY7C63001A I/O端口的值,命令代码为:04h
;*********************************************
mov a,[EP0_FIFO.2]
cmp a,0h
jnz USBEventEP0VendorRqstReadPort1
USBEventEP0VendorRqstReadPort0:
iord P0_Data
jmp USBEventEP0VendorRqstReadPortsDone
USBEventEP0VendorRqstReadPort1:
iord P1_Data
;jmp USBEventEP0VendorRqstReadPortsDone
USBEventEP0VendorRqstReadPortsDone:
mov [EP0_FIFO.1],a
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstWritePort:
cmp a,05h
jnz USBEventEP0VendorRqstReadTemperature
;*********************************************
;向CY7C63001A的I/O端口写入数据,命令代码为:05h
;*********************************************
mov a,[EP0_FIFO.2]
cmp a,0
jnz USBEventEP0VendorRqstWritePort1
USBEventEP0VendorRqstWritePort0:
mov a,[EP0_FIFO.4]
iowr P0_Data
jmp USBEventEP0VendorRqstWritePortsDone
USBEventEP0VendorRqstWritePort1:
mov a,[EP0_FIFO.4]
or a,04h
iowr P1_Data
mov [LEDControl],a
;jmp USBEventEP0VendorRqstWritePortsDone
USBEventEP0VendorRqstWritePortsDone:
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstReadTemperature:
cmp a,06h
jnz USBEventEP0VendorRqstSetLED2Brightness
;*********************************************
;读取系统当前的温度,命令代码为:06h
;*********************************************
mov a,[gbThermTempHigh]
mov [EP0_FIFO.1],a
mov a,[gbThermTempLow]
mov [EP0_FIFO.2],a
mov a,[gbButtonPushed]
mov [EP0_FIFO.3],a
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstSetLED2Brightness:
cmp a,07h
jnz USBEventEP0VendorRqstReadDS1620TH
;*********************************************
;设置LED2的亮度,命令代码为:07h
;*********************************************
mov a,1
mov [gbLEDBrightnessUpdate],a
mov a,[EP0_FIFO.2]
mov [gbLEDBrightness],a
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstReadDS1620TH:
cmp a,08h
jnz USBEventEP0VendorRqstSetDS1620TH
;*********************************************
;读取DS1620 TH的值,命令代码为:08h
;*********************************************
mov a,ThermReadTempHigh
Call ThermPortRead9
mov a,[gbThermDataValueHigh]
mov [EP0_FIFO.1],a
mov a,[gbThermDataValueLow]
mov [EP0_FIFO.2],a
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstSetDS1620TH:
cmp a,09h
jnz USBEventEP0VendorRqstReadDS1620TL
;*********************************************
;设置DS1620 TH的值,命令代码为:09h
;*********************************************
mov a,[EP0_FIFO.3]
mov [gbThermTHValueHigh],a
mov a,[EP0_FIFO.2]
mov [gbThermTHValueLow],a
Call ThermSetTH
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstReadDS1620TL:
cmp a,0Ah
jnz USBEventEP0VendorRqstSetDS1620TL
;*********************************************
;读取DS1620 TL的值,命令代码为:0Ah
;*********************************************
mov a,ThermReadTempLow
Call ThermPortRead9
mov a,[gbThermDataValueHigh]
mov [EP0_FIFO.1],a
mov a,[gbThermDataValueLow]
mov [EP0_FIFO.2],a
jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstSetDS1620TL:
cmp a,0Bh
jnz USBEventEP0Stall
;*********************************************
;设置DS1620 TL的值,命令代码为:0Bh
;*********************************************
mov a,[EP0_FIFO.3]
mov [gbThermTLValueHigh],a
mov a,[EP0_FIFO.2]
mov [gbThermTLValueLow],a
Call ThermSetTL
;jmp USBEventEP0VendorRqstFinish
USBEventEP0VendorRqstFinish:
mov a,42h
mov [EP0_FIFO.0],a
mov a,USBC_StatusOuts
iowr USB_Control
mov a,8
or a,EP0_Tx_Toggle
or a,EP0_Tx_Respond
iowr EP0_Tx_Config
pop x
jmp USBEventEP0End
;********************************************************
; USBSend0DataAck()
;********************************************************
USBSend0DataAck:
mov a,EP0_Tx_Respond | EP0_Tx_Toggle
iowr EP0_Tx_Config
mov a,[gbInterruptMask]
iowr Global_Interrupt
jmp USBSendWaitForComplete
;********************************************************
; USBSendWaitForComplete()
;********************************************************
USBSendWaitForComplete:
iord EP0_Tx_Config
and a,EP0_Tx_Respond
jz USBSendWaitComplete
iord EP0_Rx_Status
and a,EP0_Rx_Out
jnz USBSendWaitComplete
jmp USBSendWaitForComplete
USBSendWaitComplete:
ret
;//////////////////////////////////USB_EP0_ISR end/////////////////////////////////////////////
include "DS1620.asm"
;********************************************************
; SysDelayMS()
;********************************************************
SysDelayMS:
push a
push x
SysDelayMSLoop:
push a
mov a,10
SysDelayMSLoopDelay:
push a
mov a,100
call SysDelayUS
pop a
dec a
jnz SysDelayMSLoopDelay
pop a
dec a
jnz SysDelayMSLoop
pop x
pop a
ret
;********************************************************
; SysDelayUS()
;********************************************************
SysDelayUS:
push a
push x
SysDelayUSLoop:
push a
pop a
dec a
jnz SysDelayUSLoop
pop x
pop a
ret
;********************************************************
;ROM数据段 Data Segment (ROM)
;********************************************************
USBSendROMBufferBase:
USBDeviceDescription:
db 12h
db 01h
db 10h,01h
db 00h
db 00h
db 00h
db 08h
db xxh,xxh ;xxxx-十六进制数
db xxh,xxh ;xxxx-十六进制数
db 01h,00h
db 01h
db 02h
db 00h
db 01h
USBDeviceDescriptionEnd:
;*************************************************
USBConfigurationDescription:
db 09h
db 02h
db 12h,00h
db 01h
db 01h
db 00h
db 80h
db 32h
USBConfigurationDescriptionEnd:
;*************************************************
USBInterfaceDescription:
db 09h
db 04h
db 00h
db 00h
db 00h
db 00h
db 00h
db 00h
db 00h
USBInterfaceDescriptionEnd:
;*************************************************
USBStringDescription0:
db 04h
db 03h
db 09h
db 01h
USBStringDescription1:
db 08h
db 03h
dsu "Ysu"
USBStringDescription2:
db 18h
db 03h
dsu "Thermometer"
USBStringDescription3:
db 08h
db 03h
dsu "Lyw"
;=====================文件完毕==========================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -