LED驱动-创建一个工程
1.汇编入口start.S
.global _start
.align 2
.text
_start:
bl entry
.end
2.主文件app.c
#include "led.h"
void entry()
{
led_init();
int i = 30;
while(i--)
{
led_on_all();
delay(0xfffff);
led_off_all();
delay(0xfffff);
}
}
3.led头文件led.h
#ifndef __LED_H__
#define __LED_H__
#define GPM4CON (*(unsigned int *)0x110002e0)
#define GPM4DAT (*(unsigned int *)0x110002e4)
#endif
4.led驱动 led.c
#include "led.h"
void delay(int i)
{
while(i--);
}
void led_init()
{
GPM4CON = 0x1111;
}
void led_on_all()
{
GPM4DAT = 0x0;
}
void led_off_all()
{
GPM4DAT = 0xf;
}
void led_on(int i)
{
GPM4DAT &= ~(0x1<<i);
}
void led_off(int i)
{
GPM4DAT |= 0x1<<i;
}
5.makefile
# 1. arm-linux-gcc -c start.S -o start.o
# 2. arm-linux-gcc -c led.c -o led.o
# 3. arm-linux-gcc -c app.c -o app.o
# 4. arm-linux-ld -Ttext=0x40008000 start.o led.o app.o -o led
# 5. arm-linux-objcopy -O binary led led.bin
#######################################
TARGET=arm
BIN=$(TARGET).bin
OBJS=app.o led.o
OBJS_S=start.o
#######################################
CROSS_COMPILE=arm-linux-
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
OBJCOPY=$(CROSS_COMPILE)objcopy
#######################################
$(BIN):$(TARGET)
$(OBJCOPY) -O binary $< $@
$(TARGET):$(OBJS_S) $(OBJS)
$(LD) -Ttext=0x40008000 $^ -o $@
%.o:%.S
$(CC) -c $< -o $@
%.o:%.c
$(CC) -c $< -o $@
#######################################
.PHONY:clean
clean:
rm -rf *.o $(TARGET) $(BIN)
6.编译链接
>$ make
7.执行过程
连接好开发板
打开minicom
开发板 dnw 40008000
PC端 dnw arm.bin
开发板 go 40008000
8.试验结果
开发板核心板上led1~led4交替闪烁
热门评论
没有OS啊!