MINI2440 先从最简单的 LED 及 按键 开始!

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--);

    }      

}

       

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值