?? leds.c
字號(hào):
/* * leds.c: 循環(huán)點(diǎn)亮4個(gè)LED * 屬于第二部分程序,此時(shí)MMU已開啟,使用虛擬地址 */ #define GPBCON (*(volatile unsigned long *)0xA0000010) // 物理地址0x56000010#define GPBDAT (*(volatile unsigned long *)0xA0000014) // 物理地址0x56000014#define GPB5_out (1<<(5*2))#define GPB6_out (1<<(6*2))#define GPB7_out (1<<(7*2))#define GPB8_out (1<<(8*2))/* * wait函數(shù)加上“static inline”是有原因的, * 這樣可以使得編譯leds.c時(shí),wait嵌入main中,編譯結(jié)果中只有main一個(gè)函數(shù)。 * 于是在連接時(shí),main函數(shù)的地址就是由連接文件指定的運(yùn)行時(shí)裝載地址。 * 而連接文件mmu.lds中,指定了leds.o的運(yùn)行時(shí)裝載地址為0xB4004000, * 這樣,head.S中的“l(fā)dr pc, =0xB4004000”就是跳去執(zhí)行main函數(shù)。 */static inline void wait(unsigned long dly){ for(; dly > 0; dly--);}int main(void){ unsigned long i = 0; // 將LED1-4對(duì)應(yīng)的GPB5/6/7/8四個(gè)引腳設(shè)為輸出 GPBCON = GPB5_out|GPB6_out|GPB7_out|GPB8_out; while(1){ wait(30000); GPBDAT = (~(i<<5)); // 根據(jù)i的值,點(diǎn)亮LED1-4 if(++i == 16) i = 0; } return 0;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -