⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 key2.lst

📁 82K96E/82M99E开发的USB键盘接收端DEMO程序源码
💻 LST
📖 第 1 页 / 共 3 页
字号:
"File: KEY2.ASM      Holtek Cross-Assembler  Version 2.86      Page 5

 234  0034  2000     R                  CALL    GetScanPortAndBit   ;Output: PortNo & BitNo
 235  0035                 ;get key state of scan line
 236  0035  0F0A                        MOV     A,10                ;Delay 30 intruction time
 237  0036  2000     R                  CALL    DelayNInst          ;   about 20 us in 6 M sysclk
 238  0037  0712                        MOV     A,ScanIn          ;Get key state
 239  0038  0080     R                  MOV     CurrentState1,A   	;Save key state
 240  0039                  ;check the same 0 value position between CurrentState and CurrentState1
 241  0039                  ;the 0 value of result means the same 0 value position
 242  0039  0500     R                  OR      A,CurrentState
 243  003A  0080     R                  MOV     BitMap,A          	;Save result to buffer
 244  003B  0CFF                        XOR     A,0FFH              ;Have any 0 value ?
 245  003C  3D0A                        SZ      Z                   ;
 246  003D  2800     R                  JMP     NextLine            ;No
 247  003E                  ;How many 0 counts in BitMap          	;Yes
 248  003E  0F08                        MOV     A,08H
 249  003F  0080     R                  MOV     ScanTemp,A
 250  0040  1F05                        CLR     ACC
 251  0041              BitMapCountLp:
 252  0041  1B80     R                  RRC     BitMap
 253  0042  380A                        SNZ     C
 254  0043  1485                        INC     ACC                 ;0 value counts
 255  0044  1780     R                  SDZ     ScanTemp
 256  0045  2800     R                  JMP     BitMapCountLp
 257  0046  0EFE                        AND     A,0FEH              ;0 value counts >= 2 ?
 258  0047  390A                        SNZ     Z                   ;
 259  0048  2800     R                  JMP     FoundPhantom        ;Yes
 260  0049                                                          ;No
 261  0049                  ;-------- this block maybe not need ---------------------------------
 262  0049                  ;Whether CurrentState1 is equal to CurrentState ?             		;
 263  0049                  ;If no, phantom keys is found.                                    	;
 264  0049  0700     R                  MOV     A,CurrentState                              	;
 265  004A  0400     R                  XOR     A,CurrentState1                             	;
 266  004B  390A                        SNZ     Z                                             	;
 267  004C  2800     R                  JMP     FoundPhantom        ;No                       	;
 268  004D                  ;--------------------------------------------------------------------
 269  004D              ;----------------------------------------------------------------------------
 270  004D              
 271  004D              NextLine:
 272  004D  1480     R                  INC     GhostScanLine     	;to scan next line
 273  004E  0F14                        MOV     A,end_of_ScanLines       	;End scan line ?
 274  004F  0400     R                  XOR     A,GhostScanLine   	;
 275  0050  390A                        SNZ     Z                   ;
 276  0051  2800     R                  JMP     GhostLoop           ;No (Continue)
 277  0052  2800     R                  JMP     CheckPhantomOK      ;Yes
 278  0053              
 279  0053              ;----------------------------------------------------------------------------
 280  0053              FoundPhantom:
 281  0053              ;Get phantom key index & save to report buffer
 282  0053  3C00     R                  SZ      bPhantom
 283  0054  2800     R                  JMP     Exit_Scan_Keyboard
 284  0055  3000     R                  SET     bKB_KeyUpt    ;Key is changed
 285  0056  3000     R                  SET     bPhantom      ;Found a phantom key
 286  0057  2800     R                  JMP     Error_Exit_Keyboard
 287  0058              ;----------------------------------------------------------------------------
 288  0058              
 289  0058              CheckPhantomOK:
 290  0058  0001                        CLR     WDT
 291  0059  0700     R                  MOV     A,ScanLineNo      			;Get the buffer pointer of
 292  005A  0B00     R                  ADD     A,OFFSET STATE_BUF_BEG     	;   current scan line state
 293  005B  0081                        MOV     MP0,A               		;
"File: KEY2.ASM      Holtek Cross-Assembler  Version 2.86      Page 6

 294  005C                  ;found any changed
 295  005C  0700     R                  MOV     A,CurrentState    	;Any key changed in current scan
 296  005D  0400                        XOR     A,R0                ;  line
 297  005E  0080     R                  MOV     ChangeKeyMap,A    	;
 298  005F  1F00     R                  CLR     KeyNo             	;bit counter
 299  0060  0F80                        MOV     A,80H               ;1000 0000b
 300  0061  0080     R                  MOV     KeyBit,A          	;Set first bit to check
 301  0062              CheckChangeKeyLp:
 302  0062  1880     R                  RL      KeyBit            	;Update check bit order
 303  0063  1B80     R                  RRC     ChangeKeyMap      	;check changed key bitmap
 304  0064  380A                        SNZ     C                   ;changed ?
 305  0065  2800     R                  JMP     NotChanged          ;No
 306  0066                                                          ;Yes
 307  0066              
 308  0066              ;Get key index from key index table and save it to keyboard buffer.
 309  0066                  ;Get scan line base address
 310  0066  1800     R  				rla		ScanLineNo
 311  0067  1885        				rl		acc
 312  0068  1885        				rl		acc
 313  0069  0300     R                  ADD     A,KeyNO           	;
 314  006A  0B00     R                  ADD     A,LOW KBIndexORG    ;
 315  006B  2000     R                  CALL    GetKeyboardIndex    ;Get keyboard index code in ACC
 316  006C  0080     R                  MOV     IndexBuf,A  		;Save keyboard index code to IndexBuf
 317  006D              
 318  006D  0700     R                  MOV     A,IndexBuf        	;Is modifier key ?
 319  006E  0AE0                        SUB     A,0E0H              ;
 320  006F  380A                        SNZ     C
 321  0070  2800     R                  JMP     NotModifierKey
 322  0071  0700     R                  MOV     A,IndexBuf        	;Is modifier key ?
 323  0072  0AE8                        SUB     A,0E8H              ;
 324  0073  380A                        SNZ     C
 325  0074  2800     R                  JMP     ModifierKey
 326  0075              
 327  0075              ;Not a modifier key
 328  0075              NotModifierKey:
 329  0075                  ;Check press or release
 330  0075  3800     R                  SNZ     CurrentState.0    	;press or release ?
 331  0076  2800     R                  JMP     MakeCode            ;press
 332  0077              
 333  0077              ;				set		break_key
 334  0077              ;release Code:
 335  0077                  ;to find the keyboard index in keyboard buffer and remove it
 336  0077  2000     R                  CALL    RemoveKey           ;Remove ACC key index from
 337  0078                                                          ;   keyboard buffer, if found
 338  0078  390A                        SNZ     Z                   ;Any one moved ?
 339  0079  2800     R              	JMP     NotChanged          ;No(means buffer still full)
 340  007A                                                         	;Don't check current line again
 341  007A                  ;to sort keyboard buffer
 342  007A  2000     R                  CALL    SortKeyboardbuf     ;reorder all 0 value in keyboard
 343  007B  2800     R                  JMP     UpdateState
 344  007C              MakeCode:
 345  007C  0700     R                  MOV     A,BUFF_Index      	;keyboard buffer Full ?
 346  007D  0C00     R                  XOR     A,OFFSET KEY_BUF_END       ;
 347  007E  3D0A                        SZ      Z                   ;
 348  007F  2800     R                  JMP     FIFO1_Full          ;Yes
 349  0080  0700     R                  MOV     A,BUFF_Index 		;No: write keyboard index
 350  0081  0081                        MOV     MP0,A               ;      to keyboard buffer
 351  0082  0700     R                  MOV     A,IndexBuf        	;
 352  0083  0080                        MOV     R0,A                ;
 353  0084  1480     R                  INC     BUFF_Index        	;Update keyboard buffer pointer
"File: KEY2.ASM      Holtek Cross-Assembler  Version 2.86      Page 7

 354  0085  2800     R                  JMP     UpdateState
 355  0086              
 356  0086              ModifierKey:
 357  0086              ;				set		key_modify
 358  0086  0F80                        MOV     A,80H           	;at least rotate one time
 359  0087  0080     R                  MOV     ScanTemp,A    		;
 360  0088  0700     R                  MOV     A,IndexBuf    		;
 361  0089  0AE0                        SUB     A,0E0H          	;the code of first modifier key is E0h
 362  008A  1485                        INC     ACC             	;at least rotate one time
 363  008B              FoundMKBitmapLp:
 364  008B  1880     R                  RL      ScanTemp          	;Rotate to get modifier key order
 365  008C  1785                        SDZ     ACC                 ;
 366  008D  2800     R                  JMP     FoundMKBitmapLp     ;
 367  008E              MKBitmapOK:
 368  008E  0700     R                  MOV     A,ScanTemp
 369  008F  3800     R                  SNZ     CurrentState.0    	;press or release ?
 370  0090  2800     R                  JMP     MKMakeCode          ;Make
 371  0091              ;MKBreakCode:
 372  0091  0185                        CPL     ACC                 ;reset to 0
 373  0092  0680     R                  ANDM    A,KEY_MdfB
 374  0093  2800     R                  JMP     UpdateState1
 375  0094              MKMakeCode:
 376  0094  0580     R                  ORM     A,KEY_MdfB        	;set to 1
 377  0095  2800     R                  JMP     UpdateState1
 378  0096              
 379  0096              UpdateState:
 380  0096  3400     R                  CLR     bPhantom  		;Clear phantom flag
 381  0097              UpdateState1:
 382  0097  3000     R                  SET     bKB_KeyUpt    	;Key is changed
 383  0098  0700     R                  MOV     A,ScanLineNo      	;Get the buffer pointer of
 384  0099  0B00     R                  ADD     A,OFFSET STATE_BUF_BEG     ;   current scan line state
 385  009A  0081                        MOV     MP0,A               ;
 386  009B  0700     R                  MOV     A,KeyBit          	;Change key state
 387  009C  0480                        XORM    A,R0                ;
 388  009D  2800     R                  JMP     NotChanged
 389  009E              
 390  009E              FIFO1_Full:
 391  009E  3C00     R                  SZ      bPhantom
 392  009F  2800     R                  JMP     NotChanged
 393  00A0  3000     R                  SET     bKB_KeyUpt 	;Key is changed
 394  00A1  3000     R                  SET     bPhantom  		;Set phantom flag
 395  00A2  2800     R  				JMP		Error_Exit_Keyboard
 396  00A3              NotChanged:
 397  00A3  1980     R                  RR      CurrentState      	;Update current check key
 398  00A4  1480     R                  INC     KeyNo             	;Update current key no.
 399  00A5  0F08                        MOV     A,08H             	;Finish all key ?
 400  00A6  0400     R                  XOR     A,KeyNo           	;
 401  00A7  390A                        SNZ     Z                 	;
 402  00A8  2800     R                  JMP     CheckChangeKeyLp  	;No
 403  00A9              ScanOneRowOK:
 404  00A9                  ;Scan next line
 405  00A9  1F00     R                  CLR     DebounceCounter   ;reset debounc counter to 0
 406  00AA  1480     R                  INC     ScanLineNo        ;update to next scan line
 407  00AB  0700     R                  MOV     A,ScanLineNo      ;Has finished all scan line ?
 408  00AC  0A14                        SUB     A,end_of_scanlines;
 409  00AD  3C0A                        SZ     	C                 ;
 410  00AE              Error_Exit_Keyboard:
 411  00AE  1F00     R  				CLR		ScanLineNo		  ;Reset the Scanline to Zero
 412  00AF              Exit_Scan_Keyboard:
 413  00AF  2800     E  				jmp		exit_of_examine_kb_state
"File: KEY2.ASM      Holtek Cross-Assembler  Version 2.86      Page 8

 414  00B0                              
 415  00B0              ;----------------------------------------------------------------------------
 416  00B0              ; Scan keyboard (end)
 417  00B0              ;----------------------------------------------------------------------------
 418  00B0              get_kb_matrix_start_pcl:
 419  00B0              ;----------------------------------------------------------------------------
 420  00B0              ;Get keyboard index code
 421  00B0              ;Input : ACC le pointer
 422  00B0              ;Output: ACC keyboard index code
 423  00B0              GetKeyboardIndex:
 424  00B0  0087                        MOV     	TBLP,A
 425  00B1  1D05                        TABRDc  	ACC
 426  00B2  0003                        RET
 427  00B3              
 428  00B3              ;**************************************************************************************************************
 429  00B3              KBIndexORG:
 430  00B3  0048 0003   dw 	key_pause, 		0003, 			0003, 			0003, 			key_r_ctrl,  	0003, 				key_L_ctrl, 	key_f5			;19
            0003 0003 00E4 0003 00E0 003E
 431  00BB  0014 002B   dw	key_q, 			key_tab, 		key_a, 			key_esc, 		key_z, 		 	key_code131, 		key_tilde, 		key_1							;18
            0004 0029 001D 008B 0035 001E
 432  00C3  001A 0039   dw	key_w, 			key_cap, 		key_s, 			key_code45, 	key_x, 		 	key_code132, 		key_f1, 		key_2						;17
            0016 0064 001B 008A 003A 001F
 433  00CB  0008 003C   dw	key_e, 			key_f3, 		key_d, 			key_F4, 		key_c, 		 	key_code133, 		key_f2, 		key_3						;16
            0007 003D 0006 0088 003B 0020
 434  00D3  0015 0017   dw	key_r, 			key_t, 			key_f, 			key_g, 			key_v, 		 	key_b, 				key_5, 			key_4						;15
            0009 000A 0019 0005 0022 0021
 435  00DB  0018 001C   dw	key_u, 			key_y, 			key_j, 			key_h, 			key_m, 			key_n, 				key_6, 			key_7							;14
            000D 000B 0010 0011 0023 0024
 436  00E3  000C 0030   dw	key_i,			key_R_brackets, key_k, 			key_F6, 		key_comma, 		key_code56, 		key_equation, 	key_8							;13
            000E 003F 0036 0087 002E 0025
 437  00EB  0012 0040   dw	key_o,			key_f7, 		key_l, 			0003, 			key_dot, 		key_app, 			key_f8, 		key_9							;12
            000F 0003 0037 0065 0041 0026
 438  00F3  005F 005C   dw	key_num_7, 		key_num_4, 		key_num_1, 		key_space, 		key_num_lock,	key_dn_arrow, 		key_del, 		0003			;8
            0059 002C 0053 0051 004C 0003
 439  00FB  0089 002A   dw	key_code14, 	key_bs, 		key_div, 		key_f11, 		key_enter, 		key_f12, 			key_f9, 		key_f10							;9
            0031 0044 0028 0045 0042 0043
 440  0103  0047 0003   dw	key_scroll, 	0003, 			0003, 			key_l_alt, 		0003,  			key_r_alt, 			0003, 			key_print						;10
            0003 00E2 0003 00E6 0003 0046
 441  010B  0013 002F   dw	key_p, 			key_L_brackets, key_semicolon, 	key_apostrophe, key_code42,  	key_interrogation, 	key_neg, 		key_0							;11
            0033 0034 0032 0038 002D 0027
 442  0113  0003 00E3   dw	0003, 			key_L_win, 		0003, 			0003, 			0003, 			0003, 				0003, 			0003							;3
            0003 0003 0003 0003 0003 0003
 443  011B  0090 0003   dw	key_Hangul, 	0003, 			key_r_win, 		0003, 			0003, 			0003, 				0003, 			Key_Hanja							;2
            00E7 0003 0003 0003 0003 0091
 444  0123  0003 0003   dw	0003,			0003,			0003,			0003,			0003,			0003,				0003,			0003
            0003 0003 0003 0003 0003 0003
 445  012B  0003 0003   dw	0003,			0003,			0003,			0003,			0003,			0003,				0003,			0003
            0003 0003 0003 0003 0003 0003
 446  0133  0003 00E1   dw	0003,			key_l_shift, 	key_r_shift, 	0003, 			0003, 			0003, 				0003, 			0003							;4
            00E5 0003 0003 0003 0003 0003
 447  013B  0057 0085   dw	key_num_plus, 	key_code107, 	key_num_enter, 	key_Up_arrow, 	0003, 			key_L_arrow, 		key_home, 		key_end			;5
            0058 0052 0003 0050 004A 004D
 448  0143  0061 005E   dw	key_num_9, 		key_num_6, 		key_num_3, 		key_num_dot, 	key_num_star,	key_num_neg, 		key_pgup, 		key_pgdn				;6
            005B 0063 0055 0056 004B 004E
 449  014B  0060 005D   dw	key_num_8, 		key_num_5, 		key_num_2, 		key_num_0, 		key_num_div, 	key_R_arrow, 		key_insert, 	0003			;7
            005A 0062 0054 004F 0049 0003
 450  0153              ;**************************************************************************************************************
 451  0153              get_kb_matrix_end_pcl:
 452  0153              
 453  0153              ;Delay ACC * 2 instruction time

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -