ARM按键控制LED

#define     GPACON     (*(volatile unsigned long*)0x56000000)
#define     GPADAT      (*(volatile unsigned long *)0x56000004)
#define     GPBCON      (*(volatile unsigned long *)0x56000010)
#define     GPBDAT      (*(volatile unsigned long *)0x56000014)
#define     GPFCON      (*(volatile unsigned long *)0x56000050)
#define     GPFDAT      (*(volatile unsigned long *)0x56000054)
#define     GPBSEL      (*(volatile unsigned long *)0x5600001c)

void main(void)
{
    int dat = 0;

    //
所有LED熄灭
    GPACON = 0x0;  
    GPBCON = ( 0x5<<(2*5) );   
    GPADAT = (0x3<<25);
    GPBDAT = (0x3<<5);
    GPBSEL = 0x0;
   
    //
配置GPF引脚为输入功能
    GPFCON = 0;
   
    //
轮询的方式查询按键事件
    while(1)
    {
        dat = GPFDAT;

        if(dat & (1<<0))                // KEY1
被按下,则LED1亮,否则LED1
            GPBDAT |= 1<<5;
        else
            GPBDAT &=~(1<<5);

        if(dat & (1<<1))                // KEY2
被按下,则LED2亮,否则LED2
            GPBDAT |= 1<<6;
        else
            GPBDAT &=~(1<<6);

        if(dat & (1<<2))                // KEY3
被按下,则LED3亮,否则LED3
            GPADAT |= (1<<25);
        else
            GPADAT &=~(1<<25);

        if(dat & (1<<3))                // KEY4
被按下,则LED4亮,否则LED4
            GPADAT |= 1<<26;
        else
            GPADAT &=~(1<<26);

    }
}

你可能感兴趣的:(ARM)