Fork me on GitHub

【嵌入式学习分享】2.裸板LED(c语言)

start.s:

.global _start
_start:
/ 关看门狗 /
/ 往WTCON(0x53000000)写0 /
ldr r0, =0x53000000
mov r1, #0
str r1, [r0]

/ 设置栈 /
ldr sp, =41024
/ 调用c */
bl czp

halt:
b halt

led_test.c:
void delay()
{
volatile int j = 0x10000;
while(j –);
}

int czp()
{
int i = 0;
volatile unsigned long GPBCON = (volatile unsigned long )0x56000010;
volatile unsigned long GPBDAT = (volatile unsigned long )0x56000014;

/ GPB5-7 输出 /
GPBCON = 0x15400;
GPBDAT = 0;
while(1)
{
*GPBDAT = i;
i += (1 << 6);
if(i >= (16 << 5)) i = 0;
delay();
}
return 0;
}

Makefile:

led.bin:start.o led.o
arm-linux-ld -Ttext 0 -o led.elf start.o led.o
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led.dis
start.o:start.s
arm-linux-gcc -o start.o start.s -c
led.o:led_test.c
arm-linux-gcc -o led.o led_test.c -c