;time 2012-12-24
;developer:MDK 4.0 and J-link v8
;developer board MINI 2440
;function: LEDs and beeper on when pressing key
;GOOD: simple
;BAD: low efficiency
;--------------------------------------------------
;macro the register
pGPBCON EQU 0x56000010
pGPBDAT EQU 0x56000014
pGPBUP EQU 0x56000018
pGPGCON EQU 0x56000060
pGPGDAT EQU 0x56000064
pGPGUP EQU 0x56000068
AREA led_key, CODE, READONLY ;define code section and its property
ENTRY ;declare this entrance of the program
NOP
;set the GPB pins with output funtion
LDR r0,= pGPBCON
LDR r1,[r0]
MOV r2,#(0x55<<10)
ORR r1,r1,r2
ADD r1,#0x1
STR r1,[r0]
;disable the poll-up
LDR r0,= pGPBUP
LDR r1,[r0]
LDR r2,=0x7ff
ORR r1,r1,r2
STR r1,[r0]
;init the output pins at the high voltage level
LDR r0,= pGPBDAT
LDR r1,[r0]
LDR r2,=0x7fe
ORR r1,r1,r2
STR r1,[r0]
NOP
NOP
;set the GPG pins with input funtion
LDR r0,= pGPGCON
MOV r1,#0x0
STR r1,[r0]
;disable the poll-up
LDR r0,= pGPGUP
LDR r1,[r0]
LDR r2,=0xffff
ORR r1,r1,r2
STR r1,[r0]
;keep the original val of pGPGDAT for comparing
LDR r0,= pGPGDAT
LDR r3,[r0]
;set looping method to check the status of inputs from key
LOOP
LDR r0,= pGPGDAT
LDR r1,[r0]
CMP r1,r3
BEQ LOOP ;no press on the keys
BNE LED_DISPLAY ;press on the keys
LED_DISPLAY
LDR r0,= pGPBDAT
LDR r1,=0x1
STR r1,[r0] ; display leds and enable beeper
BL DELAY
LDR r0,= pGPBDAT
LDR r1,=0x7fe
STR r1,[r0] ;close leds and beeper
B LOOP
DELAY
LDR r0,=0xfff
TMP
SUB r0,r0,#0x1
CMP r0,#0x0
BNE TMP
MOV pc,lr
END
转载于:https://blog.51cto.com/642364/1098611