MICRO2440裸跑之按键点亮LED

/****************************************************** * MICRO 2440 按键LED程序 * *******************************************************/ #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 LED2 LED3 LED4 对应关系 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 K2 k3 k4 K5 K6 GPG0 GPG3 GPG5 GPG6 GPG7 GPG11 */ #define GPG0_in ~(3<<(0*2)) #define GPG3_in ~(3<<(3*2)) #define GPG5_in ~(3<<(5*2)) #define GPG6_in ~(3<<(6*2)) #define GPG7_in ~(3<<(7*2)) #define GPG11_in ~(3<<(11*2)) int main() { unsigned long dwDat; //LED1 LED2 LED3 LED4设置对应的4根引脚为输出 GPBCON = GPB5_out | GPB6_out | GPB7_out | GPB8_out;//2个bit为01设置对应的引脚为输出 //K1 K2 K3 K4 K5 K6对应的引脚设置为输入 GPGCON = GPG11_in & GPG7_in & GPG6_in & GPG5_in & GPG3_in & GPG0_in; while(1) { //若Kn 按下则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 点亮 //按下K5时候点亮LED1 LED4 if(dwDat & (1 << 7)) //K5没有按下 GPBDAT |= (1 << 8); // LED 4熄灭 else GPBDAT &= (~(1 << 5) & ~(1 << 8));//LED1 LED4 点亮 //按下K6时候点亮所有的LED if(dwDat & (1 << 11)) //K6没有按下 GPBDAT |= (1 << 8) ; //LED4 熄灭 else GPBDAT &= (~(1 << 5) &~(1 << 6) & ~(1 << 8) & ~(1 << 7));//LED 点亮 } }

 

电路说明:

 

MICRO2440裸跑之按键点亮LED_第1张图片

 

 MICRO2440裸跑之按键点亮LED_第2张图片

你可能感兴趣的:(MICRO2440裸跑之按键点亮LED)