咱们的LED在核心板上,所以需要看核心板的原理图
打开核心板原理图(Tiny4412-1412-Schematic.pdf)
由上图可知,Tiny4412有4个用户LED灯,控制它们四个引脚分别是GPM4_0~ GPM4_3,由原理可知,当IO引脚为高电平时,LED灯灭,当IO引脚为低电平时LED亮。我们要做的工作就是设置GPM4_0~ GPM4_3为输出功能,且控制且输出电平高低即可。
由原理图可知,程序只进行了两步操作。
第一步:设置GPM4_0~GPM4_3相对应的控制寄存器GPM4CON,使GPM4_0 GPM4_3四个引脚为输出功能。
第二步:设置其对应的数据寄存器GPM4DAT对应的4个bit位为0,使GPM4_0~ GPM4_3为低电平,4个LED灯全亮,使GPM4_0~ GPM4_3全为高电平,4个LED灯全灭。
将所有的灯全部都亮
.section .rodata
.align 2
.LC0:
.string "led all on\n"
.section .text
.align 2
.global _start
_start:
stmfd sp!, {lr}
@配置为输出
ldr r0, =0x110002E0
ldr r1, [r0]
ldr r2, =0xffff
bic r1, r1, r2
@0x1 = Output
ldr r2, =0x1111
orr r1, r1, r2
str r1, [r0]
@设置低电平
ldr r0, =0x110002E4
ldr r1, [r0]
bic r1, r1, #0xf
str r1, [r0]
@output led all on
ldr r0, =.LC0
mov lr, pc
ldr pc, =0x43e11a2c
ldmfd sp!, {pc}
Makefile
all:
arm-linux-gcc -c test.s -o test.o
arm-linux-ld -Ttext=0x40008000 test.o -o test
arm-linux-objcopy -O binary test test.bin
.PHONY:clean
clean:
rm -rf test.o test test.bin
将所有的灯全部都灭
.section .rodata
.align 2
.LC0:
.string "led all off\n"
.section .text
.align 2
.global _start
_start:
stmfd sp!, {lr}
@配置为输出
ldr r0, =0x110002E0
ldr r1, [r0]
ldr r2, =0xffff
bic r1, r1, r2
ldr r2, =0x1111
orr r1, r1, r2
str r1, [r0]
@设置低点平
ldr r0, =0x110002E4
ldr r1, [r0]
orr r1, r1, #0xf
str r1, [r0]
@output led all on
ldr r0, =.LC0
mov lr, pc
ldr pc, =0x43e11a2c
ldmfd sp!, {pc}
所有led闪烁
.section .rodata
.align 2
.LC0:
.string "led all off\n"
.section .text
.align 2
.global _start
_start:
stmfd sp!, {lr}
@配置为输出
ldr r0, =0x110002E0
ldr r1, [r0]
ldr r2, =0xffff
bic r1, r1, r2
ldr r2, =0x1111
orr r1, r1, r2
str r1, [r0]
1:
@off
ldr r0, =0x110002E4
ldr r1, [r0]
orr r1, r1, #0xf
str r1, [r0]
@sleep 1
ldr r0, =1000000
mov lr, pc
ldr pc, =0x43e26480
@on
ldr r0, =0x110002E4
ldr r1, [r0]
bic r1, r1, #0xf
str r1, [r0]
@sleep 1
ldr r0, =1000000
mov lr, pc
ldr pc, =0x43e26480
b 1b
ldmfd sp!, {pc}
Exynos 4412 SCP_Users Manual_Ver.0.10.00_Preliminary0.pdf