上面的是實驗箱的第一個代碼,后面是根據(jù)第一個改出來的,然后現(xiàn)在的要求是先亮第一段代碼的LED燈,然后點擊4412實驗箱上的音量+和音量-可以中斷切換到第二個代碼的亮燈。或者可以給出一個延時函數(shù),延時2秒左右的時間切換到第二段代碼也可以。
- #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;
- }
復(fù)制代碼
#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;
}
|