在线时间116 小时
UID3123257
注册时间2016-10-11
NXP金币0
TA的每日心情 | 奋斗 2017-1-18 20:00 |
---|
签到天数: 45 天 连续签到: 1 天 [LV.5]常住居民I
高级会员

- 积分
- 533
- 最后登录
- 2024-11-23
|
LPC54114板子上共有8个可控的LED,查看原理图发现LED11~LED4对应的是LED0~LED7
给的例程里面也是按照对应的编号进行初始化的。
- #include "board.h"
- #include "pin_mux.h"
- #include "fsl_common.h"
- #include "fsl_iocon.h"
- #include <stdbool.h>
- #include "app_led.h"
- /*******************************************************************************
- * Definitions
- ******************************************************************************/
- #define LED_GPIO_CFG IOCON_MODE_PULLUP | IOCON_FUNC0 | IOCON_GPIO_MODE | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF
- /*******************************************************************************
- * Prototypes
- ******************************************************************************/
- const uint8_t LED_GPIO_PORT[LED_NUM] = { 0, 0, 0, 0, 0, 0, 0, 0};
- const uint8_t LED_GPIO_PIN [LED_NUM] = {15, 19, 21, 22, 25, 26, 29, 30};
- const uint8_t LED_GPIO_ON [LED_NUM] = { 1, 1, 1, 1, 0, 0, 0, 0};
- const uint8_t LED_GPIO_OFF [LED_NUM] = { 0, 0, 0, 0, 1, 1, 1, 1};
- /*******************************************************************************
- * Code
- ******************************************************************************/
- /*!
- * @brief Main function
- */
- uint8_t led_init(void)
- {
- uint8_t ret = 0;
- uint8_t i = 0;
-
- // Init output LED GPIO
- for(i=0; i<LED_NUM; i++)
- {
- GPIO->DIR[LED_GPIO_PORT[i]] |= 1U << LED_GPIO_PIN[i];
- GPIO->B[LED_GPIO_PORT[i]][LED_GPIO_PIN[i]] = LED_GPIO_OFF[i];
- IOCON_PinMuxSet(IOCON, LED_GPIO_PORT[i], LED_GPIO_PIN[i], LED_GPIO_CFG);
- }
-
- ret = 1;
-
- return ret;
- }
- void led_on(uint8_t num)
- {
- GPIO->B[LED_GPIO_PORT[num]][LED_GPIO_PIN[num]] = LED_GPIO_ON[num];
- }
- void led_off(uint8_t num)
- {
- GPIO->B[LED_GPIO_PORT[num]][LED_GPIO_PIN[num]] = LED_GPIO_OFF[num];
- }
- void led_toggle(uint8_t num)
- {
- GPIO->NOT[LED_GPIO_PORT[num]] |= (1 << LED_GPIO_PIN[num]);
- }
- // end file
复制代码 例程已经为LED进行了初始化,在例程的基础上修改就可以实现GPIO控制LED实现流水灯。
在例程的application.c文件中把暂时不需要的屏蔽
- #include "fsl_device_registers.h"
- #include "fsl_debug_console.h"
- #include "board.h"
- #include "pin_mux.h"
- #include "fsl_common.h"
- #include "fsl_iocon.h"
- #include <stdbool.h>
- //#include "app_interrupt.h"
- #include "app_led.h"
- //#include "app_adc.h"
- //#include "app_key.h"
- //#include "app_dmic.h"
- //#include "app_spiflash.h"
- //#include "app_pct2075.h"
- //#include "app_wm8904.h"
- //#include "app_usbdmsc.h"
- //#include "ff.h"
- //#include "diskio.h"
- //#include "app_spisd.h"
- /*******************************************************************************
- * Definitions
- ******************************************************************************/
- /*******************************************************************************
- * Prototypes
- ******************************************************************************/
- //volatile float fPCTValue;
- //static FATFS g_fileSystem; /* File system object */
- //const TCHAR driverNumberBuffer[3U] = {SDSPIDISK + '0', ':', '/'};
- uint8_t LEDNUM[8]={0,1,2,3,4,5,6,7};
- /*********************************************************************************************************
- ** Function name: myDelay
- ** Descriptions: Èí¼þÑÓʱ
- ** input parameters: ÎÞ
- ** output parameters: ÎÞ
- ** Returned value: ÎÞ
- *********************************************************************************************************/
- void myDelay(uint32_t ulTime)
- {
- uint32_t i;
- i = 0;
- while (ulTime--) {
- for (i = 0; i < 5000; i++);
- }
- }
- /*******************************************************************************
- * Code
- ******************************************************************************/
- /*!
- * @brief Main function
- */
- int main(void)
- {
- // char ch;
- // uint16_t wADCValue = 0;
- // uint8_t ret;
-
- /* Init board hardware. */
- /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
- CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
- BOARD_InitPins();
- BOARD_BootClockRUN();
- BOARD_InitDebugConsole();
-
- SystemCoreClockUpdate();
-
- // SysTick_Config(SystemCoreClock/1000);
- //
- // PRINTF("\r\n-------------------------------\r\n\r\n");
- // PRINTF("hello world.\r\n");
- // PRINTF("LPC54110 Sys Clock is %dMhz.\r\n", SystemCoreClock/1000000);
- // PRINTF("\r\n-------------------------------\r\n");
-
- CLOCK_EnableClock(kCLOCK_InputMux);
- CLOCK_EnableClock(kCLOCK_Iocon);
- CLOCK_EnableClock(kCLOCK_Gpio0);
- CLOCK_EnableClock(kCLOCK_Gpio1);
-
- led_init();
- // key_init();
- // adc_init();
- // dmic_init();
- // ret = spiflash_init();
- // if(ret == 1)
- // {
- // led_on(5);
- // }
- // else
- // {
- // led_off(5);
- // }
- //
- // pct2075_i2c_init();
- // wm8904_i2s_init();
- // usbdmsc_init();
- //
- // if (f_mount(&g_fileSystem, driverNumberBuffer, 1))
- // {
- // PRINTF("Mount volume failed.\r\n");
- // }
- //
- //#if (_FS_RPATH >= 2)
- // if (f_chdrive((char const *)&driverNumberBuffer[0]))
- // {
- // PRINTF("Change drive failed.\r\n");
- // return;
- // }
- //#endif
- // FIL fd;
- // if(f_open(&fd, "4:/readme.txt", FA_READ) )
- // {
- // PRINTF("f_open failed.\r\n");
- // led_off(6);
- // }
- // else
- // {
- // led_on(6);
- // }
-
- while (1)
- {
- for(int i=0;i<8;i++){
- led_on(LEDNUM[i]);
- myDelay(500);
- }
- for(int i=7;i>=0;i--){
- led_off(LEDNUM[i]);
- myDelay(500);
- }
-
-
- //// ADC test schedule
- // wADCValue = adc_read(ADC_CHANNEL_NUM);
- // if(wADCValue != 0xFFFF)
- // {
- // dwLedTime = (wADCValue*2000)/0xFFFF; // ajust the led blinky freqency
- // }
- //// Button test schedule
- // if( (key_value(0) == 0) || (key_value(1) == 0) || (key_value(2) == 0) || (key_value(3) == 0) )
- // {
- // led_on(2);
- // }
- // else
- // {
- // led_off(2);
- // }
- // ret = pct2075_i2c_read(&fPCTValue);
- // if(ret == 1)
- // {
- // led_on(4);
- // }
- // else
- // {
- // led_off(4);
- // }
- // if(fPCTValue>=0)
- // {
- // PRINTF("Temperature Value is +%d.%d oC.\r", (int)(fPCTValue*100)/100, (int)(fPCTValue*100)%100);
- // }
- // else
- // {
- // PRINTF("Temperature Value is -%d.%d oC.\r", (int)((0-fPCTValue)*100)/100, (int)((0-fPCTValue)*100)%100);
- // }
- //
- // usbdmsc_proc();
- // __WFI();
- }
- }
复制代码 程序中主要是写了一个延时函数,一个数组,然后两个for循环,实现LED流水灯。现象是板子上的LED11到LED4依次点亮,然后LED4到LED11依次熄灭,此后一直这样循环。
|
|