查看: 875|回复: 0

【NXP OKdo E1双核Cortex M33开发板】测评+ LED灯控制

[复制链接]
  • TA的每日心情
    奋斗
    2023-5-10 20:09
  • 签到天数: 1742 天

    连续签到: 1 天

    [LV.Master]伴坛终老

    发表于 2020-11-1 01:30:23 | 显示全部楼层 |阅读模式
    分享到:
    在OKdo E1开发板上,配置了3个LED灯,其原理图如图1所示。
    1.jpg
    图1   LED灯原理图

    由此可知LED灯与MCU的连接关系为:
    LEDR---PIO1_4
    LEDB---PIO1_6
    LEDG---PIO1_7

    为便于相关引脚的设置,故编写了一个LED灯的配置函数:
    1. void LEDS_InitPins(void)
    2. {
    3. /* Enables the clock for the I/O controller.: Enable Clock. */
    4. CLOCK_EnableClock(kCLOCK_Iocon);
    5. /* Enables the clock for the GPIO1 module */
    6. CLOCK_EnableClock(kCLOCK_Gpio1);
    7. gpio_pin_config_t LED_BULE_config = {
    8. .pinDirection = kGPIO_DigitalOutput,
    9. .outputLogic = 0U
    10. };
    11. /* Initialize GPIO functionality on pin PIO1_4 (pin 1)  */
    12. GPIO_PinInit(GPIO, 1U, 4U, 1u <<4U);
    13. GPIO_PinInit(GPIO, 1U, 6U, 1u <<6U);
    14. GPIO_PinInit(GPIO, 1U, 7U, 1u <<7U);
    15. const uint32_t port0_pin10_config = (/* Pin is configured as SWO */
    16. IOCON_PIO_FUNC6 |
    17. /* No addition pin function */
    18. IOCON_PIO_MODE_INACT |
    19. /* Standard mode, output slew rate control is enabled */
    20. IOCON_PIO_SLEW_STANDARD |
    21. /* Input function is not inverted */
    22. IOCON_PIO_INV_DI |
    23. /* Enables digital function */
    24. IOCON_PIO_DIGITAL_EN |
    25. /* Open drain is disabled */
    26. IOCON_PIO_OPENDRAIN_DI |
    27. /* Analog switch is disabled */
    28. IOCON_PIO_ASW_DIS_DI);
    29. /* PORT0 PIN10 (coords: 21) is configured as SWO */
    30. IOCON_PinMuxSet(IOCON, 0U, 10U, port0_pin10_config);
    31. const uint32_t LEDS = (/* Pin is configured as PIO1_4 */
    32. IOCON_PIO_FUNC0 |
    33. /* Selects pull-up function */
    34. IOCON_PIO_MODE_PULLUP |
    35. /* Standard mode, output slew rate control is enabled */
    36. IOCON_PIO_SLEW_STANDARD |
    37. /* Input function is not inverted */
    38. IOCON_PIO_INV_DI |
    39. /* Enables digital function */
    40. IOCON_PIO_DIGITAL_EN |
    41. /* Open drain is disabled */
    42. IOCON_PIO_OPENDRAIN_DI);
    43. /* PORT1 PIN4 (coords: 1) is configured as PIO1_4 */
    44. IOCON_PinMuxSet(IOCON, 1U, 4U, LEDS);
    45. IOCON_PinMuxSet(IOCON, 1U, 6U, LEDS);
    46. IOCON_PinMuxSet(IOCON, 1U, 7U, LEDS);
    47. }
    复制代码

    控制LED灯依次点亮的主程序如下:
    1. int main(void)
    2. {
    3. /* Init output LED GPIO. */
    4. GPIO_PortInit(GPIO, 1U);
    5. /* set BOD VBAT level to 1.65V */
    6. POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
    7. LEDS_InitPins();
    8. SystemCoreClockUpdate();
    9. /* Set systick reload value to generate 1ms interrupt */
    10. if (SysTick_Config(SystemCoreClock / 1000U))
    11. {
    12. while (1)
    13. {
    14. }
    15. }
    16. while (1)
    17. {
    18. GPIO_PortClear(GPIO, 1U, 1u <<4U);//RED
    19. SysTick_DelayTicks(1000U);
    20. GPIO_PortSet(GPIO, 1U, 1u <<4U);
    21. SysTick_DelayTicks(1000U);

    22.                               GPIO_PortClear(GPIO, 1U, 1u <<6U);//BLUE
    23. SysTick_DelayTicks(1000U);
    24. GPIO_PortSet(GPIO, 1U, 1u <<6U);
    25. SysTick_DelayTicks(1000U);

    26.                               GPIO_PortClear(GPIO, 1U, 1u <<7U);//GREEN
    27. SysTick_DelayTicks(1000U);
    28. GPIO_PortSet(GPIO, 1U, 1u <<7U);
    29. SysTick_DelayTicks(1000U);
    30. }
    31. }
    复制代码

    编译下载后,其运行效果如图2所示。
    2.jpg
    图2  LED灯控制效果

    目标代码:

    led_blinky.rar

    5.31 KB, 下载次数: 1

    回复

    使用道具 举报

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

    本版积分规则

    关闭

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

    手机版|小黑屋|与非网

    GMT+8, 2024-11-19 14:24 , Processed in 0.123700 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.