擴展鍵盤電路及其編程
3. 軟件程序清單
軟件的流程框圖如圖2所示。具體的程序清單如下:
THIS_051 EQU #0AAH
NO_KEY EQU #0F0H
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP INT_T0
ORG 0023H
AJMP INT_SERIES
ORG 0030H
MAIN:
MOV SP,#40H
SETB P1.0
SETB P1.1
SETB P1.2
SETB P1.3
CLR P3.7
MOV TMOD,#21H
MOV TL1,#0E6H
MOV TH1,#0E6H
MOV TL0,#00H
MOV TH0,#80H
CLR ET1
SETB TR1
SETB ET0
SETB TR0
MOV PCON,#80H
MOV SCON,#0D0H
SETB ES
SETB EA
READKEY:
CLR P1.1
CLR P1.2
CLR P1.3
MOV R1,#00H
LCALL DELAY10US
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,DEL_SHAKER1
SJMP TEST_LINE2
DEL_SHAKER1:
LCALL DELAY10MS
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,KEY_VALUE
TESTLINE2:
SETB P1.1
MOV R1,#01H
LCALL DELAY10US
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,DEL_SHAKER2
SJMP TEST_LINE3
DEL_SHAKER2:
LCALL DELAY10MS
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,KEY_CALUE
TEST_LINE3:
SETB P1.2
CLR P1.1
MOV R1,#02H LCALL DELAY10US
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,DEL_SHAKER3
SJMP TEST_LINE4
DEL_SHAKER3:
LCALL DELAY10MS
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,KEY_VALUE
TEST_LINE4:
SETB P1.1
MOV R1,#03H
LCALL DELAY10US
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,DEL_SHAKER4
SJMP TEST_LINE5
DEL_SHAKER4:
LCALL DELAY10MS
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,KEY_VALUE
TEST_LINE5:
SETB P1.3
CLR P1.1
CLR P1.2
MOV R1,#04H
LCALL DELAY10US
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,DEL_SHAKER5
SJMP RET_READKEY
DEL_SHAKER5:
LCALL DELAY10MS
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,KEY_VALUE
RET_READKEY:
AJMP READKEY
KEY_VALUE:
JNB ACC.7,F(xiàn)IRST_LINE
JNB ACC.6,SECOND_LINE
JNB ACC.5,THIRD_LINE
JNB ACC.4,F(xiàn)OUTH_LINE
AJMP READKEY
FIRST_LINE:
MOV R0,#03H
SJMP SEND_KEY
SECOND_LINE:
MOV R0,#02H
SJMP SEND_KEY
THIRD_LINE:
MOV R0,#01H
SJMP SEND-KEY
FOUTH_LINE:
MOV R0,#00H
SEND_KEY:
MOV A,R0
MOV B,#05H
MUL AB
ADD A,R1
MOV DPTR,#KBTAB
MOVC A,@A+DPTR
MOV R3,A
CLR P1.0
LCALL DELAY10US
SETB P1.0 KEY_LOOP:
LCALL DELAY10US
MOV A,P1
ANL A,#0F0H
CJNE A,NO_KEY,KEY_LOOP
SETB P1.1
SETB P1.2
SETB P1.3
AJMP READKEY
INTT0:
MOV TL0,#00H
MOV TH0,#80H
CPL P3.7
RETI
INT_SERIES:
PUSH ACC
JNB RI,TRANSMISSION
CLR RI
MOV A,SBUF
CJNE A,THIS?051,RETURN
MOV A,R3
MOV SBUF,A
SJMP RETURN
TRANSMISSION:
CLR TI
RETURN:
POP ACC
RETI
DELAY10MS:
MOV R6,#10
DELAY1:MOV R5,#250
DELAY2:DJNZ R5,DELAY2
DJNZ R6,DELAY1
RET
DELAY1MS:
MOV R5,#250
DELAY4:DJNZ R5,DELAY4
RET
DELAY10US:
MOV R5,#05H
DELAY3:DJNZ R5,DELAY3
RET
KBTAB:DB′TG369CF258DP147SH0IR′
DIY機械鍵盤相關(guān)社區(qū):機械鍵盤DIY
評論