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

📄 bbu_keypad.s

📁 关于PXA310的最小系统的程序,初级学习阶段会有所帮助,汇编语言编写的
💻 S
📖 第 1 页 / 共 3 页
字号:
        ldr     r0,     =BBU_KEYP_MSG20 ; Keypad Register message
        bl      BBU_putstr              ; Output message
        ldr     r4,     =bbu_stat_data          ; Get address where system status data stored
        ldr     r2,     [r4]                    ; Get system status word
        orr     r2,     r2,     #BBU_STAT_KEYR  ; Set BBU Keypad Regester dump
        str     r2,     [r4]                    ; Update system status word
        b      %B542                            ; Yes - loop back

103     cmp     r4,     #'K'            ; Was a K entered?
        bne     %F104                   ; No - take exit path
        ldr     r0,     =BBU_KEYP_MSG21 ; Keypad Key message
        bl      BBU_putstr              ; Output message
        ldr     r4,     =bbu_stat_data  ; Get address where system status data stored
        ldr     r2,     [r4]                    ; Get system status word
        bic     r2,     r2,     #BBU_STAT_KEYR  ; Clear BBU Keypad Regester dump
        str     r2,     [r4]            ; Update system status word
        b      %B542                    ; Yes - loop back
;
;       Any other key will cause an exit
;
104     bl      BBU_crlf                ; New line
        mov     r0,     #7              ; Enable interrupts
        bl      BBU_KEYPAD_Enable_Int   ; Enable Keypad interrupts
        ldmfd   sp!,    {r0-r12, pc}    ; Restore used registers and return to caller
;
;       Keypad Decode lookup table
;
KEY_D   DCB     0x00,'1', 0x10,'2', 0x20,'3', 0x01,'4', 0x11,'5', 0x21,'6'
        DCB     0x02,'7', 0x12,'8', 0x22,'9', 0x03,'*', 0x13,'0', 0x23,'#'
        DCB     0x30,1,   0x31,2,   0x40,3,   0x41,4,   0x32,5,   0x33,6
        DCB     0x42,7,   0x43,8,   0x50,9,   0x51,10,  0x52,11,  0x53,12
        DCB     0x54,13
        DCB     0xFF,'?'        ; Marks the end of the table
                            
;
;       KEYP Messages
;
BBU_KEYP_MSG1   DCB   "keyp-->                    ** Keypad Test **",0XD,0XA
                DCB   "        Pressing a key on the keypad will display the key data.",0XD,0XA
                DCB   "        Press the K key on the host keyboard to decode key presses.",0XD,0XA
                DCB   "        Press the R yey on the host keyboard to dump registers.",0XD,0XA
                DCB   "        Press any other key on the host keyboard to exit the test.",0xD,0xA,0
BBU_KEYP_MSG5   DCB   "keyp--> KPAS     = ",0
BBU_KEYP_MSG6   DCB   "keyp--> KPASMKP0 = ",0
BBU_KEYP_MSG7   DCB   "keyp--> KPASMKP1 = ",0
BBU_KEYP_MSG8   DCB   "keyp--> KPASMKP2 = ",0
BBU_KEYP_MSG9   DCB   "keyp--> KPASMKP3 = ",0
BBU_KEYP_MSG10  DCB   "keyp--> KPREC    = ",0
BBU_KEYP_MSG11  DCB   " (Scroll wheel data)",0xD,0xA,0xA,0
BBU_KEYP_MSG20  DCB   0x8,0x20,0xD,0xA,"keyp--> Key presses will be displayed as register dumps.",0xD,0xA,0xA,0
BBU_KEYP_MSG21  DCB   0x8,0x20,0xD,0xA,"keyp--> Key presses will be decoded into key function.",0xD,0xA,0xA,0
BBU_KEYP_MSG23  DCB   0xD,0xA,"keyp--> Multiple key press detected!",0xD,0xA,0
BBU_KEYP_SPK1   DCB   "<SOFT1>",0
BBU_KEYP_SPK2   DCB   "<SOFT2>",0
BBU_KEYP_SPK3   DCB   "<SEND>",0
BBU_KEYP_SPK4   DCB   "<END>",0
BBU_KEYP_SPK5   DCB   "<HOME>",0
BBU_KEYP_SPK6   DCB   "<BACK>",0
BBU_KEYP_SPK7   DCB   "<VOL_UP>",0
BBU_KEYP_SPK8   DCB   "<VOL_DN>",0
BBU_KEYP_SPK9   DCB   "<UP>",0
BBU_KEYP_SPK10  DCB   "<DOWN>",0
BBU_KEYP_SPK11  DCB   "<LEFT>",0
BBU_KEYP_SPK12  DCB   "<RIGHT>",0
BBU_KEYP_SPK13  DCB   "<OK>",0

        ALIGN   4
;*********************************************************************************
;
;       *********************
;       *                   * 
;       * bbu_Keypad_getchro * Subroutine
;       *                   *
;       *********************
;
; This subroutine gets scan data from the keypad
;
; PARAMETER PASSING:
;
;
; NOTES:
;
;    1. This subroutine uses r1-r8 and r12 and does not preserve the previous values
;
;
bbu_Keypad_getchro   FUNCTION  ;  (Old function - to be replaced with updated one below)
;
;       Load keypad controller base address - get encoder status
;
        ldr     r1,     =bbu_KEYPAD_PHYSICAL_BASE       ; Get keypad registers base address
        ldr     r12,    [r1, #bbu_KPREC_offset]         ; Get contents of KPREC register
        mov     r2,      #0                             ; Clear r2 (character return byte)
;
;       See if the scroll wheel was pressed
;
        ldr     r3,     [r1,  #bbu_KPC_offset]  ; Get the contents of the KP control register
        mov     r5,     r3                      ; copy it to r5
        ands    r3,     r3,     #bbu_KPC_DI     ; Was there a direct keypad interrrupt?
        beq     %F1                             ; No - skip direct input check
        ldr     r3,     [r1, #bbu_KPDK_offset]  ; Get Keypad direct Key input
        mov     r4,     #0x4                    ; Load mask bit for scroll wheel push
        ands    r3,     r3,     r4              ; Mask the scroll wheel push switch
        movne   r2,     #'P'                    ; Move 'P' into the return buffer if bit was set
        bne     %F5                             ; Take exit path
;
; Some key was pressed - for now just get the data are return
;
1       ldr     r4,     [r1, #bbu_KPAS_offset]          ; Get KPAS value
        ldr     r5,     [r1, #bbu_KPASMKP0_offset]      ; Get KPASMKP0 value
        ldr     r6,     [r1, #bbu_KPASMKP1_offset]      ; Get KPASMKP1 value
        ldr     r7,     [r1, #bbu_KPASMKP2_offset]      ; Get KPASMKP2 value
        ldr     r8,     [r1, #bbu_KPASMKP3_offset]      ; Get KPASMKP3 value

5       mov     pc,     lr                              ; Return to caller
        ENDFUNC
;*********************************************************************************
;
;       *********************
;       *                   * 
;       * bbu_Keypad_getchr * Subroutine
;       *                   *
;       *********************
;
; This subroutine gets scan data from the keypad
;
; PARAMETER PASSING:
;
;       INPUT:
;         No parameters required
;
;       OUTPUT:
;         r0 = contents of the KPAS register  (key press data)
;         r1 = bits 7:0 of the KPREC register (scroll wheel data)
;
;
BBU_KEYPAD_getchr   FUNCTION

        stmfd   sp!,    {r2, lr}        ; Save used registers and link on stack
;
;       Load keypad controller base address - get encoder status
;
        ldr     r2,     =bbu_KEYPAD_PHYSICAL_BASE       ; Get keypad registers base address
        ldr     r0,     [r2, #bbu_KPC_offset]           ; Dummy read to clear read status
        ldr     r0,     [r2, #bbu_KPAS_offset]          ; Get KPAS value
        ldr     r1,     [r2, #bbu_KPREC_offset]         ; Get contents of KPREC register
        and     r1,     r1,     #0xFF                   ; Save off bits 7:0

        ldmfd   sp!,    {r2, pc}        ; Restore used registers and return to caller
        ENDFUNC
;
;*********************************************************************************
;
;       *************************
;       *                       * 
;       * BBU_Enable_KEYPAD_Int * Subroutine
;       *                       *
;       *************************
;
; This fuction enables interrupts from the platform KEYPAD
;
;       INPUT:
;
;               r0 = 0 to disable interrupts
;               r0 = 1 to enable interrupts
;
BBU_KEYPAD_Enable_Int   FUNCTION
;
        stmfd   sp!,    {r1-r2, lr}     ; Save used registers
;
;       Enable KEYPAD interrupts in the KEYPAD controller
;
        ldr     r1,     =bbu_KEYPAD_PHYSICAL_BASE       ; Get keypad registers base address

        ldr     r2,     [r1, #bbu_KPC_offset]   ; Get the contents of the KP control register
        bic     r2,     r2,     #bbu_KPC_MIE    ; Clear the interrupt enable bit
        cmp     r0,     #0                      ; Set or clear interrupts?
        orrne   r2,     r2,     #bbu_KPC_MIE    ; Non-zero = Set the Matrix Interrupt Enable bit
        str     r2,     [r1, #bbu_KPC_offset]   ; Write back to set/clear interrupts

        ldmfd   sp!,    {r1-r2, pc}     ; Restore used registers & return to caller
        ENDFUNC
;
;*********************************************************************************
;
;       ********************
;       *                  * 
;       * BBU_KEYPAD_INPUT * Subroutine
;       *                  *
;       ********************
;
; This fuction processes keypad data after a keypad interrupt has been detected
;
;       INPUT:
;
;         This code picks up the data from BBU's keypad buffer
;
BBU_KEYPAD_INPUT        FUNCTION
;
        stmfd   sp!,    {r0-r6, lr}     ; Save used registers
;
;       ALWAYS RUN IN LCD FRAME BUFFER 0
;
        mov     r0,     #0      ; Select frame buffer 0
        bl      BBU_LCD_FRAME   ; Select this frame buffer 

        ldr     r0,     =ISR_KEYPAD_KP  ; Location where keypad data was saved
        ldrb    r1,     [r0]            ; Fetch the data
;
;       Once the data has been fetched - clear the bit in the bbu_cmd_status word
;       to indicate this data has been fetched.
;
        ldr     r2,     =bbu_cmd_status ; Get address of BBU command status word
        ldr     r3,     [r2]                    ; Get the data
        bic     r3,     r3,     #BBU_CMD_KEYPAD ; Clear this bit
        str     r3,     [r2]                    ; Write the status back
;
;       First test to see if BBU is in keypad input mode. At boot up BBU defaults
;       to the UART for input but monitors the keypad for input as well. If the
;       user presses the <OK> button 10 times in a row, BBU replaces the welcome
;       message with the keypad input screen.
;
        ldr     r3,     =BBU_KISW       ; Address of status Keypad Input Status Word
        ldrb    r2,     [r3]            ; Fetch the status
        cmp     r2,     #0              ; Already in keypad input mode?
        bne     %F50                    ; Yes - skip to code
;
;       Not in keypad mode - the only keypad input accepted is the <OK> button. If
;       anything else is entered, the counter is reset to zero.
;
        ldr     r0,     =BBU_KISPB      ; Address of status Keypad Scratch Pad Byte
        ldrb    r2,     [r0]            ; Fetch the SPB contents
        cmp     r1,     #0x54           ; Did the user press <OK>?
        movne   r2,     #0              ; No - clear this register
        addeq   r2,     r2,     #1      ; Yes - increment the <OK> count
        strb    r2,     [r0]            ; Save the updated status
        bne     %F99                    ; Exit path if <OK> not pressed
        cmp     r2,     #10             ; Was this the 10th sucessive push?         
        bne     %F99                    ; No - just exit
;
;       Switch to KEYPAD Input Mode
;
        ldrb    r2,     [r3]            ; Fetch Keypad status byte
        orr     r2,     r2,      #1     ; Set the LSB
        strb    r2,     [r3]            ; Save the byte
        ldr     r0,     =BBU_KPCP       ; Address where KeyPad Command Pointer is saved
        ldr     r1,     [r0]            ; Get address contents
        cmp     r1,     #0              ; Is it zero?
        ldreq   r1,     =BBU_KP_CMDS    ; Yes - point to top of command list
        str     r1,     [r0]            ; Save off this value
;
;       Set up the LCD
;
        ldr     r0,     =BBU_BG_COLOR   ; This is where the background color is stored
        ldr     r1,     =0xF800         ; Change background color to RED
        strh    r1,     [r0]            ; Update background color
        ldr     r0,     =BBU_TX_COLOR   ; This is where the background color is stored
        ldr     r1,     =0xFFFF         ; Change background color to WHITE
        strh    r1,     [r0]            ; Update background color
        mov     r0,     #0              ; Line #0
        mov     r1,     #0              ; Column #0
        ldr     r2,     =BBU_KPIN_BL20  ; Blank line 
        bl      BBU_LCD_put16x20str     ; Send it out 
        add     r0,     r0,     #1      ; Move down a line
        ldr     r2,     =BBU_KPIN_HDR0  ; Header line 0
        bl      BBU_LCD_put16x20str     ; Send it out
        add     r0,     r0,     #1      ; Move down a line
        ldr     r2,     =BBU_KPIN_BL20  ; Blank line 
        bl      BBU_LCD_put16x20str     ; Send it out  
        ldr     r0,     =BBU_BG_COLOR   ; This is where the background color is stored
        ldr     r1,     =0x0000         ; Change background color to BLACK
        strh    r1,     [r0]            ; Update background color
        mov     r0,     #3              ; Line 3
        mov     r1,     #0              ; Column 0
        ldr     r2,     =BBU_KPIN_BL16  ; Blank line
        bl      BBU_LCD_put11x16str     ; Output this string
        add     r0,     r0,     #1      ; Move down a line
        ldr     r2,     =BBU_KPIN_HDR1  ; Header line 1
        bl      BBU_LCD_put11x16str     ; Output this string
        add     r0,     r0,     #1      ; Go to the next line
        ldr     r2,     =BBU_KPIN_HDR2  ; Header line 2
        bl      BBU_LCD_put11x16str     ; Output this string
        add     r0,     r0,     #1      ; Go to the next line
        ldr     r2,     =BBU_KPIN_BL16  ; Blank line
        bl      BBU_LCD_put11x16str     ; Output this string        
;
;       Display updated command list
;
50      ldr     r0,     =BBU_BG_COLOR   ; This is where the background color is stored
        ldr     r3,     =0x07FF         ; Change background color to CYAN
        strh    r3,     [r0]            ; Update background color
        ldr     r0,     =BBU_TX_COLOR   ; This is where the background color is stored
        ldr     r3,     =0x0000         ; Change background color to BLACK
        strh    r3,     [r0]            ; Update background color
;
;       See what the user entered and take the selected action
;       Did the user push <UP>?
;
        cmp     r1,     #0x50           ; Move down the command list? <UP> pushed?
        bne     %F51                    ; No - skip the following
        ldr     r3,     =BBU_KPCP       ; Address of Keypad Command Pointer
        ldr     r2,     [r3]            ; Fetch the pointer
        bl      BBU_KPIN_NCR            ; Get pointer to next command up the list...
        str     r2,     [r3]            ; ...and save the pointer
;
;       Did the user push <DOWN>?
;

⌨️ 快捷键说明

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