📄 main.asm
字号:
include body.inc
include usbrf1.inc
include usbFIFO.inc
extern ext_start :near ;usb_int.asm
extern Ram_init :near ;usb_proc.asm
extern Timer1_ISR :near ;readwrite.asm
extern VAR_init :near
extern User_Action :near
extern ISR_USB_ACC :byte ;usb_int.asm
extern baddr_state :bit ;variable.asm
extern bCfgValue :bit
extern bwdt_timeout :bit
extern bwait_setup :bit
extern bRmtWakeup :bit
extern STALL :byte
extern temp1 :byte
extern temp2 :byte
PIPE_CTRL EQU [041H]
main .section at 0 'code'
org 0
;check to flag, if z=0, wdt overflow
mov a,status
and a,00110000b
xor a,00110000b
jmp main_start
;---------------------------------------------------------------------------------------------
org 04h ;usb interrut subroutine
clr wdt
MOV ISR_USB_ACC,A ;Save ACC
MOV A,STATUS ;Save STATUS
jmp EXT_start ;usb_int.asm
;----------------------------------------------------------------------------------------------
org 8h ;steal the int1 subroutine space for another procedure
;wait_27intr
wait_28us:
mov a,8
wait_28us_cont:
sdz acc
jmp wait_28us_cont
;wait_4instr
wait_4us:
ret
;----------------------------------------------------------------------------------------------
org 0ch ;timer1 interrupt subroutine for UART polling
;*******************************
; timer 1 interrupt vector
;*******************************
jmp Timer1_ISR
reti
;-----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------
; main program here
;-----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------
main_start:
snz z
jmp main_start_cont
;----------------------------------------------------------------------------------------------
watchdog_timout:
clr wdt
clr sel_ps2_line ; usr.4, not working under ps2 mode
clr sel_usb_line ; usr.5, not working under usb mode
clr chk_usb_reset_event ; usc.2, USB bus reset event flag
set bwdt_timeout
call wait_about_1s
;----------------------------------------------------------------------------------------------
main_start_cont:
clr wdt
mov a,10000111b
mov WDTS,a
call Ram_init ; rf_proc.asm
;********************************
; initial your own variables here
;********************************
call VAR_init
;-------------------------------------------------------------------------------------------
;********************************
;Timer1 overflow per 4ms
;********************************
mov a,10000000b
mov tmr1c,a
mov a,090h
mov tmr1L,a
mov a,0E8h
mov tmr1H,a ;about 4ms for 6MHz
;********************************
; set for 6m, clr for 12mz
;********************************
set SCC.6 ; for 6MHz
;---------------------------------------------------------------------------------
set baddr_state ; USB in address state
set bwait_setup
set STALL
mov a,1
mov bp,a
mov a, 41H
mov mp1,a
clr r1.2
CLR PIPE_CTRL.2
clr bp
set on_usb_clk ; enable usb clock
clr sel_ps2_line
set sel_usb_line ; set usb mode
mov a,00001011b ; enable usb, timer1 interrupt
mov intc,a
;------------------------------------------------------------------------------------------------
mainloop:
clr wdt
sz suspend_line ; USC.0=1, USB enter suspend mode
jmp Tosuspend
;********************************
; Start to do your action when usb is ready
;********************************
sz bcfgvalue ; usb plug in, (set configuration complete)
call User_Action
JMP MainLoop ; No
;-----------------------------------------------------------------------------------
ToSuspend:
clr timer1_on
clr bwdt_timeout
call wait_about_1s
;------------------------------------------------------------------------------------------
ToSuspend_again:
snz suspend_line ;about 850
jmp exit_of_suspend
sz resume_line ;;; 2008/06/12
jmp exit_of_suspend
clr on_usb_clk
halt
;------------------------------------------------------------------------------------------
RemoteWakeup:
set on_usb_clk
;remote wakeup
;wakeup by system, suspend_line=0, resume_line=1;
;wakeup by device, suspend_line=1(remote wakeup), resume_line=0;
;out wakeup pulse
;if(suspend_line && !resume_line)
snz suspend_line
jmp exit_of_suspend
sz resume_line
jmp exit_of_suspend
snz bRmtWakeup
jmp ToSuspend_again
;wakeup pulse
set wakeup_line
call wait_4us
clr wakeup_line
exit_of_suspend:
set timer1_on
jmp mainloop
;----------------------------------------------------------------------------------------------
; wait 1 s
; 1. delay 1 sec before entering suspend mode.
; if not do so, system will not function properly
; 2. when wdt overflow, wait 1 s to simulate a replug action
wait_about_1s:
;about wait_3s for 6MHz crystal
mov a,4
mov temp2,a
set temp1
set acc
wait_3s:
clr wdt
sz bwdt_timeout ;for watchdog time-out
jmp $+3
snz suspend_line ;about 1ms
ret
sdz acc
jmp wait_3s
sdz temp1
jmp wait_3s ;260ms
sdz temp2
jmp wait_3s
ret
;---------------------------------------------------------------------------------------------
public wait_28us
public wait_4us
public wait_28us_cont
end
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -