[其他] IO点灯程序,看了一下,跟ST那边的风格很像,很上手

[复制链接]
 楼主| gejigeji521 发表于 2023-3-19 18:08 | 显示全部楼层 |阅读模式
  1. /**
  2.   ******************************************************************************
  3.   * [url=home.php?mod=space&uid=288409]@file[/url]    main.c
  4.   * [url=home.php?mod=space&uid=187600]@author[/url]  Alexander
  5.   * [url=home.php?mod=space&uid=895143]@version[/url] V1.0.0
  6.   * [url=home.php?mod=space&uid=212281]@date[/url]    04-January-2023
  7.   * [url=home.php?mod=space&uid=247401]@brief[/url]   Main program body
  8.   ******************************************************************************
  9.   * @attention
  10.   *
  11.   * Copyright (c) 2023 HKMicroelectronics.
  12.   * All rights reserved.
  13.   *
  14.   * This software is licensed under terms that can be found in the LICENSE file
  15.   * in the root directory of this software component.
  16.   * If no LICENSE file comes with this software, it is provided AS-IS.
  17.   *
  18.   ******************************************************************************
  19.   */

  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"

  22. /** @addtogroup HK32F030Mxx_StdPeriph_Examples
  23.   * @{
  24.   */
  25.        
  26. /** @addtogroup GPIO_IOToggle
  27.   * @{
  28.   */       

  29. /* Private typedef -----------------------------------------------------------*/
  30. /* Private define ------------------------------------------------------------*/
  31. #define BSRR_VAL 0x0006

  32. /* Private macro -------------------------------------------------------------*/
  33. /* Private variables ---------------------------------------------------------*/
  34. GPIO_InitTypeDef        GPIO_InitStructure;

  35. /* Private function prototypes -----------------------------------------------*/
  36. /* Private functions ---------------------------------------------------------*/

  37. /**
  38.   * @brief  Main program.
  39.   * @param  None
  40.   * @retval None
  41.   */
  42. int main(void)
  43. {
  44.   /*!< At this stage the microcontroller clock setting is already configured,
  45.        this is done through SystemInit() function which is called from startup
  46.        file (KEIL_startup_hk32f030m.s) before to branch to application main.
  47.        To reconfigure the default setting of SystemInit() function, refer to
  48.        system_hk32f030m.c file
  49.      */
  50.   /* GPIOD Periph clock enable */
  51.         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);
  52.        
  53.         /* Configure PD01 and PD02 in output pushpull mode */
  54.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
  55.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  56.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  57.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  58.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  59.         GPIO_Init(GPIOD, &GPIO_InitStructure);
  60.        
  61.         while(1)
  62.         {
  63.                 /* Set PD01 and PD02 */
  64.                 GPIOD->BSRR = BSRR_VAL;
  65.                 /* Reset PD01 and PD02 */
  66.                 GPIOD->BRR = BSRR_VAL;
  67.                
  68.                 /* Set PD01 and PD02 */
  69.                 GPIOD->BSRR = BSRR_VAL;
  70.                 /* Reset PD01 and PD02 */
  71.                 GPIOD->BRR = BSRR_VAL;
  72.                
  73.                 /* Set PD01 and PD02 */
  74.                 GPIOD->BSRR = BSRR_VAL;
  75.                 /* Reset PD01 and PD02 */
  76.                 GPIOD->BRR = BSRR_VAL;
  77.                
  78.                 /* Set PD01 and PD02 */
  79.                 GPIOD->BSRR = BSRR_VAL;
  80.                 /* Reset PD01 and PD02 */
  81.                 GPIOD->BRR = BSRR_VAL;
  82.                
  83.                 /* Set PD01 and PD02 */
  84.                 GPIOD->BSRR = BSRR_VAL;
  85.                 /* Reset PD01 and PD02 */
  86.                 GPIOD->BRR = BSRR_VAL;
  87.         }
  88. }

  89. #ifdef  USE_FULL_ASSERT

  90. /**
  91.   * @brief  Reports the name of the source file and the source line number
  92.   *         where the assert_param error has occurred.
  93.   * @param  file: pointer to the source file name
  94.   * @param  line: assert_param error line source number
  95.   * @retval None
  96.   */
  97. void assert_failed(uint8_t* file, uint32_t line)
  98. {
  99.   /* User can add his own implementation to report the file name and line number,
  100.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  101.   /* Infinite loop */
  102.   while (1)
  103.   {
  104.   }
  105. }
  106. #endif

  107. /**
  108.   * @}
  109.   */

  110. /**
  111.   * @}
  112.   */


 楼主| gejigeji521 发表于 2023-3-19 18:08 | 显示全部楼层
都是通过一个数据结构体传送参数初始化,很棒,很习惯。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

196

主题

2465

帖子

8

粉丝
快速回复 在线客服 返回列表 返回顶部