分类: 嵌入式
2010-01-05 16:04:59
$$$$$$$$$$ crt0.S $$$$$$$$$$$$$$
;****************************************
file:crt0.S
; 功能:通过它转入C程序
;*******************************************
IMPORT Main
AREA KEY_LED, CODE, READONLY
ENTRY
CODE32
START ldr r0, =0x53000000 ; WATCHDOG寄存器地址
mov r1, #0x0
str r1, [r0] ; 写入0,禁止WATCHDOG,否则CPU会不断重启
ldr sp, =1024*100
bl Main ; 调用C程序中的main函数
halt_loop
b halt_loop
END
^^^^^^^^^^^^^^^ key_led.c ^^^^^^^^^^^
#define GPBCON (*(volatile unsigned long *)0x56000010)
#define GPBDAT (*(volatile unsigned long *)0x56000014)
#define GPGCON (*(volatile unsigned long *)0x56000060)
#define GPGDAT (*(volatile unsigned long *)0x56000064)
/*
* LED1-4对应GPB5、GPB6、GPB7、GPB8
*/
#define GPB5_out (1<<(5*2))
#define GPB6_out (1<<(6*2))
#define GPB7_out (1<<(7*2))
#define GPB8_out (1<<(8*2))
/*
* K1-K4对应GPG6、GPG5、GPG3、GPG0
*/
#define GPG6_in ~(3<<(6*2))
#define GPG5_in ~(3<<(5*2))
#define GPG3_in ~(3<<(3*2))
#define GPG0_in ~(3<<(0*2))
int Main()
{
unsigned long dwDat;
// LED1-LED4对应的4根引脚设为输出
GPBCON = GPB5_out | GPB6_out | GPB7_out | GPB8_out ;
// K1-K4对应的2根引脚设为输入
GPGCON = GPG6_in & GPG5_in & GPG3_in & GPG0_in;
while(1){
//若Kn为0(表示按下),则令LEDn为0(表示点亮)
dwDat = GPGDAT; // 读取GPG管脚电平状态
if (dwDat & (1<<0)) // K1没有按下
GPBDAT |= (1<<5); // LED1熄灭
else
GPBDAT &= ~(1<<5); // LED1点亮
if (dwDat & (1<<3)) // K2没有按下
GPBDAT |= (1<<6); // LED2熄灭
else
GPBDAT &= ~(1<<6); // LED2点亮
if (dwDat & (1<<5)) // K3没有按下
GPBDAT |= (1<<7); // LED3熄灭
else
GPBDAT &= ~(1<<7); // LED3点亮
if (dwDat & (1<<6)) // K4没有按下
GPBDAT |= (1<<8); // LED4熄灭
else
GPBDAT &= ~(1<<8); // LED4点亮
}
return 0;
}