每次对应上电某个输出口,读取输入数据。若有输入,则检测输入,跳至相关按键处理;若无,则设置下次上电的输出口。
代码:
CLRHALTFLAG:
LD A,#0
LD (HALTTIME1),A
LD (HALTTIME0),A
LD A,(HALTFLAG)
AND A,#0111B
LD (HALTFLAG),A
SET #1,(PWM_CTRL)
SET #1,(PWM_CTRL)
ldpch SERVICEIO_OK
jmp SERVICEIO_OK
; RETS
SERVICEIO:
LDMAH #0
ld a,(scankeydelay)
cmp a,#0fh
jnz EXITIO
ld a,(scankeyline)
cmp a,#0001b
ldpch scankeyportb0
jz scankeyportb0
cmp a,#0010b
ldpch scankeyportb1
jz scankeyportb1
setportb0:
set #0,(data_pb)
clr #1,(data_pb)
ld a,#0001b
ld (scankeyline),a
ld a,#0000b
ld (scankeydelay),a
EXITIO:
LD A,#0000B
LD (KEYDELAY),A
ldpch SERVICEIO_OK
jmp SERVICEIO_OK
; RETS
scankeyportb0:
set #0,(data_pb)
clr #1,(data_pb)
ld a,(data_pa)
and a,#0111b
xor a,(KEYFLAGB0)
ldpch setportb1
jz setportb1
ld a,(data_pa)
and a,#0111b
cmp a,(keybutfer)
ldpch scankeyportb00
jz scankeyportb00
ld (keybutfer),a
ldpch EXITIO
jmp EXITIO
scankeyportb00:
CLR #1,(PWM_CTRL)
CLR #1,(PWM_CTRL)
LD A,(KEYDELAY)
AND A,#0010B
;;;;;;;;2*8=16MS
JZ CLRHALTFLAG
LD A,#0000B
LD (KEYDELAY),A
LD A,(KEYBUTFER)
XOR A,(KEYFLAGB0)
AND A,(KEYBUTFER)
LD (KEYLFLAG),A
LD A,(KEYBUTFER)
LD (KEYFLAGB0),A
LD A,(KEYLFLAG)
AND A,#0001B
ldpch key01rin
JNZ key01rin
ld a,(keyflag)
and a,#0001b
jz CLRHALTFLAG
LD A,(KEYLFLAG)
AND A,#0010B
jnz key02rin
LD A,(KEYLFLAG)
AND A,#0100B
jnz key03rin
JMP CLRHALTFLAG;;;;;FALL KEY MASK
setportb1:
set #1,(data_pb)
clr #0,(data_pb)
ld a,#0010b
ld (scankeyline),a
ld a,#0000b
ld (scankeydelay),a
ldpch EXITIO
jmp EXITIO
scankeyportb1:
set #1,(data_pb)
clr #0,(data_pb)
ld a,(data_pa)
and a,#0111b
xor a,(KEYFLAGB1)
ldpch setportb0
jz setportb0
ld a,(data_pa)
and a,#0111b
cmp a,(keybutfer)
ldpch scankeyportb10
jz scankeyportb10
ld (keybutfer),a
ldpch EXITIO
jmp EXITIO
scankeyportb10:
CLR #1,(PWM_CTRL)
CLR #1,(PWM_CTRL)
LD A,(KEYDELAY)
AND A,#0010B
;;;;;;;;2*8=16MS
JZ CLRHALTFLAG
LD A,#0000B
LD (KEYDELAY),A
LD A,(KEYBUTFER)
XOR A,(KEYFLAGB1)
AND A,(KEYBUTFER)
LD (KEYLFLAG),A
LD A,(KEYBUTFER)
LD (KEYFLAGB1),A
ld a,(keyflag)
and a,#0001b
jz CLRHALTFLAG
LD A,(KEYLFLAG)
AND A,#0001B
ldpch key04rin
JNZ key04rin
LD A,(KEYLFLAG)
AND A,#0010B
jnz key05rin
LD A,(KEYLFLAG)
AND A,#0100B
jnz key06rin
JMP CLRHALTFLAG;;;;;FALL KEY MASK
;------------ 华丽的分割线 ------------
KEY01RIN:
scankeydelay 在每次中断时增加,为0fH时不再增加。
代码:
ld a,(scankeydelay)
cmp a,#0fh
jz scankeydelay_ok
inc (scankeydelay)
scankeydelay_ok: