📄 counter.lst
字号:
000A 80 10 [05] jmp SysUnUsed ; Reserved
000C 80 99 [05] jmp SysGPIOEvent ; Button
000E 80 10 [05] jmp SysUnUsed ; CExt (not used)
0010
0010 ;*************************************************
0010 ; Unused event
0010 ; Do nothing, restore machine to prior state
0010 ;*************************************************
0010 SysUnUsed:
0010 2D [05] push a
0011 1A 20 [06] mov a,[gbSysInterruptMask]
0013 1E 20 [13] ipret SysInterrupt
0015
0015 ;//$PAGE
0015 ;*******************************************************************************
0015 ; main()
0015 ; @func Entry point after PowerOn, WatchDog timeout or WakeUp from sleeping.
0015 ; @comm Never returns
0015 ;*******************************************************************************
0015 main:
0015 ; This portion of Main is only executed after a RESET (Power-On or USB)
0015 ; Setup data stack in high order RAM, just below EP0 FIFO
0015 ; It will grow down from here
0015 19 70 [04] mov a,70h ; USBEndP0FIFO
0017 30 [05] swap a,dsp
0018
0018 ; Initialize both Ports high
0018 19 FF [04] mov a,FFh
001A 2A 00 [05] iowr SysPort0 ; Port 0 Data reg
001C 2A 01 [05] iowr SysPort1 ; Port 1 Data reg
001E ; 1 on P13 is needed to make sure enumerate LED is off
001E ; 1 on any port that needs to be an input
001E ; Enable Pullups (0=enable)
001E 19 00 [04] mov a,0
0020 2A 08 [05] iowr SysPort0PullUp
0022 19 04 [04] mov a,Button_Pin
0024 2A 09 [05] iowr SysPort1PullUp ; 1 on P12 is needed to make sure GPIO interrupt
0026 ; occurs on LOW to HIGH transistion. This
0026 ; disables it's pull up
0026
0026 ; Enable or disable interrupts on appropriate pins
0026 19 00 [04] mov a,0
0028 2A 04 [05] iowr SysPort0IntEnable ; All pins irq's are disabled on Port 0
002A 19 04 [04] mov a,Button_Pin
002C 2A 05 [05] iowr SysPort1IntEnable ; Enable P12, the button pin.
002E ; No interrupts will occur until the device
002E ; is enumerated. Then GPIO's will be enabled and
002E ; we will allow P12 to generate interrupts
002E
002E ; Initialize USB variables
002E 19 00 [04] mov a,0
0030 31 28 [05] mov [gbUSBSendSequence],a ; Start with a 0
0032
0032 ; Initialize Counter
0032 19 00 [04] mov a,0
0034 31 2D [05] mov [gbButtonClicks],a ; Initial state of 0, no button pushed
0036
0036 ; Initialize variables
0036 19 00 [04] mov a,0
0038 31 29 [05] mov [gbUSBSendBytes],a ; No bytes to send in FIFO buffers
003A 31 2B [05] mov [gbSuspendCount],a ; Reset bus activity to 0
003C 31 2C [05] mov [gbButtonDebounce],a ; We are not debouncing
003E
003E ; Set interrupt mask
003E 19 0C [04] mov a,SysIntTimer1024us | SysIntUSBEndP0
0040 31 20 [05] mov [gbSysInterruptMask],a
0042
0042 ;*********************************************
0042 MainLoop:
0042 ; Enable interrupts to current mask
0042 1A 20 [06] mov a,[gbSysInterruptMask]
0044 2A 20 [05] iowr SysInterrupt
0046
0046 ; Loop
0046 80 42 [05] jmp MainLoop
0048
0048 ;********************************************************
0048 ; SysTimer1024usEvent()
0048 ; @func Timer interrupt event ocurring every 1.024 mSec
0048 ; using 6Mhz crystal.
0048 ;********************************************************
0048 SysTimer1024usEvent:
0048
0048 ; Save accumulator
0048 2D [05] push a
0049
0049 ; Clear watchdog timer
0049 ; Clearing it here effectively disables the timer
0049 2A 21 [05] iowr SysWatchDog
004B
004B ; Keep track of length of any IDLE conditions (No bus activity)
004B 29 13 [05] iord USBControl ; Read the USB Status and Control Reg
004D 10 01 [04] and a,01h ; Check bit 0
004F 16 00 [04] cmp a,0h
0051 A0 5F [05] jz Inc_Counter ; Hmm! No activity. Branch and keep track of it.
0053 29 13 [05] iord USBControl ; Ah! There was activity,
0055 ; clear the bus activity bit
0055 10 FE [04] and a,0feh
0057 2A 13 [05] iowr USBControl
0059 19 00 [04] mov a,0 ; Clear the suspend counter
005B 31 2B [05] mov [gbSuspendCount],a
005D 80 72 [05] jmp Suspend_End
005F
005F Inc_Counter: ; Monitor the IDLE count
005F 1A 2B [06] mov a,[gbSuspendCount] ; Get # of mSec we have been IDLE
0061 21 [04] inc a ; Increment the count
0062 31 2B [05] mov [gbSuspendCount],a
0064 16 03 [04] cmp a,03h ; Has it been 3msec yet?
0066 B0 72 [05] jnz Suspend_End ; Not yet, branch
0068 19 00 [04] mov a,0h ; Yes, clear the suspend counter
006A 31 2B [05] mov [gbSuspendCount],a
006C 29 FF [05] iord SysStatus
006E 0D 08 [04] or a,08h ; Set the suspend bit to cause a suspend
0070 2A FF [05] iowr SysStatus ; We will enter the suspend state during
0072 ; the next instruction.
0072
0072 Suspend_End:
0072 ; Are we counting down a button debounce
0072 19 00 [04] mov a,0
0074 17 2C [06] cmp a,[gbButtonDebounce]
0076 A0 95 [05] jz STimerNoDebounce ; Not debouncing, branch
0078
0078 ; Yes, we're debouncing. Let's see if we are timed out.
0078 27 2C [07] dec [gbButtonDebounce]
007A 19 00 [04] mov a,0
007C 17 2C [06] cmp a,[gbButtonDebounce]
007E
007E ; has debounce timed out?
007E B0 95 [05] jnz STimerNoDebounce ; No, still debouncing, branch.
0080
0080 ; The debounce timer has timed out
0080 ; check if the button pin is at a 1. If not, the button is either still
0080 ; bouncing or still pushed
0080 29 01 [05] iord SysPort1 ; check the port the button is on
0082 10 04 [04] and a,Button_Pin ; check the pin
0084 A0 95 [05] jz STimerNoDebounce ; branch if it is not pushed
0086
0086 ; Reset debounce since the button is not yet released or is bouncing
0086 1A 2D [06] mov a,[gbButtonClicks]
0088 21 [04] inc a;
0089 31 2D [05] mov [gbButtonClicks],a
008B 31 78 [05] mov [USBEndP1FIFO_0],a
008D
008D 29 11 [05] iord USBEndP1TxConfig
008F 10 40 [04] and a,40h
0091 0D 91 [04] or a,91h
0093 2A 11 [05] iowr USBEndP1TxConfig
0095
0095 ; Debounce must be over
0095 STimerNoDebounce:
0095 ; Enable interrupts and return
0095 1A 20 [06] mov a,[gbSysInterruptMask]
0097 1E 20 [13] ipret SysInterrupt
0099
0099 ;//$PAGE
0099 ;********************************************************
0099 ; SysGPIOEvent()
0099 ; @func General purpose port event
0099 ; @comm Which pin?
0099 ;********************************************************
0099 SysGPIOEvent:
0099
0099 ; Save accumulator
0099 2D [05] push a
009A
009A ; Reset debounce any time we are here
009A 19 32 [04] mov a,50
009C 31 2C [05] mov [gbButtonDebounce],a
009E
009E SysGPIOButtonDebouncing:
009E ; Enable interrupts and return
009E 1A 20 [06] mov a,[gbSysInterruptMask]
00A0 1E 20 [13] ipret SysInterrupt
00A2
00A2 USBEndPoint1Event:
00A2
00A2 ; Save accumulator
00A2 2D [05] push a
00A3
00A3 29 11 [05] iord USBEndP1TxConfig
00A5 13 40 [04] xor a,40h
00A7 2A 11 [05] iowr USBEndP1TxConfig
00A9
00A9 ; Enable interrupts and return
00A9 1A 20 [06] mov a,[gbSysInterruptMask]
00AB 1E 20 [13] ipret SysInterrupt
00AD
00AD ;*******************************************************************************
00AD ;
00AD ; This section of code responds to activity on End Point 0 and determines
00AD ; what needs to be done.
00AD ;
00AD ;*******************************************************************************
00AD
00AD ;//$PAGE
00AD ;********************************************************
00AD ; USBEndPoint0Event()
00AD ; @func End Point zero USB event.
00AD ; @comm Default end point.
00AD ;********************************************************
00AD USBEndPoint0Event:
00AD
00AD ; This code checks to see what type of packet was received
00AD ; (Setup, Out, or In) and jumps to the correct routine to decode the
00AD ; specifics. After the code to which the jump points is through, it jumps
00AD ; back to USBEventEP0End.
00AD
00AD ; Save accumulator
00AD 2D [05] push a
00AE
00AE ; Is this a SETUP packet?
00AE 29 14 [05] iord USBEndP0RxStatus
00B0 10 01 [04] and a,USBEndP0RxSetup ; Check the setup bit
00B2 B0 C0 [05] jnz USBEventEP0_SETUP ; Yes it's a setup, branch
00B4
00B4 USBEventEP0End:
00B4 ; OK. We're done with the packet.
00B4 ; Let's enable interrupts and return
00B4 1A 20 [06] mov a,[gbSysInterruptMask]
00B6 1E 20 [13] ipret SysInterrupt ; done with EP0 irq service routine
00B8
00B8 USBEventEP0Stall:
00B8 ; Stall any subsequent IN's or OUT's until the
00B8 ; stall bit (bit 5) is cleard by an I/O write to
00B8 ; the USB End Point 0 TX Configuration Register (0x10)
00B8 ; or any SETUP is received.
00B8 29 10 [05] iord USBEndP0TxConfig
00BA 0D 20 [04] or a,USBEndP0TxStall
00BC 2A 10 [05] iowr USBEndP0TxConfig
00BE
00BE ; OK. We've set the stall condition for Endpoint 0.
00BE ; Now let's complete the routine.
00BE 80 B4 [05] jmp USBEventEP0End
00C0
00C0 ;*******************************************************************************
00C0 ;
00C0 ; We know we have received a Setup token. Now we need to parse it to
00C0 ; determine what command it is.
00C0 ;
00C0 ;*******************************************************************************
00C0
00C0 ;//$PAGE
00C0 ;*******************************************************************************
00C0 ; USBEventEP0_SETUP()
00C0 ; @func End point event SETUP packet handler.
00C0 ; @devnote Runs in interrupt enabled context.
00C0 ;********************************************************
00C0 USBEventEP0_SETUP:
00C0 ; Well, we have a SETUP packet. Let's find out what to do.
00C0 1A 20 [06] mov A,[gbSysInterruptMask]
00C2 2A 20 [05] iowr SysInterrupt
00C4
00C4 ; If we are here and are and we are processing a previous Setup,
00C4 ; we need to abort the processing of the previous Setup
00C4 19 00 [04] mov a,0 ; Clear any indication that we have bytes left to transfer
00C6 31 29 [05] mov [gbUSBSendBytes],a
00C8
00C8 ; Clear EP0 RxReg (including the Setup flag)
00C8 ; The Data toggle bit remains unchanged, however.
00C8 19 00 [04] mov a,0
00CA 2A 14 [05] iowr USBEndP0RxStatus
00CC
00CC ;*********************************************
00CC ; Setup Event
00CC ;*********************************************
00CC
00CC ; Check the request type and branch to the correct location to handle it.
00CC 1A 70 [06] mov a,[USBEndP0FIFO_0]
00CE
00CE USBEventEP0SetupTargetDeviceOUT:
00CE ; Target Device?
00CE 16 00 [04] cmp a,USBRqstTargetDevice
00D0 A0 F0 [05] jz USBEventEP0SetupIsSetAddress ; Yes
00D2
00D2 USBEventEP0SetupTargetInterfaceOUT:
00D2 16 01 [04] cmp a,USBRqstTargetInterface
00D4 A0 B8 [05] jz USBEventEP0Stall ; Yes. Oops! We don't have an interface.
00D6
00D6 USBEventEP0SetupTargetEndpointOUT:
00D6 16 02 [04] cmp a,USBRqstTargetEndPoint
00D8 A0 B8 [05] jz USBEventEP0Stall ; Yes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -