00. 目录
01. 控制原理
咱们的LED在核心板上,所以需要看核心板的原理图
打开核心板原理图(Tiny4412-1412-Schematic.pdf)
由上图可知,Tiny4412有4个用户LED灯,控制它们四个引脚分别是GPM4_0~ GPM4_3,由原理可知,当IO引脚为高电平时,LED灯灭,当IO引脚为低电平时LED亮。我们要做的工作就是设置GPM4_0~ GPM4_3为输出功能,且控制且输出电平高低即可。
02. 配置寄存器
由原理图可知,程序只进行了两步操作。
第一步:设置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灯全灭。
03. 程序示例一
所有led闪烁 汇编函数
.section .rodata
.align 2
.LC0:
.string "led all off\n"
.section .text
.align 2
.global _start
_start:
stmfd sp!, {lr}
bl led_init
1:
bl led_alloff
ldr r0, =1000000
bl led_delay
bl led_allon
ldr r0, =1000000
bl led_delay
b 1b
ldmfd sp!, {pc}
.align 2
.global led_init
led_init:
@配置为输出
ldr r0, =0x110002E0
ldr r1, [r0]
ldr r2, =0xffff
bic r1, r1, r2
ldr r2, =0x1111
orr r1, r1, r2
str r1, [r0]
mov pc, lr
.align 2
.global led_allon
led_allon:
ldr r0, =0x110002E4
ldr r1, [r0]
bic r1, r1, #0xf
str r1, [r0]
mov pc, lr
.align 2
.global led_alloff
led_alloff:
ldr r0, =0x110002E4
ldr r1, [r0]
orr r1, r1, #0xf
str r1, [r0]
mov pc, lr
.align 2
.global led_delay
led_delay:
stmfd sp!, {lr}
mov lr, pc
ldr pc, =0x43e26480
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
04. 程序示例二
所有led闪烁 汇编函数 多文件操作
lib.s文件内容如下
.section .text
.align 2
.global led_delay
led_delay:
stmfd sp!, {lr}
mov lr, pc
ldr pc, =0x43e26480
ldmfd sp!, {pc}
led.s文件内容如下
.section .text
.align 2
.global led_init
led_init:
@配置为输出
ldr r0, =0x110002E0
ldr r1, [r0]
ldr r2, =0xffff
bic r1, r1, r2
ldr r2, =0x1111
orr r1, r1, r2
str r1, [r0]
mov pc, lr
.align 2
.global led_allon
led_allon:
ldr r0, =0x110002E4
ldr r1, [r0]
bic r1, r1, #0xf
str r1, [r0]
mov pc, lr
.align 2
.global led_alloff
led_alloff:
ldr r0, =0x110002E4
ldr r1, [r0]
orr r1, r1, #0xf
str r1, [r0]
mov pc, lr
test.s文件内容如下:
.section .rodata
.align 2
.LC0:
.string "led all off\n"
.section .text
.align 2
.global _start
_start:
stmfd sp!, {lr}
bl led_init
1:
bl led_alloff
ldr r0, =1000000
bl led_delay
bl led_allon
ldr r0, =1000000
bl led_delay
b 1b
ldmfd sp!, {pc}
Makefile文件
all:
arm-linux-gcc -c test.s -o test.o
arm-linux-gcc -c led.s -o led.o
arm-linux-gcc -c lib.s -o lib.o
arm-linux-ld -Ttext=0x40000000 test.o lib.o led.o -o test
arm-linux-objcopy -O binary test test.bin
.PHONY:clean
clean:
rm -rf *.o test test.bin
05. 程序示例三
跑马灯程序
lib.s文件内容
.align 2
.global led_delay
led_delay:
stmfd sp!, {lr}
mov lr, pc
ldr pc, =0x43e26480
ldmfd sp!, {pc}
led.s文件内容
.section .text
.align 2
.global led_init
led_init:
@配置为输出
ldr r0, =0x110002E0
ldr r1, [r0]
ldr r2, =0xffff
bic r1, r1, r2
ldr r2, =0x1111
orr r1, r1, r2
str r1, [r0]
mov pc, lr
.align 2
.global led_allon
led_allon:
ldr r0, =0x110002E4
ldr r1, [r0]
bic r1, r1, #0xf
str r1, [r0]
mov pc, lr
.align 2
.global led_alloff
led_alloff:
ldr r0, =0x110002E4
ldr r1, [r0]
orr r1, r1, #0xf
str r1, [r0]
mov pc, lr
.align 2
.global led_on
led_on:
ldr r1, =0x110002E4
ldr r2, [r1]
mov r3, #1
bic r2, r2, r3, LSL r0
str r2, [r1]
mov pc, lr
.align 2
.global led_off
led_off:
ldr r1, =0x110002E4
ldr r2, [r1]
mov r3, #1
orr r2, r2, r3, LSL r0
str r2, [r1]
mov pc, lr
test.s文件内容
.section .rodata
.align 2
.LC0:
.string "led all off\n"
.section .text
.align 2
.global _start
_start:
stmfd sp!, {lr}
bl led_init
bl led_alloff
mov r4, #0
1:
mov r0, r4
bl led_on
ldr r0, =1000000
bl led_delay
mov r0, r4
bl led_off
ldr r0, =1000000
bl led_delay
add r4, r4, #1
cmp r4, #4
moveq r4, #0
b 1b
ldmfd sp!, {pc}
Makefile文件
all:
arm-linux-gcc -c test.s -o test.o
arm-linux-gcc -c led.s -o led.o
arm-linux-gcc -c lib.s -o lib.o
arm-linux-ld -Ttext=0x40000000 test.o lib.o led.o -o test
arm-linux-objcopy -O binary test test.bin
.PHONY:clean
clean:
rm -rf *.o test test.bin
06. 附录
Exynos 4412 SCP_Users Manual_Ver.0.10.00_Preliminary0.pdf
转载:https://blog.csdn.net/dengjin20104042056/article/details/107820291
查看评论