A SERVICE OF

logo

Cypress CY3640 USB Starter Kit
User’s Guide
Cypress Semiconductor Ver 0.993
Page 22
iord USBControl ; Read the USB Status and Control Reg
and a,01h ; Check bit 0
cmp a,0h
jz Inc_Counter ; Hmm! No activity. Branch and keep track of it.
iord USBControl ; Ah! There was activity,
; clear the bus activity bit
and a,0feh
iowr USBControl
mov a,0 ; Clear the suspend counter
mov [gbSuspendCount],a
jmp Suspend_End
Inc_Counter: ; Monitor the IDLE count
mov a,[gbSuspendCount] ; Get # of mSec we have been IDLE
inc a ; Increment the count
mov [gbSuspendCount],a
cmp a,03h ; Has it been 3msec yet?
jnz Suspend_End ; Not yet, branch
mov a,0h ; Yes, clear the suspend counter
mov [gbSuspendCount],a
iord SysStatus
or a,08h ; Set the suspend bit to cause a suspend
iowr SysStatus ; We will enter the suspend state during
; the next instruction.
Suspend_End:
; Increment the 1024 usec counter and check for rollover
inc [gbSysTick1024us]
jnz STimerNo1024usRoll ; No
; Clear rollover
mov a,0
mov [gbSysTick1024usRoll],a
STimerNo1024usRoll:
; Are we counting down a button debounce
mov a,0
cmp a,[gbButtonDebounce]
jz STimerNoDebounce ; Not debouncing, branch
; Yes, we're debouncing. Let's see if we are timed out.
dec [gbButtonDebounce]
mov a,0
cmp a,[gbButtonDebounce]
; has debounce timed out?
jnz STimerNoDebounce ; No, still debouncing, branch.
; The debounce timer has timed out
; check if the button pin is at a 1. If not, the button is either still
; bouncing or still pushed
iord SysPort1 ; check the port the button is on
and a,Button_Pin ; check the pin
jnz STimerDebounceOver ; branch if it is not pushed ; mrr
; Reset debounce since the button is not yet released or is bouncing
mov a,100
mov [gbButtonDebounce],a
jnz STimerNoDebounce ; continue waiting for debounce to end
STimerDebounceOver:
; it's really ready!
; Toggle the button state flag to let the Windows app know that
; the button has been pushed.
mov a,1
xor [gbButtonPushed],a
; Debounce must be over
STimerNoDebounce:
; Enable interrupts and return
mov a,[gbSysInterruptMask]