MINI2440 先从最简单的 LED 及 按键 开始罢!
1. 查看在原理图中的网络名nLED_1 nLED_2 nLED_3 nLED_4
2. 本开发板具有4 个用户可编程LED,它们直接与CPU 的GPIO 相连接,低电平有效(点亮),详细的资源占用如下:
3. LED1 LED2 LED3 LED4
GPB5 GPB6 GPB7 GPB8
4.本开发板总共有6 个用户测试用按键,它们均从CPU 中断引脚直接引出,属于低电平触发,这些引脚也可以复用为GPIO 和特殊功能口,这6个按键定义如下:
K1 K2 K3 K4 K5 K6
GPG0 GPG3 GPG5 GPG6 GPG7 GPG11
下列程序可以按键分别点亮LED:
//GPB 5,6,7,8 for LED
#define rGPBCON (*(volatile unsigned *)0x56000010) //Port B control
#define rGPBDAT (*(volatile unsigned *)0x56000014) //Port B data
//GPG 0,3,5,6,7,11 for keyset
#define rGPGCON (*(volatile unsigned *)0x56000060) //Port G control
#define rGPGDAT (*(volatile unsigned *)0x56000064) //Port G data
//LED1-4
#define GPB5o (1<<(5*2))
#define GPB6o (1<<(6*2))
#define GPB7o (1<<(7*2))
#define GPB8o (1<<(8*2))
//K1-K6
#define GPG11i ~(3<<(11*2))
#define GPG7i ~(3<<(7*2))
#define GPG6i ~(3<<(6*2))
#define GPG5i ~(3<<(5*2))
#define GPG3i ~(3<<(3*2))
#define GPG0i ~(3<<(0*2))
void delay(unsigned counter);
int main(void)
{
unsigned long dwDat;
// LED1-LED4
rGPBCON = GPB5o | GPB6o | GPB7o | GPB8o ;
// light up all leds
rGPBDAT &= ~((1<<5)|(1<<6)|(1<<7)|(1<<8));
delay(3000); //light up for a moment
rGPBDAT &= ((1<<5)|(1<<6)|(1<<7)|(1<<8)); //turn off all leds
// K1-K6
rGPGCON = GPG11i & GPG7i & GPG6i & GPG5i & GPG3i & GPG0i ;
while(1){
//
dwDat = rGPGDAT; // read keyset status?
if (dwDat & (1<<11)) // K6 was not pressed?
rGPBDAT |= (1<<5); // LED1 was off
else
rGPBDAT &= ~(1<<5); // LED1 was on
if (dwDat & (1<<7)) // K5 was not pressed?
rGPBDAT |= (1<<6); // LED2 was off
else
rGPBDAT &= ~(1<<6); // LED2 was on
if (dwDat & (1<<6)) // K4 was not pressed?
rGPBDAT |= (1<<7); // LED3 was off
else
rGPBDAT &= ~(1<<7); // LED3 was on
if (dwDat & (1<<5)) // K3 was not pressed?
rGPBDAT |= (1<<8); // LED4 was off
else
rGPBDAT &= ~(1<<8); // LED4 was on
if (dwDat & (1<<3)) // K2 was not pressed
rGPBDAT |= ((1<<5)|(1<<7)); // LED1 and LED3 were off
else
rGPBDAT &= ~((1<<5)|(1<<7)); // LED1 and LED3 were on
if (dwDat & (1<<0)) // K1 was not pressed
rGPBDAT |= ((1<<6)|(1<<8)); // LED2 and LED4 were off
else
rGPBDAT &= ~((1<<6)|(1<<8)); // LED2 and LED4 were on
}
return 0;
}
void delay(unsigned counter)
{
unsigned i;
while(counter--)
{
i = 100000;
while(i--);
}
}