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

📄 key2.asm

📁 基于HT82K96E的usb鼠标实现源程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
                SZ      Z                   ;
                JMP     FIFO1_Full          ;Yes
                MOV     A,BUFF_Index 		;No: write keyboard index
                MOV     MP0,A               ;      to keyboard buffer
                MOV     A,IndexBuf        	;
                MOV     R0,A                ;
                INC     BUFF_Index        	;Update keyboard buffer pointer
                JMP     UpdateState

ModifierKey:
;				set		key_modify
                MOV     A,80H           	;at least rotate one time
                MOV     ScanTemp,A    		;
                MOV     A,IndexBuf    		;
                SUB     A,0E0H          	;the code of first modifier key is E0h
                INC     ACC             	;at least rotate one time
FoundMKBitmapLp:
                RL      ScanTemp          	;Rotate to get modifier key order
                SDZ     ACC                 ;
                JMP     FoundMKBitmapLp     ;
MKBitmapOK:
                MOV     A,ScanTemp
                SNZ     CurrentState.0    	;press or release ?
                JMP     MKMakeCode          ;Make
;MKBreakCode:
                CPL     ACC                 ;reset to 0
                ANDM    A,KEY_MdfB
                JMP     UpdateState1
MKMakeCode:
                ORM     A,KEY_MdfB        	;set to 1
                JMP     UpdateState1

UpdateState:
                CLR     bPhantom  		;Clear phantom flag
UpdateState1:
                SET     bKB_KeyUpt    	;Key is changed
                MOV     A,ScanLineNo      	;Get the buffer pointer of
                ADD     A,OFFSET STATE_BUF_BEG     ;   current scan line state
                MOV     MP0,A               ;
                MOV     A,KeyBit          	;Change key state
                XORM    A,R0                ;
                JMP     NotChanged

FIFO1_Full:
                SZ      bPhantom
                JMP     NotChanged
                SET     bKB_KeyUpt 	;Key is changed
                SET     bPhantom  		;Set phantom flag
				JMP		Error_Exit_Keyboard
NotChanged:
                RR      CurrentState      	;Update current check key
                INC     KeyNo             	;Update current key no.
                MOV     A,08H             	;Finish all key ?
                XOR     A,KeyNo           	;
                SNZ     Z                 	;
                JMP     CheckChangeKeyLp  	;No
ScanOneRowOK:
    ;Scan next line
                CLR     DebounceCounter   ;reset debounc counter to 0
                INC     ScanLineNo        ;update to next scan line
                MOV     A,ScanLineNo      ;Has finished all scan line ?
                SUB     A,end_of_scanlines;
                SZ     	C                 ;
Error_Exit_Keyboard:
				CLR		ScanLineNo		  ;Reset the Scanline to Zero
Exit_Scan_Keyboard:
				jmp		exit_of_examine_kb_state
                
;----------------------------------------------------------------------------
; Scan keyboard (end)
;----------------------------------------------------------------------------
get_kb_matrix_start_pcl:
;----------------------------------------------------------------------------
;Get keyboard index code
;Input : ACC le pointer
;Output: ACC keyboard index code
GetKeyboardIndex:
                MOV     	TBLP,A
                TABRDc  	ACC
                RET

;**************************************************************************************************************
KBIndexORG:
dw 	key_pause, 		0003, 			0003, 			0003, 			key_r_ctrl,  	0003, 				key_L_ctrl, 	key_f5			;19
dw	key_q, 			key_tab, 		key_a, 			key_esc, 		key_z, 		 	key_code131, 		key_tilde, 		key_1							;18
dw	key_w, 			key_cap, 		key_s, 			key_code45, 	key_x, 		 	key_code132, 		key_f1, 		key_2						;17
dw	key_e, 			key_f3, 		key_d, 			key_F4, 		key_c, 		 	key_code133, 		key_f2, 		key_3						;16
dw	key_r, 			key_t, 			key_f, 			key_g, 			key_v, 		 	key_b, 				key_5, 			key_4						;15
dw	key_u, 			key_y, 			key_j, 			key_h, 			key_m, 			key_n, 				key_6, 			key_7							;14
dw	key_i,			key_R_brackets, key_k, 			key_F6, 		key_comma, 		key_code56, 		key_equation, 	key_8							;13
dw	key_o,			key_f7, 		key_l, 			0003, 			key_dot, 		key_app, 			key_f8, 		key_9							;12
dw	key_num_7, 		key_num_4, 		key_num_1, 		key_space, 		key_num_lock,	key_dn_arrow, 		key_del, 		0003			;8
dw	key_code14, 	key_bs, 		key_div, 		key_f11, 		key_enter, 		key_f12, 			key_f9, 		key_f10							;9
dw	key_scroll, 	0003, 			0003, 			key_l_alt, 		0003,  			key_r_alt, 			0003, 			key_print						;10
dw	key_p, 			key_L_brackets, key_semicolon, 	key_apostrophe, key_code42,  	key_interrogation, 	key_neg, 		key_0							;11
dw	0003, 			key_L_win, 		0003, 			0003, 			0003, 			0003, 				0003, 			0003							;3
dw	key_Hangul, 	0003, 			key_r_win, 		0003, 			0003, 			0003, 				0003, 			Key_Hanja							;2
dw	0003,			0003,			0003,			0003,			0003,			0003,				0003,			0003
dw	0003,			0003,			0003,			0003,			0003,			0003,				0003,			0003
dw	0003,			key_l_shift, 	key_r_shift, 	0003, 			0003, 			0003, 				0003, 			0003							;4
dw	key_num_plus, 	key_code107, 	key_num_enter, 	key_Up_arrow, 	0003, 			key_L_arrow, 		key_home, 		key_end			;5
dw	key_num_9, 		key_num_6, 		key_num_3, 		key_num_dot, 	key_num_star,	key_num_neg, 		key_pgup, 		key_pgdn				;6
dw	key_num_8, 		key_num_5, 		key_num_2, 		key_num_0, 		key_num_div, 	key_R_arrow, 		key_insert, 	0003			;7
;**************************************************************************************************************
get_kb_matrix_end_pcl:

;Delay ACC * 2 instruction time
;Input : ACC = Instruction numbers
DelayNInst:
                SDZ     ACC
                JMP     DelayNInst
                RET

;----BEGIN (Remove one keyboard index from keyboard buffer)
;Remove one keyboard index ([IndexBuf]) from keyboard buffer
;Output: Z = 1:Remove/0:None
RemoveKey:
                MOV     A,OFFSET KEY_Code1B
                MOV     MP0,A
RemoveKeyLp:
                MOV     A,IndexBuf
                XOR     A,R0
                SZ      Z
                JMP     ExtRemove
                INC     MP0
                MOV     A,OFFSET KEY_BUF_END       ;until buffer end (6)
                XOR     A,MP0
                SNZ     Z
                JMP     RemoveKeyLp
                CLR     Z
                RET
ExtRemove:
                CLR     R0
                RET
;----END (Remove one keyboard index from keyboard buffer)

;----BEGIN (reorder all 0 value in keybaord buffer to buffer's tail)
;reorder all 0 value in keybaord buffer to buffer's tail
SortKeyboardBuf:
                MOV     A,OFFSET KEY_CODE1B
                MOV     MP0,A
SortKeyboardBufLp:
                MOV     A,BUFF_Index
                XOR     A,MP0
                SZ      Z
                JMP     ExtSortKey
                MOV     A,R0
                INC     MP0
                SZ      ACC
                JMP     SortKeyboardBufLp
                MOV     A,R0
                DEC     MP0
                MOV     R0,A
                INC     MP0
                CLR     R0
                JMP     SortKeyboardBufLp
ExtSortKey:
                DEC     BUFF_Index
                RET
;----END (reorder all 0 value in keybaord buffer to buffer's tail)


;----------------------------------------------------------------------------
;Input 	
;ACC		: store the present scan out line
;Output
;Change I/O PB,PC,PD state
;variable used
;temp1		: temporary variable
 
GetScanPortAndBit:
				mov			temp1,a

				set			ScanOut1C
				set			ScanOut3C
				mov			a,Scan2_Mask
				orm			a,ScanOut2C

				mov			a,scanout1C_adr			;1~8
				sz			temp1.3
				mov			a,scanout3C_adr			;9~16
				sz			temp1.4
				mov			a,scanout2C_adr			;17~20
				mov			mp0,a
				clr			temp1.4
				inc			temp1
				mov			a,01111111b
next_bit:
				rl			acc
				sdz			temp1
				jmp			next_bit
				mov			temp1,a
				mov			a,mp0
				xor			a,scanout2C_adr
				mov			a,temp1
				snz			z
                JMP     	SetLine
ScanOut2Line:
				swap		temp1
                MOV     	A,Scan2_Mask    	;Mask for ScanOut2
                ANDM    	A,Temp1    			;
                MOV     	A,LED_PORT   		;Get LED_PORT state
                AND     	A,LED_Mask      	;
                OR      	A,Temp1
SetLine:
                MOV     	R0,A
                dec     	MP0
                MOV     	R0,A
				mov			a,kb_led
				jmp			setled	

;----------------------------------------------------------------------------
SETLED:
				snz		acc.@num_bit
				jmp		turn_off_num
turn_on_num:
				clr		led_num_c
				clr		led_num
				jmp		examine_cap_state
turn_off_num:
				set		led_num_c
				set		led_num
		

examine_cap_state:	
				snz		acc.@cap_bit
				jmp		turn_off_cap
turn_on_cap:
				clr		led_cap_C
				clr		led_cap
				jmp		examine_scroll_state
turn_off_cap:
				set		led_cap_C
				set		led_cap
examine_scroll_state:	
				snz		acc.@scrl_bit
				jmp		turn_off_scroll
turn_on_scroll:
				clr		led_scrl_c
				clr		led_scrl
				jmp		out_of_examine_led
turn_off_scroll:
				set		led_scrl_c
				set		led_scrl
out_of_examine_led:
				ret	
;------------------------------------------------------------------------------
MoveKeyboardData:
				sz		bPhantom
				jmp		out_kb_error_status
                CLR     BP                  ;set to BP 0
                MOV     A,OFFSET KEY_Mdfb    ;report buffer pointer
                MOV     MP0,A               ;
                MOV     A,OFFSET FIFO_OUT1  ;FIFO_OUTx pointer
                MOV     MP1,A               ;
GetInputSLp:
                MOV     A,R0                ;move report buffer
                MOV     R1,A                ; into FIFO_OUT
                INC     MP0                 ;Update source pointer
                INC     MP1                 ;Update target pointer
                INC     FIFO_SendLen	    ;Update FIFO data length
                MOV     A,OFFSET KEY_Mdfb + REPORT_KB_SIZE   ;end buffer address
                XOR     A,MP0               ;End buffer ?
                SNZ     Z                   ;
                JMP     GetInputSLp         ;No

				

out_of_MOVEKEYBOARDDATA:
                MOV     A,USB_REG_BANK      ;Yes: Reset to USB register bank
                MOV     BP,A 
				ret

;------------------------------------------------------------------------------
out_kb_error_status:
				mov		a,01
				mov		fifo_out1,a
				mov		fifo_out2,a
				mov		fifo_out3,a
				mov		fifo_out4,a
				mov		fifo_out5,a
				mov		fifo_out6,a
				mov		fifo_out7,a
				mov		fifo_out8,a
				jmp		out_of_MOVEKEYBOARDDATA
;------------------------------------------------------------------------------
kb_io_config:
			set			ScanOut1		;PB SET TO BE INPUT MODE&SET HIGH
			set			ScanOut1c
			mov			a,Scan2_Mask	;?
			orm			a,scanout2		;?
			orm			a,scanout2c		;?
			set			scanout3		;PD SET TO BE INPUT MODE&SET HIGH
			set			scanout3c
			mov			a,11111110b		;PC SET TO BE INPUT MODE&SET HIGH
			andm		a,led_port_c	;EXCEPT PC.0
			andm		a,led_port
			ret
;----------------------------------------------------------------------------
KB_INITIAL:
				MOV     A,OFFSET STATE_BUF_BEG
            	MOV     MP0,A
InitRAMLp_KB:					;采用比较偏移地址方法来确定初始化的范围
            	SET     R0		
            	INC     MP0
            	MOV     A,OFFSET STATE_BUF_END 
            	XOR     A,MP0			
            	SNZ     Z
            	JMP     InitRAMLp_KB
          	MOV     A,OFFSET KEY_Code1B ;Reset keyboard buffer pointer to
           	MOV     BUFF_Index,A  		;   1st KeyCode


			clr			ScanLineNo
            ret
;----------------------------------------------------------------------------
kb_suspend:
				mov		a,00000000b
                mov     ScanOut1C,a     ;Set all scan row 0 lines to output mode                
				mov		Scanout1,a

				mov		a,00001110b
                MOV     ScanOut2C,A   ;Set all scan row 2 lines to output mode
                MOV     ScanOut2,A    ;Set all scan row 2 lines to low

				mov		a,00000000b
                mov     ScanOut3C,a     ;Set all scan row 0 lines to output mode                
				mov		Scanout3,a
				ret	
;----------------------------------------------------------------------------




PUBLIC			examine_kb_state
public			setled
public			MoveKeyboardData
public			get_kb_matrix_end_pcl
public			get_kb_matrix_start_pcl
public			kb_suspend
public			KB_INITIAL
public			kb_io_config

END

⌨️ 快捷键说明

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