新闻中心

EEPW首页>嵌入式系统>设计应用> GPIO(二)C程序

GPIO(二)C程序

作者: 时间:2016-11-22 来源:网络 收藏
@******************************************************************************

@ File:crt0.S
@ 功能:通过它转入C程序
@******************************************************************************

本文引用地址://m.amcfsurvey.com/article/201611/319965.htm

.text
.global _start
_start:
ldr r0, =0x53000000 @ WATCHDOG寄存器地址
mov r1, #0x0
str r1, [r0] @ 写入0,禁止WATCHDOG,否则CPU会不断重启

ldr sp, =1024*4 @ 设置堆栈,注意:不能大于4k, 因为现在可用的内存只有4K
@ nand flash中的代码在复位后会移到内部ram中,此ram只有4K
bl main @ 调用C程序中的main函数
halt_loop:
b halt_loop

#define GPBCON (*(volatile unsigned long *)0x56000010)
#define GPBDAT (*(volatile unsigned long *)0x56000014)

int main()
{
GPBCON = 0x00015400; // 设置GPB5-8为输出口
//[11:10]=0b01,[13:12]=0b01,
//[15:14]=0b01,[17:16]=0b01,
GPBDAT = 0x00000000; // GPB5-8输出0,LED1点亮

return 0;
}

使用如下命令进行编译和连接

arm-linux-gcc -g -c -o crt0.o crt0.S
arm-linux-gcc -g -c -nostdlib -oled_on_c.o led_on_c.c
arm-linux-ld -Ttext 0x0000000 -g crt0.o led_on_c.o -o led_on_c_elf
arm-linux-objcopy -O binary -S led_on_c_elf led_on_c.bin



关键词:GPIOC程

评论


技术专区

关闭