|
3鱼币
;==========================================
CLR KEY_CNT ;SET KEY-NO. = 0
CLR FIRST_KEY
CLR KEY_FLAG
MOV A,#0FFH
MOV LINES,A
NEXT_STROBE_:
INC LINES,LINES
CLR PCH
MOV A,LINES ; A = LINES
ADD A,#MOVOUT ; A = A + #MOVOUT
MOVC
JSR SET_PORTA
MOV A,TBDH
JSR SET_PORTB
KEY_DETECT_:
JSR DELAY8US
MOV A,#0FFH
MOV KEYTMP1,A
MOV KEYTMP2,A
MOV A,PORTA
MOV KEYLINES,A
SBS5 KEYLINES ;如果keylines[5]不等于0,跳过下一条指令
RMB0 KEYTMP1 ;0放入KEYTMP1[0]
SBS6 KEYLINES
RMB1 KEYTMP1 ;0放入KEYTMP1[1]
SBS4 KEYLINES
RMB2 KEYTMP1
MOV A,PORTB
MOV KEYLINES,A
SBS0 KEYLINES
RMB3 KEYTMP1
SBS1 KEYLINES
RMB4 KEYTMP1
SBS3 KEYLINES
RMB5 KEYTMP1
SBS4 KEYLINES
RMB6 KEYTMP1
SBS5 KEYLINES
RMB7 KEYTMP1
SBS6 KEYLINES
RMB0 KEYTMP2
SBS7 KEYLINES
RMB1 KEYTMP2
SBS2 KEYLINES
RMB2 KEYTMP2 ;最后看 keyTMP1[0~7] 和KEYTMP2[0~2]中的数据
MOV A,LINES
MOV BITNUM,A
SUB A,#0BH ;8H-A=A
MOV KEYLINES,A
KEY_OUT_LOOP_: ;
MOV A,BITNUM
SBR2 STATUS;如果STATUS[2]=0,跳过下一条指令(A不等于0)
JMP DEKEY0_
RRC KEYTMP2,KEYTMP2
RRC KEYTMP1,KEYTMP1
DEC BITNUM,BITNUM ;bitnum-1=bitnum
JMP KEY_OUT_LOOP_
DEKEY0_:
INC KEY_CNT,KEY_CNT
RRC KEYTMP2,KEYTMP2
RRC KEYTMP1,KEYTMP1
SBR0 STATUS ;如果STATUS[0]=0(无进位时候),跳过下一条指令
JMP DEKEY00_ ;C=0 => KEY DETECTED
SBS0 KEY_FLAG
JMP DEKEY0_1ST_KEY_
;
SBS7 KEY_FLAG
JMP DEKEY_NOGND
JSR KEY_STB_TABLE_
SUB A,KEY_CNT
XRL A,FIRST_KEY
SBR2 STATUS;如果STATUS[2]=0,跳过下一条指令
JMP DEKEY00_
JMP MULTIKEY_DET_ ;
DEKEY_NOGND:
;
MOV A,FIRST_KEY
XRL A,KEY_CNT
SKPZ
JMP MULTIKEY_DET_
DEKEY0_1ST_KEY_:
MOV A,KEY_CNT
MOV FIRST_KEY,A
SMB0 KEY_FLAG
;JDG GND LINE
MOV A,#12
JDG_GND_LINE:
SUB A,KEY_CNT
SBR0 STATUS ;如果STATUS[0]=0,跳过下一条指令
JMP DEKEY00_
SMB7 KEY_FLAG ;
DEKEY00_:
MOV A,KEY_CNT
SE #64
JMP DEK000_
JMP DEKEY_END_
DEK000_:
DEC KEYLINES,KEYLINES
MOV A,KEYLINES
SBR2 STATUS
JMP NEXT_STROBE_
JMP DEKEY0_
DEKEY_END_:
MOV A,FIRST_KEY
SKPZ
JMP DEKEY_RTS_1_
NO_KEY_:
SMB2 KEY_FLAG ;MARK NO-KEY FLAG
DEKEY_RTS_1_:
XRL A,KEY_ACTIVE
SBR2 STATUS
JMP DEKEY_RTS_
SMB3 KEY_FLAG ;MARK DIFFERENT-KEY FLAG
DEKEY_RTS_:
MOV A,FIRST_KEY
MOV KEY_ACTIVE,A
RET
MULTIKEY_DET_:
SMB1 KEY_FLAG ;MARK MULTI -KEY FLAG
RET
;====================================
.ORG 01FDH
JMP START
;====================================
.ORG 01FFH
JMP START
;====================================
.END
分析过:采用芯片11个I/O 口 作为按键接口,应该不是用反转法
好i像是逐行逐列扫描?
有前辈 愿意帮解析下这段程序么?
或者 说说 梯形键盘 是怎么扫描的??
|
|