?? leds.c
字號:
/* * leds.c: 循環點亮4個LED * 屬于第二部分程序,此時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函數加上“static inline”是有原因的, * 這樣可以使得編譯leds.c時,wait嵌入main中,編譯結果中只有main一個函數。 * 于是在連接時,main函數的地址就是由連接文件指定的運行時裝載地址。 * 而連接文件mmu.lds中,指定了leds.o的運行時裝載地址為0xB4004000, * 這樣,head.S中的“ldr pc, =0xB4004000”就是跳去執行main函數。 */static inline void wait(unsigned long dly){ for(; dly > 0; dly--);}int main(void){ unsigned long i = 0; // 將LED1-4對應的GPB5/6/7/8四個引腳設為輸出 GPBCON = GPB5_out|GPB6_out|GPB7_out|GPB8_out; while(1){ wait(30000); GPBDAT = (~(i<<5)); // 根據i的值,點亮LED1-4 if(++i == 16) i = 0; } return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -