[开发工具] GPIO点灯操作

[复制链接]
 楼主| huahuagg 发表于 2022-12-22 21:41 | 显示全部楼层 |阅读模式
  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. **   - 2018-10-14 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        (PortE)
  29. #define  LED0_PIN         (Pin06)

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

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

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

  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. ******************************************************************************/


 楼主| huahuagg 发表于 2022-12-22 21:42 | 显示全部楼层
http://xhsc.com.cn/Productlist/info.aspx?itemid=1850
资料下载地址
aoyi 发表于 2023-1-3 14:32 | 显示全部楼层
能介绍一下硬件是如何连接的吗 使用的是什么引脚
tpgf 发表于 2023-1-3 14:53 | 显示全部楼层
看了一下软件中对寄存器的配置非常简单了 就是实现小灯的亮灭
nawu 发表于 2023-1-3 15:14 | 显示全部楼层
功能非常简单 关键还得看时钟配置以及io配置
zljiu 发表于 2023-1-3 15:26 | 显示全部楼层
可以看一下楼主的io口初始化的那部分的代码吗
gwsan 发表于 2023-1-3 15:48 | 显示全部楼层
楼主的这种匀速点灯完全可以通过pwm来实现吧
tfqi 发表于 2023-1-3 15:56 | 显示全部楼层
每个新手入门的操作就是点灯 不过点灯也是有一定技巧的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

159

主题

1408

帖子

2

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