查看: 3568|回复: 0

[原创] LPC54114学习+GPIO流水灯

[复制链接]
  • TA的每日心情
    奋斗
    2017-1-18 20:00
  • 签到天数: 45 天

    连续签到: 1 天

    [LV.5]常住居民I

    17

    主题

    262

    帖子

    0

    高级会员

    Rank: 4

    积分
    533
    最后登录
    2024-11-23
    发表于 2017-4-7 10:19:46 | 显示全部楼层 |阅读模式
        LPC54114板子上共有8个可控的LED,查看原理图发现LED11~LED4对应的是LED0~LED7
    截图20170407100832.png
        给的例程里面也是按照对应的编号进行初始化的。
    1. #include "board.h"

    2. #include "pin_mux.h"

    3. #include "fsl_common.h"
    4. #include "fsl_iocon.h"

    5. #include <stdbool.h>

    6. #include "app_led.h"

    7. /*******************************************************************************
    8. * Definitions
    9. ******************************************************************************/
    10. #define LED_GPIO_CFG IOCON_MODE_PULLUP | IOCON_FUNC0 | IOCON_GPIO_MODE | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF

    11. /*******************************************************************************
    12. * Prototypes
    13. ******************************************************************************/
    14. const uint8_t  LED_GPIO_PORT[LED_NUM] = { 0,  0,  0,  0,  0,  0,  0,  0};
    15. const uint8_t  LED_GPIO_PIN [LED_NUM] = {15, 19, 21, 22, 25, 26, 29, 30};
    16. const uint8_t  LED_GPIO_ON  [LED_NUM] = { 1,  1,  1,  1,  0,  0,  0,  0};
    17. const uint8_t  LED_GPIO_OFF [LED_NUM] = { 0,  0,  0,  0,  1,  1,  1,  1};

    18. /*******************************************************************************
    19. * Code
    20. ******************************************************************************/
    21. /*!
    22. * @brief Main function
    23. */
    24. uint8_t led_init(void)
    25. {       
    26.         uint8_t ret = 0;
    27.         uint8_t i = 0;
    28.        
    29. // Init output LED GPIO
    30.         for(i=0; i<LED_NUM; i++)
    31.         {
    32.                 GPIO->DIR[LED_GPIO_PORT[i]] |= 1U << LED_GPIO_PIN[i];
    33.                 GPIO->B[LED_GPIO_PORT[i]][LED_GPIO_PIN[i]] = LED_GPIO_OFF[i];
    34.                 IOCON_PinMuxSet(IOCON, LED_GPIO_PORT[i], LED_GPIO_PIN[i], LED_GPIO_CFG);
    35.         }
    36.        
    37.         ret = 1;
    38.        
    39.         return ret;
    40. }

    41. void led_on(uint8_t num)
    42. {
    43.         GPIO->B[LED_GPIO_PORT[num]][LED_GPIO_PIN[num]] = LED_GPIO_ON[num];
    44. }

    45. void led_off(uint8_t num)
    46. {
    47.         GPIO->B[LED_GPIO_PORT[num]][LED_GPIO_PIN[num]] = LED_GPIO_OFF[num];
    48. }

    49. void led_toggle(uint8_t num)
    50. {
    51.         GPIO->NOT[LED_GPIO_PORT[num]] |= (1 << LED_GPIO_PIN[num]);
    52. }

    53. // end file
    复制代码
        例程已经为LED进行了初始化,在例程的基础上修改就可以实现GPIO控制LED实现流水灯。
        在例程的application.c文件中把暂时不需要的屏蔽
    1. #include "fsl_device_registers.h"
    2. #include "fsl_debug_console.h"
    3. #include "board.h"

    4. #include "pin_mux.h"

    5. #include "fsl_common.h"
    6. #include "fsl_iocon.h"

    7. #include <stdbool.h>


    8. //#include "app_interrupt.h"
    9. #include "app_led.h"
    10. //#include "app_adc.h"
    11. //#include "app_key.h"
    12. //#include "app_dmic.h"
    13. //#include "app_spiflash.h"
    14. //#include "app_pct2075.h"
    15. //#include "app_wm8904.h"
    16. //#include "app_usbdmsc.h"
    17. //#include "ff.h"
    18. //#include "diskio.h"
    19. //#include "app_spisd.h"

    20. /*******************************************************************************
    21. * Definitions
    22. ******************************************************************************/


    23. /*******************************************************************************
    24. * Prototypes
    25. ******************************************************************************/
    26. //volatile float fPCTValue;
    27. //static FATFS g_fileSystem; /* File system object */
    28. //const TCHAR driverNumberBuffer[3U] = {SDSPIDISK + '0', ':', '/'};

    29. uint8_t  LEDNUM[8]={0,1,2,3,4,5,6,7};
    30. /*********************************************************************************************************
    31. ** Function name:       myDelay
    32. ** Descriptions:        Èí¼þÑÓʱ
    33. ** input parameters:    ÎÞ
    34. ** output parameters:   ÎÞ
    35. ** Returned value:      ÎÞ
    36. *********************************************************************************************************/
    37. void myDelay(uint32_t ulTime)
    38. {
    39.     uint32_t i;

    40.     i = 0;
    41.     while (ulTime--) {
    42.         for (i = 0; i < 5000; i++);
    43.     }
    44. }

    45. /*******************************************************************************
    46. * Code
    47. ******************************************************************************/
    48. /*!
    49. * @brief Main function
    50. */
    51. int main(void)
    52. {
    53. //        char ch;
    54. //        uint16_t wADCValue = 0;

    55. //        uint8_t ret;
    56.        
    57.         /* Init board hardware. */
    58.         /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
    59.         CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

    60.         BOARD_InitPins();
    61.         BOARD_BootClockRUN();
    62.         BOARD_InitDebugConsole();
    63.        
    64.         SystemCoreClockUpdate();
    65.        
    66. //        SysTick_Config(SystemCoreClock/1000);
    67. //       
    68. //        PRINTF("\r\n-------------------------------\r\n\r\n");
    69. //        PRINTF("hello world.\r\n");
    70. //        PRINTF("LPC54110 Sys Clock is %dMhz.\r\n", SystemCoreClock/1000000);
    71. //        PRINTF("\r\n-------------------------------\r\n");
    72.        
    73.   CLOCK_EnableClock(kCLOCK_InputMux);
    74.   CLOCK_EnableClock(kCLOCK_Iocon);
    75.   CLOCK_EnableClock(kCLOCK_Gpio0);
    76.   CLOCK_EnableClock(kCLOCK_Gpio1);
    77.        
    78.         led_init();
    79. //        key_init();
    80. //        adc_init();
    81. //        dmic_init();
    82. //        ret = spiflash_init();
    83. //        if(ret == 1)
    84. //        {
    85. //                led_on(5);
    86. //        }
    87. //        else
    88. //        {
    89. //                led_off(5);
    90. //        }
    91. //       
    92. //        pct2075_i2c_init();
    93. //        wm8904_i2s_init();
    94. //        usbdmsc_init();
    95. //       
    96. //        if (f_mount(&g_fileSystem, driverNumberBuffer, 1))
    97. //        {
    98. //                        PRINTF("Mount volume failed.\r\n");
    99. //        }
    100. //               
    101. //#if (_FS_RPATH >= 2)
    102. //        if (f_chdrive((char const *)&driverNumberBuffer[0]))
    103. //        {
    104. //                PRINTF("Change drive failed.\r\n");
    105. //                return;
    106. //        }
    107. //#endif       
    108. //        FIL fd;
    109. //        if(f_open(&fd, "4:/readme.txt", FA_READ) )
    110. //        {
    111. //                PRINTF("f_open failed.\r\n");
    112. //                led_off(6);
    113. //        }
    114. //        else
    115. //        {
    116. //                led_on(6);
    117. //        }

    118.        
    119.         while (1)
    120.         {
    121.                 for(int i=0;i<8;i++){
    122.                         led_on(LEDNUM[i]);
    123.                           myDelay(500);
    124.                 }
    125.                 for(int i=7;i>=0;i--){
    126.                         led_off(LEDNUM[i]);
    127.                           myDelay(500);
    128.                 }
    129.                
    130.                
    131. //// ADC test schedule
    132. //                wADCValue = adc_read(ADC_CHANNEL_NUM);
    133. //                if(wADCValue != 0xFFFF)
    134. //                {
    135. //                        dwLedTime = (wADCValue*2000)/0xFFFF; // ajust the led blinky freqency
    136. //                }
    137. //// Button test schedule               
    138. //                if( (key_value(0) == 0) || (key_value(1) == 0) || (key_value(2) == 0) || (key_value(3) == 0) )
    139. //                {
    140. //                        led_on(2);
    141. //                }
    142. //                else
    143. //                {
    144. //                        led_off(2);
    145. //                }
    146. //                ret = pct2075_i2c_read(&fPCTValue);
    147. //                if(ret == 1)
    148. //                {
    149. //                        led_on(4);
    150. //                }
    151. //                else
    152. //                {
    153. //                        led_off(4);
    154. //                }
    155. //                if(fPCTValue>=0)
    156. //                {
    157. //                        PRINTF("Temperature Value is +%d.%d oC.\r", (int)(fPCTValue*100)/100, (int)(fPCTValue*100)%100);
    158. //                }
    159. //                else
    160. //                {
    161. //                        PRINTF("Temperature Value is -%d.%d oC.\r", (int)((0-fPCTValue)*100)/100, (int)((0-fPCTValue)*100)%100);
    162. //                }
    163. //               
    164. //                usbdmsc_proc();
    165. //                __WFI();
    166.         }
    167. }
    复制代码
        程序中主要是写了一个延时函数,一个数组,然后两个for循环,实现LED流水灯。现象是板子上的LED11到LED4依次点亮,然后LED4到LED11依次熄灭,此后一直这样循环。
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-24 00:58 , Processed in 0.080701 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表