📄 keyboard.asm
字号:
_CMD_SET_CapsNum :
cjne a ,#CMD_SET_CapsNum ,pc_Err
call do_CMD_SET_CapsNum
; mov CMD ,#0
jmp CMD_Over
CMD_Over :
;mov r0 ,#0xFA ;交由命令处理函数完成发送应答字节
jmp pc_Over;pc_End
pc_Err :
mov b ,#1
call delay10ms
mov r1 ,#KeyBUff
mov @r1 ,#0xFE
mov a ,#1
call Send_Byte_To_Host_with ;送送接正OK BYTE
pc_End :
; mov r1 ,#r0_addr
; mov a ,#1
; call Send_Byte_To_Host_with ;送送接正OK BYTE
pc_Over :
pop b
ret
;*************************************************************************
;进行扫描
;
;***************************************************************************
ScanKey :
mov p0 ,#0xff
mov Row0_7 ,#0xfe
mov Row8_15 ,#0xff
mov r0 ,#0
mov r1 ,#LastState
sk_Scan_p1 :
mov a ,p0
mov b ,@r1 ;上次状态
cjne a ,b ,sk_delay1; sk_Next_Line
jmp sk_Next_line
sk_delay1 :
;push b
mov r7 ,b
mov b ,#2
call delay10ms
cjne a ,p0 ,sk_Next_Line
mov @r1 ,a ;保存当前状态
; pop b
mov b ,r7
xrl a ,b ;找出不同的位
mov r3 ,a ;暂存位图
jz sk_Next_Line
;找出是第几列
mov r2 ,#0
sk_Get_Col1 :
rrc a ;最先找到哪个位为1:则输出这个列
jc sk_Got_Col1
inc r2
jmp sk_Get_Col1
sk_Got_Col1 :
mov a ,b
anl a ,r3
jz sk_Is_Break_1
;是通码 写入通码
clr IS_Break
jmp sk_send_Key1
;是断码 写入断码
sk_Is_Break_1 :
setb IS_Break
sk_Send_Key1 :
call GetKeyCode
; jmp sk_Scan_Over
sk_Next_line :
inc r0
inc r1
mov a ,Row0_7
rl a
mov Row0_7 ,a
cjne r0 ,#8 ,sk_Scan_p1
mov Row0_7 ,#0xff
mov Row8_15 ,#0xfe
;--------------------------------------------------------------------------
sk_Scan_p2 :
mov a ,p0
mov b ,@r1 ;上次状态
cjne a ,b ,sk_delay2; sk_Next_Line
jmp sk_Next_line2
sk_delay2 :
;push b
mov r7 ,b
mov b ,#1
call delay10ms
cjne a ,p0 ,sk_Next_Line2
mov @r1 ,a ;保存当前状态
; pop b
mov b ,r7
xrl a ,b ;找出不同的位
mov r3 ,a ;暂存位图
jz sk_Next_Line2
;找出是第几列
mov r2 ,#0
sk_Get_Col2 :
rrc a ;最先找到哪个位为1:则输出这个列
jc sk_Got_Col2
inc r2
jmp sk_Get_Col2
sk_Got_Col2 :
mov a ,b
anl a ,r3
jz sk_Is_Break_2
;是通码 写入通码
clr IS_Break
jmp sk_Send_Key2
;mov
;是断码 写入断码
sk_Is_Break_2 :
setb IS_Break
sk_Send_Key2 :
call GetKeyCode
; jmp sk_Scan_Over
sk_Next_line2 :
inc r0
inc r1
mov a ,Row8_15
rl a
mov Row8_15 ,a
cjne r0 ,#16 ,sk_Scan_p2
sk_Scan_Over :
call SendTypical ;机打检测与发送
ret
;*************************************************************************
;查表得扫描码,并发送
;r0 :Row
;r2 :col
;***************************************************************************
GetKeyCode :
push r0_addr
push r1_addr
push acc
push b
mov a ,r0
rl a
rl a
rl a
anl a ,#0xf8
orl a ,r2
mov r1 ,#KeyBuff
mov b ,#0
;
cjne a ,#93 ,gkc_76
ajmp gkc_specialy
gkc_76 :
cjne a ,#94 ,gkc_79
ajmp gkc_specialy
gkc_79 :
cjne a ,#101 ,gkc_80
ajmp gkc_specialy
gkc_80 :
cjne a ,#102 ,gkc_81
ajmp gkc_specialy
gkc_81 :
cjne a ,#109 ,gkc_83
ajmp gkc_specialy
gkc_83 :
cjne a ,#110 ,gkc_84
ajmp gkc_specialy
gkc_84 :
cjne a ,#114 ,gkc_85
ajmp gkc_specialy
gkc_85 :
cjne a ,#116 ,gkc_86
ajmp gkc_specialy
gkc_86 :
cjne a ,#117 ,gkc_89
ajmp gkc_specialy
gkc_89 :
cjne a ,#118 ,gkc_sp_ok
ajmp gkc_specialy
gkc_specialy :
inc b
mov @r1 ,#0xE0
inc r1
gkc_sp_ok :
;
mov dptr ,#Code_Set2
movc a ,@a+dptr
; mov LastKey ,a
; mov TypicalDelayCount ,TypicalDelay ;设定机打延时
; mov TypicalIntervalCount ,TypicalInterval
; mov r1 ,#KeyBuff
jnb IS_Break ,gkc_Send_Make
;生成断码
cjne a ,LastKey ,gkc_BreakIni_Ok
mov LastKey ,#0
gkc_BreakIni_Ok :
mov @r1 ,#0xF0
inc r1
mov @r1 ,a
mov a ,b
add a ,#2
; mov r1 ,#KeyBuff
jmp gkC_Over
gkc_Send_Make :
mov LastKey ,a
mov TypicalDelayCount ,TypicalDelay ;设定机打延时
mov TypicalIntervalCount ,TypicalInterval
mov @r1 ,a
mov a ,b
add a ,#1
gkc_Over :
mov r1 ,#KeyBuff
call Send_Byte_To_Host_With
gkc_exit :
pop b
pop acc
pop r1_addr
pop r0_addr
ret
;*************************************************************************
;发送机打
;
;***************************************************************************
SendTypical :
push acc
push r1_addr
mov a ,LastKey
jz stpcl_Over
mov a ,TypicalDelayCount
jz stpl_Delay_Over
dec TypicalDelayCount
jmp stpcl_Over
stpl_Delay_Over :
;mov TypicalDelayCount ,TypicalDelay
;mov a ,TypicalIntervalCount
djnz TypicalIntervalCount ,stpcl_Over
mov TypicalIntervalCount ,TypicalInterval
mov r1 ,#KeyBuff
mov @r1 ,LastKey
mov a ,#1
call Send_Byte_to_Host_With
stpcl_Over :
pop r1_addr
pop acc
ret
;____________________________________________________________________________________________
;扫描码表
;____________________________________________________________________________________________
Code_Set1 :
DB 0x00
Code_Set2 :
;c0 c1 c2 c3 c4 c5 c6 c7
DB 0x00 ,0x00 ,0x00 ,0x00 ,0xFF ,0x00 ,0x14 ,0X03; R0
;126 ,x ,x ,x ,64 ,x ,58 ,116
DB 0x15 ,0X0D ,0X1C ,0X76 ,0X1A ,0X00 ,0X0E ,0X16 ; R1 X
;17 ,16 ,31 ,110 ,46 ,131 ,1 ,2
DB 0x1D ,0X58 ,0X1B ,0X61 ,0X22 ,0X00 ,0X05 ,0X1E ; R2 X
;18 ,30 ,32 ,45, 47 ,132 112 ,3
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0x00 ,0x12 ,0x59 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ; R15 1
;! ,44 ,57 ,! ,! ,! ,! !
;DB 0x00 ; R16 1
;! ,! ,! ,
;DB 0x00 ; R17 10
M2_Key1 : DB 0xE0 ,0x00
M2_Key2 : DB 0x16 ,0x00
M2_Key3 : DB 0x1e ,0x00
M2_Key4 : DB 0x26 ,0x00
M2_Key5 : DB 0x25 ,0x00
M2_Key6 : DB 0x2e ,0x00
M2_Key7 : DB 0x36 ,0x00
M2_Key8 : DB 0x3D ,0x00
M2_Key9 : DB 0x3E ,0x00
M2_Key10 : DB 0x46 ,0x00
M2_Key11 : DB 0x45 ,0x00
M2_Key12 : DB 0x4E ,0x00
M2_Key13 : DB 0x55 ,0x00
M2_Key14 : DB 0x6A ,0x00
M2_Key15 : DB 0x66 ,0x00
M2_Key16 : DB 0x0D ,0x00
M2_Key17 : DB 0x15 ,0x00
M2_Key18 : DB 0x1D ,0x00
M2_Key19 : DB 0x24 ,0x00
M2_Key20 : DB 0x2D ,0x00
M2_Key21 : DB 0x2C ,0x00
M2_Key22 : DB 0x35 ,0x00
M2_Key23 : DB 0x3C ,0x00
M2_Key24 : DB 0x43 ,0x00
M2_Key25 : DB 0x44 ,0x00
M2_Key26 : DB 0x4D ,0x00
M2_Key27 : DB 0x54 ,0x00
M2_Key28 : DB 0x5B ,0x00
M2_Key29 : DB 0x5D ,0x00
M2_Key30 : DB 0x58 ,0x00
M2_Key31 : DB 0x1C ,0x00
M2_Key32 : DB 0x1B ,0x00
M2_Key33 : DB 0x23 ,0x00
M2_Key34 : DB 0x2B ,0x00
M2_Key35 : DB 0x34 ,0x00
M2_Key36 : DB 0x33 ,0x00
M2_Key37 : DB 0x3B ,0x00
M2_Key38 : DB 0x42 ,0x00
M2_Key39 : DB 0x4B ,0x00
M2_Key40 : DB 0x4C ,0x00
M2_Key41 : DB 0x52 ,0x00
M2_Key42 : DB 0x5D ,0x00
M2_Key43 : DB 0x5A ,0x00
M2_Key44 : DB 0x12 ,0x00
M2_Key45 : DB 0x61 ,0x00
M2_Key46 : DB 0x1A ,0x00
M2_Key47 : DB 0x22 ,0x00
M2_Key48 : DB 0x21 ,0x00
M2_Key49 : DB 0x2A ,0x00
M2_Key50 : DB 0x32 ,0x00
M2_Key51 : DB 0x31 ,0x00
M2_Key52 : DB 0x3A ,0x00
M2_Key53 : DB 0x41 ,0x00
M2_Key54 : DB 0x49 ,0x00
M2_Key55 : DB 0x4A ,0x00
M2_Key56 : DB 0x00 ,0x00
M2_Key57 : DB 0x59 ,0x00
M2_Key58 : DB 0x14 ,0x00
M2_Key59 : DB 0x00 ,0x00
M2_Key60 : DB 0x11 ,0x00
M2_Key61 : DB 0x29 ,0x00
M2_Key62 : DB 0xE0 ,0X11 ,0x00
M2_Key63 : DB 0x00 ,0x00
M2_Key64 : DB 0xE0 ,0X14 ,0x00
M2_Key65 : DB 0x00 ,0x00
M2_Key66 : DB 0x00 ,0x00
M2_Key67 : DB 0x00 ,0x00
M2_Key68 : DB 0x00 ,0x00
M2_Key69 : DB 0x00 ,0x00
M2_Key70 : DB 0x ,0x00
M2_Key71 : DB 0x ,0x00
M2_Key72 : DB 0x ,0x00
M2_Key73 : DB 0x ,0x00
M2_Key74 : DB 0x ,0x00
M2_Key75 : DB 0xE0, 0X70 ,0x00
M2_Key76 : DB 0xE0, 0X71 ,0x00
M2_Key77 : DB 0x ,0x00
M2_Key78 : DB 0x ,0x00
M2_Key79 : DB 0xE0 ,0X6B ,0x00
M2_Key80 : DB 0xE0 ,0X6C ,0x00
M2_Key81 : DB 0xE0 ,0X69 ,0x00
M2_Key82 : DB 0x ,0x00
M2_Key83 : DB 0xE0 ,0X75 ,0x00
M2_Key84 : DB 0xE0 ,0X72 ,0x00
M2_Key85 : DB 0xE0 ,0X7D ,0x00
M2_Key86 : DB 0xE0 ,0X7A ,0x00
M2_Key87 : DB 0x ,0x00
M2_Key88 : DB 0x ,0x00
M2_Key89 : DB 0xE0 ,0X74 ,0x00
M2_Key90 : DB 0x77 ,0x00
M2_Key91 : DB 0x6C ,0x00
M2_Key92 : DB 0x6B ,0x00
M2_Key93 : DB 0x69 ,0x00
M2_Key94 : DB 0x00 ,0x00
M2_Key95 : DB 0xE0 ,0X4A ,0x00
M2_Key96 : DB 0x75 ,0x00
M2_Key97 : DB 0x73 ,0x00
M2_Key98 : DB 0x72 ,0x00
M2_Key99 : DB 0x70 ,0x00
M2_Key100 : DB 0X7C ,0x00
M2_Key101 : DB 0x7D ,0x00
M2_Key102 : DB 0x74 ,0x00
M2_Key103 : DB 0x7A ,0x00
M2_Key104 : DB 0x71 ,0x00
M2_Key105 : DB 0x7B ,0x00
M2_Key106 : DB 0x79 ,0x00
M2_Key107 : DB 0x6D ,0x00
M2_Key108 : DB 0xE0 ,0X5A ,0x00
M2_Key109 : DB 0x00 ,0x00
M2_Key110 : DB 0x76 ,0x00
M2_Key111 : DB 0x00 ,0x00
M2_Key112 : DB 0x05 ,0x00
M2_Key113 : DB 0x06 ,0x00
M2_Key114 : DB 0x04 ,0x00
M2_Key115 : DB 0x0C ,0x00
M2_Key116 : DB 0x03 ,0x00
M2_Key117 : DB 0x0B ,0x00
M2_Key118 : DB 0x83 ,0x00
M2_Key119 : DB 0x0A ,0x00
M2_Key120 : DB 0x01 ,0x00
M2_Key121 : DB 0x09 ,0x00
M2_Key122 : DB 0x78 ,0x00
M2_Key123 : DB 0x07 ,0x00
M2_Key124 : DB 0xE0 ,0X12 ,0XE0 ,0X7C ,0x00
M2_Key125 : DB 0x7E ,0x00
M2_Key126 : DB 0xE1 ,0X14 ,0X77 ,0x00
M2_Key127 : DB 0x00 ,0x00
M2_Key128 : DB 0x00 ,0x00
;E0 :后面跟一个字节
;E1 :后面跟两个字节
;F0 :后面有一个
B2_Key1 : DB 0x ,0x00
B2_Key2 : DB 0x ,0x00
B2_Key3 : DB 0x ,0x00
B2_Key4 : DB 0x ,0x00
B2_Key5 : DB 0x ,0x00
B2_Key6 : DB 0x ,0x00
B2_Key7 : DB 0x ,0x00
B2_Key8 : DB 0x ,0x00
B2_Key9 : DB 0x ,0x00
B2_Key10 : DB 0x ,0x00
B2_Key11 : DB 0x ,0x00
B2_Key12 : DB 0x ,0x00
B2_Key13 : DB 0x ,0x00
B2_Key14 : DB 0x ,0x00
B2_Key15 : DB 0x ,0x00
B2_Key16 : DB 0x ,0x00
B2_Key17 : DB 0x ,0x00
B2_Key18 : DB 0x ,0x00
B2_Key19 : DB 0x ,0x00
B2_Key20 : DB 0x ,0x00
B2_Key21 : DB 0x ,0x00
B2_Key22 : DB 0x ,0x00
B2_Key23 : DB 0x ,0x00
B2_Key24 : DB 0x ,0x00
B2_Key25 : DB 0x ,0x00
B2_Key26 : DB 0x ,0x00
B2_Key27 : DB 0x ,0x00
B2_Key28 : DB 0x ,0x00
B2_Key29 : DB 0x ,0x00
B2_Key30 : DB 0x ,0x00
B2_Key31 : DB 0x ,0x00
B2_Key32 : DB 0x ,0x00
B2_Key33 : DB 0x ,0x00
B2_Key34 : DB 0x ,0x00
B2_Key35 : DB 0x ,0x00
B2_Key36 : DB 0x ,0x00
B2_Key37 : DB 0x ,0x00
B2_Key38 : DB 0x ,0x00
B2_Key39 : DB 0x ,0x00
B2_Key40 : DB 0x ,0x00
B2_Key41 : DB 0x ,0x00
B2_Key42 : DB 0x ,0x00
B2_Key43 : DB 0x ,0x00
B2_Key44 : DB 0x ,0x00
B2_Key45 : DB 0x ,0x00
B2_Key46 : DB 0x ,0x00
B2_Key47 : DB 0x ,0x00
B2_Key48 : DB 0x ,0x00
B2_Key49 : DB 0x ,0x00
B2_Key50 : DB 0x ,0x00
B2_Key51 : DB 0x ,0x00
B2_Key52 : DB 0x ,0x00
B2_Key53 : DB 0x ,0x00
B2_Key54 : DB 0x ,0x00
B2_Key55 : DB 0x ,0x00
B2_Key56 : DB 0x ,0x00
B2_Key57 : DB 0x ,0x00
B2_Key58 : DB 0x ,0x00
B2_Key59 : DB 0x ,0x00
B2_Key60 : DB 0x ,0x00
B2_Key61 : DB 0x ,0x00
B2_Key62 : DB 0x ,0x00
B2_Key63 : DB 0x ,0x00
B2_Key64 : DB 0x ,0x00
B2_Key65 : DB 0x ,0x00
B2_Key66 : DB 0x ,0x00
B2_Key67 : DB 0x ,0x00
B2_Key68 : DB 0x ,0x00
B2_Key69 : DB 0x ,0x00
B2_Key70 : DB 0x ,0x00
B2_Key71 : DB 0x ,0x00
B2_Key72 : DB 0x ,0x00
B2_Key73 : DB 0x ,0x00
B2_Key74 : DB 0x ,0x00
B2_Key75 : DB 0x ,0x00
B2_Key76 : DB 0x ,0x00
B2_Key77 : DB 0x ,0x00
B2_Key78 : DB 0x ,0x00
B2_Key79 : DB 0x ,0x00
B2_Key80 : DB 0x ,0x00
B2_Key81 : DB 0x ,0x00
B2_Key82 : DB 0x ,0x00
B2_Key83 : DB 0x ,0x00
B2_Key84 : DB 0x ,0x00
B2_Key85 : DB 0x ,0x00
B2_Key86 : DB 0x ,0x00
B2_Key87 : DB 0x ,0x00
B2_Key88 : DB 0x ,0x00
B2_Key89 : DB 0x ,0x00
B2_Key90 : DB 0x ,0x00
B2_Key91 : DB 0x ,0x00
B2_Key92 : DB 0x ,0x00
B2_Key93 : DB 0x ,0x00
B2_Key94 : DB 0x ,0x00
B2_Key95 : DB 0x ,0x00
B2_Key96 : DB 0x ,0x00
B2_Key97 : DB 0x ,0x00
B2_Key98 : DB 0x ,0x00
B2_Key99 : DB 0x ,0x00
B2_Key100 : DB 0x ,0x00
B2_Key101 : DB 0x ,0x00
B2_Key102 : DB 0x ,0x00
B2_Key103 : DB 0x ,0x00
B2_Key104 : DB 0x ,0x00
B2_Key105 : DB 0x ,0x00
B2_Key106 : DB 0x ,0x00
B2_Key107 : DB 0x ,0x00
B2_Key108 : DB 0x ,0x00
B2_Key109 : DB 0x ,0x00
B2_Key110 : DB 0x ,0x00
B2_Key111 : DB 0x ,0x00
B2_Key112 : DB 0x ,0x00
B2_Key113 : DB 0x ,0x00
B2_Key114 : DB 0x ,0x00
B2_Key115 : DB 0x ,0x00
B2_Key116 : DB 0x ,0x00
B2_Key117 : DB 0x ,0x00
B2_Key118 : DB 0x ,0x00
B2_Key119 : DB 0x ,0x00
B2_Key120 : DB 0x ,0x00
B2_Key121 : DB 0x ,0x00
B2_Key122 : DB 0x ,0x00
B2_Key123 : DB 0x ,0x00
B2_Key124 : DB 0x ,0x00
B2_Key125 : DB 0x ,0x00
B2_Key126 : DB 0x ,0x00
B2_Key127 : DB 0x ,0x00
B2_Key128 : DB 0x ,0x00
Code_Set3 :
DB 0x00
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -