OK6410迴圈電燈程式,組合語言與C語言。

2021-06-08 10:12:50 字數 2994 閱讀 1297

學習筆記,高手勿笑!

組合語言迴圈點燈程式:

start.s

/******************/

/*迴圈點亮4盞led燈*/

/******************/

.globl _start

_start:

/* 硬體相關的設定 */

/* peri port setup */

ldr r0, =0x70000000

orr r0, r0, #0x13

mcr p15,0,r0,c15,c2,4 @ 256m(0x70000000-0x7fffffff)

/* 關看門狗 */

/* 往wtcon(0x7e004000)寫0 */

ldr r0, =0x7e004000

mov r1, #0

str r1, [r0]

/* 設定gpmcon讓gpm0-3作為輸出引腳 */

/*gpmcon = 0x7f008820,gpmdat 0x7f008824*/

ldr r0, =0x7f008820

ldr r1, =0x1111

str r1, [r0]

/* 設定gpmdat讓gpm3輸出0 */

ldr r1, =0x7f008824

mov r0, #0

str r0, [r1]

bl delay

loop:

/* 點亮led1 */

mov r0, #0xe

str r0,[r1]

bl delay

/* 點亮led2 */

mov r0, #0xd

str r0,[r1]

bl delay

/* 點亮led3 */

mov r0, #0xb

str r0,[r1]

bl delay

/* 點亮led4 */

mov r0, #0x7

str r0,[r1]

bl delay

b loop

/*延時*/

delay:

mov r2, #0x10000

delay_loop:

sub r2, r2,#1

cmp r2, #0

bne delay_loop

mov pc, lr

halt:

b halt

makefile

led.bin: start.o

arm-linux-ld -ttext 0 -o led.elf start.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 -c start.s

clean:

rm -f start.o led.dis led.bin led.elf

-------------------------------------

c語言迴圈點燈程式:

start.s

.globl _start

_start:

/* 硬體相關的設定 */

/* peri port setup */

ldr r0, =0x70000000

orr r0, r0, #0x13

mcr p15,0,r0,c15,c2,4

/* 關看門狗 */

/* 往wtcon(0x7e004000)寫0 */

ldr r0, =0x7e004000

mov r1, #0

str r1, [r0]

/*設定c語言語言環境*/

ldr sp, =8*1024

bl main

halt:

b halt

led.c

/*gpmcon = 0x7f008820,gpmdat  0x7f008824*/

#define gpmcon (*(volatile unsigned long *)0x7f008820)

#define gpmdat (*(volatile unsigned long *)0x7f008824)

void delay()

int main()

{ int i;

gpmcon = 0x1111;

gpmdat = 0xc;

while(1)

{ for(i = 0; i < 4;i++)

{ gpmdat = ~(1<

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 -o2

led.o : led.c

arm-linux-gcc -o led.o led.c -c -o2

clean:

rm *.o led.elf led.bin led.dis

對gpio的操作為了不影響其他位的狀態,一般採用位操作。如圖所示對gpmcon和gpmdat的修改:

OK6410裸機程式 hello world

上面已經解決 了幾個問題。現在我們的狀態 可以在pc ok6410 之間進行tftp傳輸,確定了一下可用的位址 空間,下面我們來說一下printf除錯 因為沒有jlink,只能用printf除錯,你也許會問,我們自己實現printf麼?答曰 不是,我們只是弄個hello world,何必那麼認真呢?...

OK6410裸機程式 點亮LED

globl start start 硬體相關的設定 peri port setup ldr r0,0x70000000 orr r0,r0,0x13 mcr p15,0,r0,c15,c2,4 256m 0x70000000 0x7fffffff 關看門狗 往wtcon 0x7e004000 寫0 ...

OK6410按鍵驅動 Qt程式 改 親測可以執行

include include include include include include include include include include include include include include include include include define device ...