4412裸机程序按键控制led灯

4412裸机程序按键控制led灯

在ubuntu中写的

c语言代码:

#define GPX2CON (*(volatile unsigned long *) 0x11000c40)
#define GPX2DAT (*(volatile unsigned long *) 0x11000c44)


#define GPL2CON (*(volatile unsigned long *) 0x11000100)
#define GPL2DAT (*(volatile unsigned long *) 0x11000104)
#define GPK1CON (*(volatile unsigned long *) 0x11000060)
#define GPK1DAT(*(volatile unsigned long *) 0x11000064)


void delay(int r0)
{
volatile int count = r0;
while(count--)
;
}
void main()
{
GPX2CON = 0x00000003;
GPL2CON = 0x00000001;
GPK1CON = 0x00000010;


while(1)
{
if((GPX2DAT & 0x01) == 1)
{ 
GPL2DAT = 1;
GPK1DAT = 0x2;
}
if((GPX2DAT & 0x01) == 0)
{
GPL2DAT = 0;
GPK1DAT = 0;
}


}
}


汇编代码:

.global _start


_start:
        //disable watch dog
        ldr     r0, =0x10060000
        mov     r1, #0
        str     r1, [r0]


        //turn on icache
        mrc     p15, 0, r0, c1, c0, 0
        //bic   r0, r0, #0x00002300     /* clear bits 13, 9:8 (--V- --RS) */
        //bic   r0, r0, #0x00000087     /* clear bits 7, 2:0 (B--- -CAM) */
        //orr   r0, r0, #0x00000002     /* set bit 2 (A) Align */
        //orr   r0, r0, #0x00001000     /* set bit 12 (I) I-Cache */


#ifdef CONFIG_SYS_ICACHE_OFF
        // clear bit 12 (I) I-cache
        bic     r0, r0, #0x00001000
#else
        // set bit 12 (I) I-cache
        orr     r0, r0, #0x00001000
#endif
        mcr     p15, 0, r0, c1, c0, 0
        //mcr p15, 0, r0, c7, c5, 0     @ invalidate icache


        //set stack
        ldr     sp, =0x02050000


        bl      main


halt:
        b halt


makefile:

key.bin: start.o key.o
        arm-none-linux-gnueabi-ld -Ttext 0x0 -o key.elf $^
        arm-none-linux-gnueabi-objcopy -O binary key.elf key.bin
        arm-none-linux-gnueabi-objdump -D key.elf > key_elf.dis




%.o : %.S
        arm-none-linux-gnueabi-gcc -o $@ $< -c -nostdlib


%.o : %.c
        arm-none-linux-gnueabi-gcc -o $@ $< -c -nostdlib


clean:
        rm *.o *.elf *.bin *.dis  -f


你可能感兴趣的:(4412)