📄 keyscan.asm
字号:
;.data
; @key_num equ xx ; the xx < 9, otherwise you must repair the routine
; @debounce_num equ #xx ; debounce time = xx * Systime base
; @keystate_set equ xx ; 0: Low voltage detect ; 1: High voltage detect
; @key_power_set equ xx ; 0: Don't care power ; 1 : care power
;@keyinbuf ds 1 ; store the temp key state when scanning
;@keychkbuf ds 1 ; store the key state
;@keycvtbuf ds 1
;@keyoldbuf ds 1
;@keyflag ds 1
; @keydown_f equ @keyflag.0
;@keychat ds 1
;@aplcode ds 1
; @key1_p equ px.x ; add at ram.asm
; @key1m_p equ pxm.x ; |
; @key2_p equ px.x ; |
; @key2m_p equ pxm.x ; |
; @key3_p equ px.x ; |
; @key3m_p equ pxm.x ; |
; @key4_p equ px.x ; |
; @key4m_p equ pxm.x ; |
; @key5_p equ px.x ; |
; @key5m_p equ pxm.x ; |
; @key6_p equ px.x ; |
; @key6m_p equ pxm.x ; |
; @key7_p equ px.x ; |
; @key7m_p equ pxm.x ; |
; @key8_p equ px.x ; |
; @key8m_p equ pxm.x ; add at ram.asm
;*******************************************************************************
; call Usage: chip support: ALL purpose: get key value *
; @@key_init: call at @@premain(if clear ram at com.asm, you can delete them)*
; @@mnkey: call at @@main *
; @@deckeychat: call at @@Intface5ms *
; @@Keyappl: call at @@main(key application, can add in Sys.asm) *
; @@key_powerdown: call at powerdown subroutine *
;Note: If detect Long time and short time key, you can set debounce time=long -*
; time, and wrtie a special routine to check short time key. *
;*******************************************************************************
;.code
;***********************************************
; Key scan data Initial *
;***********************************************
@@key_init:
clr @keyinbuf
clr @keychkbuf
clr @keycvtbuf
clr @keyoldbuf
clr @keyflag
clr @keychat
clr @aplcode
if @key_num > 8
error "Please check Key number!"
endif
ret
IF @key_power_set == 1
;**************************************
; Key power down setting *
;**************************************
@@key_powerdown:
if @keystate_set == 0
if @key_num > 0
b0bset @key1_p
endif
if @key_num > 1
b0bset @key2_p
endif
if @key_num > 2
b0bset @key3_p
endif
if @key_num > 3
b0bset @key4_p
endif
if @key_num > 4
b0bset @key5_p
endif
if @key_num > 5
b0bset @key6_p
endif
if @key_num > 6
b0bset @key7_p
endif
if @key_num > 7
b0bset @key8_p
endif
endif
if @keystate_set == 1
if @key_num > 0
b0bclr @key1_p
endif
if @key_num > 1
b0bclr @key2_p
endif
if @key_num > 2
b0bclr @key3_p
endif
if @key_num > 3
b0bclr @key4_p
endif
if @key_num > 4
b0bclr @key5_p
endif
if @key_num > 5
b0bclr @key6_p
endif
if @key_num > 6
b0bclr @key7_p
endif
if @key_num > 7
b0bclr @key8_p
endif
endif
ENDIF
;**********************************
; key board scan *
;**********************************
@@mnkey:
call @@keyin ; read into @keyinbuf
call @@keychk ; read into checkbuf
call @@keycvt ; read into convertbuf
ret
;**********************************
; read into @keyinbuf *
;**********************************
@@keyin:
clr @keyinbuf
IF @keystate_set == 0 ;Low voltage detect!
if @key_num > 0
b0bclr @key1m_p ; |
b0bts1 @key1_p ; |
b0bset @keyinbuf.0 ; |
endif
if @key_num > 1
b0bclr @key2m_p ; |
b0bts1 @key2_p ; |
b0bset @keyinbuf.1 ; |
endif
if @key_num > 2
b0bclr @key3m_p ; |
b0bts1 @key3_p ; |
b0bset @keyinbuf.2 ; |
endif
if @key_num > 3
b0bclr @key4m_p ; |
b0bts1 @key4_p ; |
b0bset @keyinbuf.3 ; |
endif
if @key_num > 4
b0bclr @key5m_p ; |
b0bts1 @key5_p ; |
b0bset @keyinbuf.4 ; |
endif
if @key_num > 5
b0bclr @key6m_p ; |
b0bts1 @key6_p ; |
b0bset @keyinbuf.5 ; |
endif
if @key_num > 6
b0bclr @key7m_p ; |
b0bts1 @key7_p ; |
b0bset @keyinbuf.6 ; |
endif
if @key_num > 7
b0bclr @key8m_p ; |
b0bts1 @key8_p ; |
b0bset @keyinbuf.7 ; |
endif
ENDIF
IF @keystate_set == 1 ; High voltage detect
if @key_num > 0
b0bclr @key1m_p ; |
b0bts0 @key1_p ; |
b0bset @keyinbuf.0 ; |
endif
if @key_num > 1
b0bclr @key2m_p ; |
b0bts0 @key2_p ; |
b0bset @keyinbuf.1 ; |
endif
if @key_num > 2
b0bclr @key3m_p ; |
b0bts0 @key3_p ; |
b0bset @keyinbuf.2 ; |
endif
if @key_num > 3
b0bclr @key4m_p ; |
b0bts0 @key4_p ; |
b0bset @keyinbuf.3 ; |
endif
if @key_num > 4
b0bclr @key5m_p ; |
b0bts0 @key5_p ; |
b0bset @keyinbuf.4 ; |
endif
if @key_num > 5
b0bclr @key6m_p ; |
b0bts0 @key6_p ; |
b0bset @keyinbuf.5 ; |
endif
if @key_num > 6
b0bclr @key7m_p ; |
b0bts0 @key7_p ; |
b0bset @keyinbuf.6 ; |
endif
if @key_num > 7
b0bclr @key8m_p ; |
b0bts0 @key8_p ; |
b0bset @keyinbuf.7 ; |
endif
ENDIF
ret
;********************************************
; check @keyinbuf and @keychkbuf *
;********************************************
@@keychk:
mov a,@keyinbuf
xor a,@keychkbuf
jnz @@keychk10 ; jmp if not same
; same
bts1 @keydown_f
jmp @@keychk90 ; end
; wait chatter
mov a,@keychat
jnz @@keychk90
; key bounce time = 0 , copy chk buf into cvt buf
mov_ @keycvtbuf,@keychkbuf
bclr @keydown_f ; clr @keyflag
jmp @@keychk90
; different
@@keychk10:
bclr have_key /////add
mov_ @keychkbuf,@keyinbuf
bset @keydown_f ; set @keyflag.0
mov_ @keychat,@debounce_num
@@keychk90:
ret
;****************************************************************
; compare @@keycvt and keyold and find the difference *
;****************************************************************
@@keycvt:
mov a,@keycvtbuf
cmprs a,@keyoldbuf
jmp @@keycvt00
jmp @@keycvt90 ; same, exit
; check the new pressed key from table
@@keycvt00:
mov_ @keyoldbuf,@keycvtbuf
;----------------------------------------------------------------
mov @aplcode,a
cmprs a,#0
jmp $+2
jmp @@keycvt90
bset have_key
@@keycvt90:
ret
;**********************************
; key debounce check *
;**********************************
@@deckeychat:
bts1 @keydown_f
jmp @@deckeychat90
mov a,@keychat
jz @@deckeychat90
decms @keychat ; @keychat--
jmp @@deckeychat90
@@deckeychat90:
ret
;**********************************
; Key application *
;**********************************
@@Keyappl:
bts1 have_key
jmp @@keyappl70
mov a,@aplcode
and a,#00011110b
jz @f
cmprs a,#00000010b
jmp $+2
jmp fast_forward_process
cmprs a,#00000100b
jmp $+2
jmp forward_process
cmprs a,#00001000b
jmp $+2
jmp low_backward_process
cmprs a,#00010000b
jmp $+2
jmp backward_process
@@: mov a,#0
@@Keyappl10:
mov remote_rambuf,a
mov a,@aplcode
and a,#00100001b
cmprs a,#00000001b
jmp $+2
jmp left_process
cmprs a,#00100000b
jmp $+2
jmp right_process
mov a,#0
or a,remote_rambuf
@@keyappl20:
mov remote_rambuf,a
mov a,@aplcode
and a,#00111111b
jnz @@keyappl30
mov a,@aplcode
and a,#11000000b
cmprs a,#01000000b
jmp $+2
jmp up_process
cmprs a,#10000000b
jmp $+2
jmp down_process
; jmp @@keyappl30
@@keyappl30:
mov a,ID_code_val
and a,#11000000b
or remote_rambuf,a
jmp @@keyappl90
@@keyappl70:
clr @aplcode
clr remote_rambuf
@@keyappl90:
ret
up_process:
mov_ remote_rambuf,#00011000b
jmp @@Keyappl30
down_process:
mov_ remote_rambuf,#00100000b
jmp @@Keyappl30
left_process:
mov a,#00001000b
or remote_rambuf,a
jmp @@Keyappl30
right_process:
mov a,#00010000b
or remote_rambuf,a
jmp @@Keyappl30
fast_forward_process:
mov a,#00000010b
jmp @@Keyappl10
forward_process:
mov a,#00000001b
jmp @@Keyappl10
low_backward_process:
mov a,#00000011b
jmp @@Keyappl10
backward_process:
mov a,#00000100b
jmp @@Keyappl10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -