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

📄 c_readkey.asm

📁 义隆公司eSLZ000 dsp处理芯片一个播放midi的样例程序。
💻 ASM
字号:
.IFNDEF @_C_ReadKey_ASM
@_C_ReadKey_ASM	.EQU	1


.INCLUDE "registerext.def"


.CODE

;*******************ReadKey MACRO******************************
.global _c_ReadKey

.code c_ReadKey

_c_ReadKey:
    PUSH	R3
    R3 = IO[SPA]
    R3	= R3 +#3
    
    R4	= [R3++]
    R6 	= [R3]    
    CALL @_LIB_F_DIRECTKEY
    
    POP	R3
    ret

	F_keep			.EQU 	15
	F_open			.EQU 	14
	F_push			.EQU 	13	
	//.extern P_init
 //   Port_init       .set   P_init
    ;Port_init       .EQU    0x00FF

;*******************DIRECTKEY MACRO******************************

.CODE @_LIB_F_DIRECTKEY_
//.EXTERN Port_init

.EXTERN @_LIB_F_DIRECTKEY
@_LIB_F_DIRECTKEY:    
        
                R0 =  #10000000b                      ;clera Flag exclude Flag_keep 
                R0 =  [R4]  AND R0
                //###R0              =       @_Key_flag  AND R0
                [R4] = R0
                //###@_Key_flag      =       R0 (L)
                R0 = IO[PORTB]                       ;read portBL
                R0 = R0 AND R6	;#0x00FF
                R5 = R4 + #2
                [R5] = R0  ;save to Read_buf 
                //###@_RK_buf                =       R0      (L)             ;save to Read_buf 
                R5 = R4 + #1
                R0 = R0 XOR [R5]  ;check same as old data 
                //###R0              =       R0      XOR     @_RK_port_code  ;check same as old data 
                IF      EQ      JMP     @_LIB_F_DIRECTKEY_RK_sameas                      ;read = old data 
        
;----------------------------------------------------------     
@_LIB_F_DIRECTKEY_RK_difference:
                R5 = R4 + #2
                R0              =          [R5]
                //###R0              =       @_RK_buf (L)
                Call            @_LIB_F_DIRECTKEY_GPBL_debounce                           ; have Keyin -> call debounce routing
                BTEST           R1.0
                IF TS           JMP     @_LIB_F_DIRECTKEY_RK_ret                         ; debounce fail 
                
;--------------------------------------                                 ; debounce OK
                R0              =       #0
                BS              R0.0
                R5 = R4 + #3
                [R5]    =       R0     
                //###@_RK_chk_bit    =       R0      (L)
@_LIB_F_DIRECTKEY_RK_bit_chk:
                R5 = R4 + #1
                R0        =         [R5]
                //###R0              =       @_RK_port_code (L)                              
                R5 = R4 + #2
                R0        =       R0      XOR    [R5]        ;set difference bit =1 
                //###R0              =       R0      XOR     @_RK_buf        ;set difference bit =1 
                R5 = R4 + #3
                R0        =       R0      AND     [R5]    ;diff_bit = check_bit ?
                //###R0              =       R0      AND     @_RK_chk_bit    ;diff_bit = check_bit ?
                IF      EQ      JMP     @_LIB_F_DIRECTKEY_RK_bit_next                    ;diff_bit <> check_bit to check next bit

                R5 = R4 + #1
                R0              =       [R5]              ;diff_bit = 1 or 0 
                //###R0              =       @_RK_port_code (L)              ;diff_bit = 1 or 0 
                R5 = R4 + #3
                R0              =       R0      AND     [R5]
                //###R0              =       R0      AND     @_RK_chk_bit 
                IF      EQ      JMP     @_LIB_F_DIRECTKEY_RK_h2l
@_LIB_F_DIRECTKEY_RK_l2h:                                               ;diff_bit = 1, Lo change Hi 
                
                R0              =       [R4]
                //###R0              =       @_Key_flag (L)
                BS                      R0.F_push                       ;set Flag_push 
                [R4]      =       R0
                //###@_Key_flag      =       R0 (L)  
                R5 = R4 + #3
                R0              =       [R5]                ;save to RK_port_code
                //###R0              =       @_RK_chk_bit (L)                ;save to RK_port_code
                R5 = R4 + #1
                R0              =       R0      XOR     [R5] 
                //###R0              =       R0      XOR     @_RK_port_code 
                R5 = R4 + #1
                [R5]  =       R0
                //###@_RK_port_code  =       R0 (L)
                JMP                     @_LIB_F_DIRECTKEY_RK_numb
@_LIB_F_DIRECTKEY_RK_h2l:                                               ;diff_bit = 0, Hi change Lo 
                R0              =       [R4]
                //###R0              =       @_Key_flag (L)
                BS                      R0.F_open                       ;set Flag_open 
                [R4]      =       R0  
                //###@_Key_flag      =       R0 (L)  
                R5 = R4 + #3
                R0              =       [R5]
                //###R0              =       @_RK_chk_bit (L)
                R5 = R4 + #1
                R0              =       R0      XOR     [R5]
                //###R0              =       R0      XOR     @_RK_port_code
                R5 = R4 + #1
                [R5]  =       R0  
                //###@_RK_port_code  =       R0 (L)  
                R5 = R4 + #2
                R0              =       [R5]                    ;check all open ?
                //###R0              =       @_RK_buf (L)                    ;check all open ?
                R1              =      R6 ;#Port_init                      ;RK_port_code
                CMP             R1,R0
                IF      NE      JMP     @_LIB_F_DIRECTKEY_RK_numb
                R0                      =       [R4]
                //###R0                      =       @_Key_flag (L)
                BC                      R0.F_keep                       ;all open, clear Flag_keep 
                [R4]      =       R0  
                //###@_Key_flag      =       R0 (L)  
;-------------------------------------- 
@_LIB_F_DIRECTKEY_RK_numb:                                              ;set change key number
                BC                      IO[SR].Carry
                R5 = R4 + #3
                R0              =       [R5]
                //###R0              =       @_RK_chk_bit (L)
                R0              =       SHR     R0
 ;              R5 = R4 + #3
               [R5]    =       R0  
               //### @_RK_chk_bit    =       R0 (L)  
                IF      CS      JMP     @_LIB_F_DIRECTKEY_RK_end
                R0              =       [R4]
                //###R0              =       @_Key_flag (L)
                R0              =       R0      +       #1
                [R4]      =       R0 
                //###@_Key_flag      =       R0  (L)
                JMP                     @_LIB_F_DIRECTKEY_RK_numb
;-------------------------------------- 
@_LIB_F_DIRECTKEY_RK_bit_next:                                           ;set next check bit =1
                R5 = R4 + #3
                R0              =       [R5]
                //###R0              =       @_RK_chk_bit (L)
                R0              =       SHL     R0
                R5 = R4 + #3
                [R5]    =       R0
                //###@_RK_chk_bit    =       R0 (L)
                IF      CC      JMP     @_LIB_F_DIRECTKEY_RK_bit_chk
@_LIB_F_DIRECTKEY_RK_end:                                               ;read key end
                R0=[R4]
                RET
                
;----------------------------------------------------------     
;        subcall
;----------------------------------------------------------     
@_LIB_F_DIRECTKEY_RK_sameas:                                                             ;read key same as old_data 
                R5 = R4 + #2
                R0              =       [R5]                    ;check read_buf = 0
                //###R0              =       @_RK_buf (L)                    ;check read_buf = 0
                R0              =       R0      -R6 ;#Port_init             ;;0XFFFF
                IF      EQ      JMP     @_LIB_F_DIRECTKEY_RK_ret                         ;if zero , return
                R0              =       [R4]
                //###R0              =       @_Key_flag (L)
                BS                      R0.F_keep       
                [R4]      =       R0                          ;all open 
                //###@_Key_flag      =       R0       (L)                    ;all open 
@_LIB_F_DIRECTKEY_RK_ret:                                                                ;read key fail go back 
                JMP @_LIB_F_DIRECTKEY_RK_end
                //ret
;-------------------------------------- 
;------------------------------
@_LIB_F_DIRECTKEY_GPBL_debounce:
        R2      =       #10     ;#20                    ;re-read times
@_LIB_F_DIRECTKEY_GPBL_debounce_1:
        ;R3     =       #0x3FF8                         ;delay 1ms 
        ;RPT    R3
        R3      =       #0x00FF ;#0x0FFE                ;delay 1ms 
        LOOP R3
        NOP
        NOP
        NOP
        NOP
        .ENDL
        R1      =       IO[PORTB]                       ;read portBL
        ;R1      =       R1 AND #0x00FF
         R1  =   R1 AND R6
        ;R1      =       R1 XOR  R0                     
        R5  =   R4 + #2
        R1  =  R1 XOR [R5]  ;check PortB == R0 (Portb-buf)?
        IF NE   JMP     @_LIB_F_DIRECTKEY_GPBL_debounde_fail
                
        R2      =       R2 - #1
        IF EQ   JMP     @_LIB_F_DIRECTKEY_GPBL_debounce_OK
        JMP     @_LIB_F_DIRECTKEY_GPBL_debounce_1

@_LIB_F_DIRECTKEY_GPBL_debounde_fail:                                     ; PBL difference -> debounce Fail
        R1      =       #1
        RET
@_LIB_F_DIRECTKEY_GPBL_debounce_OK:                                       ; PBL same as -> debounce OK
        R1      =       #0
        RET
;------------------------------


.ENDIF

⌨️ 快捷键说明

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