JZ2440开发板功能实现,通过按下3个开关键,控制3个LED灯的亮灭
-
.text
-
.global _start
-
_start:
-
ldr r0,=0x53000000
-
mov r1,#0x0
-
str r1,[r0]
-
-
ldr sp,=1024*4
-
-
bl main
-
loop:
-
b loop
-
#define GPFCON (*(volatile unsigned long*)0x56000050)
-
#define GPFDAT (*(volatile unsigned long*)0x56000054)
-
-
#define GPGCON (*(volatile unsigned long*)0x56000060)
-
#define GPGDAT (*(volatile unsigned long*)0x56000064)
-
-
/*LEDs*/
-
#define GPF4_OUT (1<<(2*4))
-
#define GPF5_OUT (1<<(2*5))
-
#define GPF6_OUT (1<<(2*6))
-
-
#define GPF4_MSK (3<<(2*4))
-
#define GPF5_MSK (3<<(2*5))
-
#define GPF6_MSK (3<<(2*6))
-
-
/*KEYs*/
-
#define GPF0_IN (0<<(2*0))
-
#define GPF2_IN (0<<(2*2))
-
#define GPG3_IN (0<<(2*3))
-
-
#define GPF0_MSK (3<<(2*0))
-
#define GPF2_MSK (3<<(2*2))
-
#define GPG3_MSK (3<<(2*3))
-
-
int main()
-
{
-
unsigned long DAT;
-
/*set LED1 LED2 LED4 for output*/
-
GPFCON&=~(GPF4_MSK | GPF5_MSK | GPF6_MSK);
-
GPFCON|=(GPF4_OUT | GPF5_OUT | GPF6_OUT);
-
-
/*set KEY2 KEY3 for input*/
-
GPFCON&=~(GPF0_MSK | GPF2_MSK);
-
GPFCON|=(GPF0_IN | GPF2_IN);
-
-
/*set KEY4 for input*/
-
GPGCON&=~GPG3_MSK;
-
GPGCON|=GPG3_IN;
-
-
while(1)
-
{
-
DAT=GPFDAT;
-
if(DAT & (1<<0))/*no press KEY2*/
-
GPFDAT|=(1<<4);/*light down*/
-
else
-
GPFDAT&=~(1<<4);/*light on*/
-
-
if(DAT & (1<<2))/*no press KEY3*/
-
GPFDAT|=(1<<5);
-
else
-
GPFDAT&=~(1<<5);
-
-
DAT=GPGDAT;
-
if(DAT & (1<<3))/*no press KEY4*/
-
GPFDAT|=(1<<6);
-
else
-
GPFDAT&=~(1<<6);
-
}
-
-
-
return 0;
-
}
-
leds_key.bin:crt0.S leds_key.c
-
arm-linux-gcc -g -c -o crt0.o crt0.S
-
arm-linux-gcc -g -c -o leds_key.o leds_key.c
-
arm-linux-ld -Ttext 0x00000000 -g crt0.o leds_key.o -o leds_key_elf
-
arm-linux-objcopy -O binary -S leds_key_elf leds_key.bin
-
clean:
-
rm -f *.o leds_key_elf leds_key.bin
阅读(2585) | 评论(0) | 转发(0) |