FS2410開發(fā)板的測試鍵盤的ADS匯編代碼
;鍵盤掃描
; 4X4 矩陣鍵盤
;四個(gè)輸入引腳: EINT0 -----( GPF0 )----INPUT
; EINT2 -----( GPF2 )----INPUT
; EINT11-----( GPG3 )----INPUT
; EINT19-----( GPG11 )----INPUT
;
;四個(gè)輸出引腳: KEYSCAN0---( GPE11 )----OUTPUT
; KEYSCAN1---( GPG6 )----OUTPUT
; KEYSCAN2---( GPE13 )----OUTPUT
; KEYSCAN3---( GPG2 )----OUTPUT
;GPG2,6 GPE11,13 行控制線
;GPG11,3 GPF2,0 列控制線
;GPF4,5,6,7 控制led以二進(jìn)制碼顯示鍵盤值
rGPECON equ 0x56000040 ;Port E control
rGPEDAT equ 0x56000044 ;Port E data
rGPEUP equ 0x56000048 ;Pull-up control E
rGPFCON equ 0x56000050 ;Port F control
rGPFDAT equ 0x56000054 ;Port F data
rGPFUP equ 0x56000058 ;Pull-up control F
rGPGCON equ 0x56000060 ;Port G control
rGPGDAT equ 0x56000064 ;Port G data
rGPGUP equ 0x56000068 ;Pull-up control G
area keydat,data,readonly
;第4行鍵值轉(zhuǎn)換數(shù)據(jù)
keytrans dcb 13,0,0,14,0,0,15,0,0,16,0,0
;鍵值對應(yīng)LED顯示的二進(jìn)制數(shù)據(jù)
keyledcode dcb 0,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0,0,0,0,0,0,0,0
area kayasm,code,readonly
code32
entry
start
mov sp,#0x0c700000
;以下代碼初始化GPIO
ldr r1,=0x5500 ;GPF4,5,6,7控制LED,設(shè)置為輸出口,其他設(shè)置為輸入
ldr r0,=rGPFCON
str r1,[r0]
;禁止內(nèi)部上拉電阻
ldr r1,=0xff
ldr r0,=rGPFUP
str r1,[r0]
;輸出1,使LED全滅
mov r1,#0xffffffff
ldr r0,=rGPFDAT
str r1,[r0]
;GPG6,2輸出
ldr r0,=rGPGCON
ldr r1,[r0]
ldr r3,=0x2020
bic r1,r1,r3
ldr r3,=0x1010
orr r1,r1,r3
str r1,[r0]
;GPG6,2輸出0
ldr r0,=rGPGDAT
mov r1,#0
str r1,[r0]
;GPE11,13輸出
ldr r0,=rGPECON
ldr r1,[r0]
bic r1,r1,#0x08800000
orr r1,r1,#0x04400000
str r1,[r0]
ldr r0,=rGPEDAT
mov r1,#0
str r1,[r0]
;GPG3,11輸入
ldr r0,=rGPGCON
ldr r1,[r0]
ldr r3,=0x00c000c0
bic r1,r1,r3
str r1,[r0]
;GPF2,0輸入
ldr r0,=rGPFCON
ldr r1,[r0]
bic r1,r1,#0x33
str r1,[r0]
;以下代碼掃描鍵盤
;逐行輸出0,GPG6,2 GPE11,13
;讀取列值GPF2,0 GPG3,11
keyscan
;第1行,GPG2=1,GPG6=1,GPE11=0,GPE13=1
ldr r0,=rGPGDAT
ldr r1,[r0]
orr r1,r1,#0x44 ;GPG2=GPG6=1
str r1,[r0]
ldr r0,=rGPEDAT
ldr r1,[r0]
orr r1,r1,#0x2000 ;GPE13=1
bic r1,r1,#0x800 ;GPE11=0
str r1,[r0]
mov r0,#1
bl genkey
cmp r0,#0
bne havekey
;第2行,GPG2=1,GPG6=0,GPE11=GPE13=1
ldr r0,=rGPGDAT
ldr r1,[r0]
bic r1,r1,#0x40 ;GPG6=0
orr r1,r1,#4 ;GPG2=1
str r1,[r0]
ldr r0,=rGPEDAT
ldr r1,[r0]
orr r1,r1,#0x2800 ;GPE11,13=1
str r1,[r0]
mov r0,#2
bl genkey
cmp r0,#0
bne havekey
;第3行,GPG2=1,GPG6=1,GPE11=1,GPE13=0
ldr r0,=rGPGDAT
ldr r1,[r0]
orr r1,r1,#0x44 ;GPG2=GPG6=1
str r1,[r0]
ldr r0,=rGPEDAT
ldr r1,[r0]
orr r1,r1,#0x800 ;GPE11=1
bic r1,r1,#0x2000 ;GPE13=0
str r1,[r0]
mov r0,#3
bl genkey
cmp r0,#0
bne havekey
;第4行,GPG2=0,GPG6=1,GPE11=GPE13=1
ldr r0,=rGPGDAT
ldr r1,[r0]
orr r1,r1,#0x40 ;GPG6=1
bic r1,r1,#4 ;GPG2=0
str r1,[r0]
ldr r0,=rGPEDAT
ldr r1,[r0]
orr r1,r1,#0x2800 ;GPE11,13=1
str r1,[r0]
mov r0,#4
bl genkey
cmp r0,#0
bne havekey
b keyscan
havekey
ldr r1,=rGPFDAT
mov r4,#0xff
str r4,[r1]
ldr r2,=keyledcode
ldrb r3,[r2,r0]
mvn r2,r3
str r2,[r1]
b keyscan
export genkey
;通過讀取列值獲取鍵值子程序
;入口參數(shù): r0, 第幾行1~4
;出口參數(shù): r0, 所得到的鍵號(1~16), 0表示沒有鍵按下
;讀取列值,讀取GPG11,GPG3 GPF2,GPF0
;內(nèi)部使用r4-r7
genkey
;暫存行值
mov r7,r0
;讀取列值
ldr r4,=rGPGDAT
ldr r5,[r4]
mov r6,r5
ands r6,r6,#0x800 ;GPG11
moveq r0,#0
beq keycac
mov r6,r5
ands r6,r6,#8 ;GPG3
moveq r0,#3
beq keycac
ldr r4,=rGPFDAT
ldr r5,[r4]
mov r6,r5
ands r6,r6,#4 ;GPF2
moveq r0,#6
beq keycac
mov r6,r5
ands r6,r6,#1 ;GPF0
moveq r0,#9
beq keycac
mov r0,#0
b keyret
keycac
cmp r7,#4
blo simplecac
ldr r4,=keytrans
ldrb r0,[r4,r0]
b keyret
simplecac
add r0,r0,r7
keyret
mov pc,lr
end
評論