[其他] 基于官方库函数的点灯操作

[复制链接]
 楼主| zhuotuzi 发表于 2023-1-30 20:23 | 显示全部楼层 |阅读模式
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. *                    opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file main.c
  11. **
  12. ** \brief This sample demonstrates how to set GPIO as output function.
  13. **
  14. **   - 2021-04-16 CDT first version for Device Driver Library of GPIO.
  15. **
  16. ******************************************************************************/

  17. /*******************************************************************************
  18. * Include files
  19. ******************************************************************************/
  20. #include "hc32_ddl.h"

  21. /*******************************************************************************
  22. * Local type definitions ('typedef')
  23. ******************************************************************************/

  24. /*******************************************************************************
  25. * Local pre-processor symbols/macros ('#define')
  26. ******************************************************************************/
  27. /* LED0 Port/Pin definition */
  28. #define  LED0_PORT        (PortD)
  29. #define  LED0_PIN         (Pin03)

  30. /* LED1 Port/Pin definition */
  31. #define  LED1_PORT        (PortD)
  32. #define  LED1_PIN         (Pin04)

  33. /* LED2 Port/Pin definition */
  34. #define  LED2_PORT        (PortD)
  35. #define  LED2_PIN         (Pin05)

  36. /* LED3 Port/Pin definition */
  37. #define  LED3_PORT        (PortD)
  38. #define  LED3_PIN         (Pin06)

  39. /* LED0~3 toggle definition */
  40. #define  LED0_TOGGLE()    (PORT_Toggle(LED0_PORT, LED0_PIN))
  41. #define  LED1_TOGGLE()    (PORT_Toggle(LED1_PORT, LED1_PIN))
  42. #define  LED2_TOGGLE()    (PORT_Toggle(LED2_PORT, LED2_PIN))
  43. #define  LED3_TOGGLE()    (PORT_Toggle(LED3_PORT, LED3_PIN))

  44. #define  DLY_MS           (100ul)

  45. /*******************************************************************************
  46. * Global variable definitions (declared in header file with 'extern')
  47. ******************************************************************************/

  48. /*******************************************************************************
  49. * Local function prototypes ('static')
  50. ******************************************************************************/

  51. /*******************************************************************************
  52. * Local variable definitions ('static')
  53. ******************************************************************************/

  54. /*******************************************************************************
  55. * Function implementation - global ('extern') and local ('static')
  56. ******************************************************************************/
  57. /**
  58. *******************************************************************************
  59. ** \brief  Main function of GPIO output
  60. **
  61. ** \param  None
  62. **
  63. ** \retval int32_t Return value, if needed
  64. **
  65. ******************************************************************************/
  66. int32_t main(void)
  67. {
  68.     stc_port_init_t stcPortInit;

  69.     /* configuration structure initialization */
  70.     MEM_ZERO_STRUCT(stcPortInit);

  71.     stcPortInit.enPinMode = Pin_Mode_Out;
  72.     stcPortInit.enExInt = Enable;
  73.     stcPortInit.enPullUp = Enable;

  74.     /* LED0 Port/Pin initialization */
  75.     PORT_Init(LED0_PORT, LED0_PIN, &stcPortInit);

  76.     /* LED1 Port/Pin initialization */
  77.     PORT_Init(LED1_PORT, LED1_PIN, &stcPortInit);

  78.     /* LED2 Port/Pin initialization */
  79.     PORT_Init(LED2_PORT, LED2_PIN, &stcPortInit);

  80.     /* LED3 Port/Pin initialization */
  81.     PORT_Init(LED3_PORT, LED3_PIN, &stcPortInit);

  82.     while(1)
  83.     {
  84.         LED0_TOGGLE();
  85.         Ddl_Delay1ms(DLY_MS);
  86.         LED1_TOGGLE();
  87.         Ddl_Delay1ms(DLY_MS);
  88.         LED2_TOGGLE();
  89.         Ddl_Delay1ms(DLY_MS);
  90.         LED3_TOGGLE();
  91.         Ddl_Delay1ms(DLY_MS);
  92.         /* de-init if necessary */
  93.         //PORT_DeInit();
  94.     };
  95. }

  96. /*******************************************************************************
  97. * EOF (not truncated)
  98. ******************************************************************************/


 楼主| zhuotuzi 发表于 2023-1-30 20:23 | 显示全部楼层
PORT_Toggle(LED0_PORT, LED0_PIN)
官方代码命名的风格挺好的,符合我的习惯。
xinpian101 发表于 2023-1-30 21:01 | 显示全部楼层
参数传递方法是跟ST很像,应该就是仿照ST的做的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

214

主题

3375

帖子

7

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