关于ARM的FS-EMB4412A实验箱关于LED灯的问题

下面的是ARM FS-EMB4412A实验箱的第一个代码,后面是根据第一个改出来的,然后现在的要求是先亮第一段代码的LED灯,然后点击4412实验箱上的音量+和音量-可以中断切换到第二个代码的亮灯。或者可以给出一个延时函数,延时2秒左右的时间切换到第二段代码也可以。

/*
 *@brief This example describes how to use GPIO to drive LEDs
 *@date: 02. June. 2014
 *@author liujh@farsight.com.cn
 *@Contact  Us: http://dev.hqyj.com
 *Copyright(C) 2014, Farsight
*/

#include "exynos_4412.h"


/**********************************************************************
 * @brief  mydelay_ms program body
 * @param[in] int (ms)
 * @return   None
 **********************************************************************/
void mydelay_ms(int ms)
{
 int i, j;
 while(ms--)
 {
  for (i = 0; i < 5; i++)
   for (j = 0; j < 514; j++);
 }
}

/*-------------------------MAIN FUNCTION------------------------------*/
/**********************************************************************
 * @brief  Main program body
 * @param[in] None
 * @return   int
 **********************************************************************/
int main(void)
{
 /*
  *Config
  *D1 -> GPX2_4 D2 -> GPX3_0
  *D3 -> GPX2_7  D4 -> GPX1_0
  */

 GPX2.CON = (GPX2.CON & ~(0xf<<16 | 0xf<<28)) | (0x1<<16 | 0x1<<28) ;//GPX2_4:output, D1
                 //GPX2_7:output, D3
 GPX3.CON = (GPX3.CON & ~(0xf<<0)) | 0x1<<0; //GPX3_0:output, D2
 GPX1.CON = (GPX1.CON & ~(0xf<<0)) | 0x1<<0; //GPX1_0:output, D4


 /*
  * Turn off all LED
  * */
 GPX2.DAT &= ~(0x1 << 4);
 GPX2.DAT &= ~(0x1 << 7);
 GPX3.DAT &= ~(0x1 << 0);
 GPX1.DAT &= ~(0x1 << 0);
 while(1)
 {
  //Turn on D1
  GPX2.DAT |= 0x1 << 4;
  mydelay_ms(500);

  //Turn on D3
  GPX2.DAT |= 0x1 << 7;


  //Turn off D1
  GPX2.DAT &= ~(0x1 << 4);
  mydelay_ms(500);

  //Turn on D2
  GPX3.DAT |= 0x1 << 0;



  //Turn off D3
  GPX2.DAT &= ~(0x1 << 7);
  mydelay_ms(500);

  //Turn on D4
  GPX1.DAT |= 0x1 << 0;

  //Turn off D2
  GPX3.DAT &= ~(0x1 << 0);
  mydelay_ms(500);




  //Turn off D4
  GPX1.DAT &= ~(0x1 << 0);

 }
 return 0;
}
/*
 *@brief This example describes how to use GPIO to drive LEDs
 *@date: 02. June. 2014
 *@author liujh@farsight.com.cn
 *@Contact  Us: http://dev.hqyj.com
 *Copyright(C) 2014, Farsight
*/

#include "exynos_4412.h"


/********************************************
```c
/*
 *@brief This example describes how to use GPIO to drive LEDs
 *@date: 02. June. 2014
 *@author liujh@farsight.com.cn
 *@Contact  Us: http://dev.hqyj.com
 *Copyright(C) 2014, Farsight
*/

#include "exynos_4412.h"


/**********************************************************************
 * @brief  mydelay_ms program body
 * @param[in] int (ms)
 * @return   None
 **********************************************************************/
void mydelay_ms(int ms)
{
 int i, j;
 while(ms--)
 {
  for (i = 0; i < 5; i++)
   for (j = 0; j < 514; j++);
 }
}

/*-------------------------MAIN FUNCTION------------------------------*/
/**********************************************************************
 * @brief  Main program body
 * @param[in] None
 * @return   int
 **********************************************************************/
int main(void)
{
 /*
  *Config
  *D1 -> GPX2_4 D2 -> GPX3_0
  *D3 -> GPX2_7  D4 -> GPX1_0
  */

 GPX2.CON = (GPX2.CON & ~(0xf<<16 | 0xf<<28)) | (0x1<<16 | 0x1<<28) ;//GPX2_4:output, D1
                 //GPX2_7:output, D3
 GPX3.CON = (GPX3.CON & ~(0xf<<0)) | 0x1<<0; //GPX3_0:output, D2
 // GPX1.CON = (GPX1.CON & ~(0xf<<0)) | 0x1<<0; //GPX1_0:output, D4


 /*
  * Turn off all LED
  * */
 GPX2.DAT &= ~(0x1 << 4);
 GPX3.DAT &= ~(0x1 << 0);
 GPX2.DAT &= ~(0x1 << 7);
 GPX1.DAT &= ~(0x1 << 0);
 while(1)
 {
  //Turn on D1
  GPX2.DAT |= 0x1 << 4;
  mydelay_ms(500);

  //Turn on D2
  GPX3.DAT |= 0x1 << 0;
  //Turn off D1
  GPX2.DAT &= ~(0x1 << 4);
  mydelay_ms(500);

  //Turn on D3
  // GPX2.DAT |= 0x1 << 7;
  //Turn off D2
  GPX3.DAT &= ~(0x1 << 0);
  mydelay_ms(500);

  //Turn on D4
  // GPX1.DAT |= 0x1 << 0;
  //Turn off D3
  //GPX2.DAT &= ~(0x1 << 7);
  //mydelay_ms(500);

  //Turn off D4
  //GPX1.DAT &= ~(0x1 << 0);

 }
 return 0;
}


```

参考GPT和自己的思路:根据您的问题,您想要实现先亮第一段代码的LED灯,然后点击4412实验箱上的音量+和音量-可以中断切换到第二个代码的亮灯。为了实现这个功能,您可以在第一个代码中添加一个延时函数,让它延时2秒钟后切换到第二段代码的亮灯。另外,在第一个代码中,添加一个中断函数来响应音量控制键的操作。具体步骤如下:

  1. 在第一个代码的while(1)循环中,添加一个延时函数,延时2秒钟:
mydelay_ms(2000);
  1. 在第一个代码中添加一个中断函数,响应音量控制键的操作。您可以使用GPIO Interrupt来实现这个功能。首先,您需要配置GPIO为输入模式,然后使用IRQ接口来实现中断处理器。具体步骤如下:

(1)在主函数中添加以下代码,将GPIO配置为输入模式:

GPX0.CON = (GPX0.CON & ~(0xf << 12)) | 0x0 << 12; // GPX0_3: input

(2)声明中断处理函数,示例代码如下:

void isr_GPIO(void)
{
    // Toggle the LED
    GPX2.DAT ^= (0x1 << 4);
    GPX3.DAT ^= (0x1 << 0);

    // Wait for a while to debounce
    mydelay_ms(100);

    // Clear interrupt pending flag
    GPX0.ICR |= (0x1 << 3);
}

(3)在主函数中启用中断并注册中断处理函数,示例代码如下:

// Enable interrupt for GPX0_3
GPX0.INTCON = (GPX0.INTCON & ~(0x7 << 12)) | 0x2 << 12;

// Register interrupt service routine
register_irq(9, isr_GPIO);

// Enable interrupt
enable_irq(9);
  1. 在第二个代码中,您可以根据需要点亮不同的LED灯。示例代码如下:
// Turn on D2
GPX3.DAT |= 0x1 << 0;

// Turn off D1
GPX2.DAT &= ~(0x1 << 4);

请注意,在第二个代码中,您需要在while(1)循环内循环不断地点亮和熄灭LED灯。