打印
[其他]

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

[复制链接]
609|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
gejigeji521|  楼主 | 2023-3-19 18:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/**
  ******************************************************************************
  * [url=home.php?mod=space&uid=288409]@file[/url]    main.c
  * [url=home.php?mod=space&uid=187600]@author[/url]  Alexander
  * [url=home.php?mod=space&uid=895143]@version[/url] V1.0.0
  * [url=home.php?mod=space&uid=212281]@date[/url]    04-January-2023
  * [url=home.php?mod=space&uid=247401]@brief[/url]   Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 HKMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */

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

/** @addtogroup HK32F030Mxx_StdPeriph_Examples
  * @{
  */
       
/** @addtogroup GPIO_IOToggle
  * @{
  */       

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define BSRR_VAL 0x0006

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef        GPIO_InitStructure;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (KEIL_startup_hk32f030m.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_hk32f030m.c file
     */
  /* GPIOD Periph clock enable */
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);
       
        /* Configure PD01 and PD02 in output pushpull mode */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOD, &GPIO_InitStructure);
       
        while(1)
        {
                /* Set PD01 and PD02 */
                GPIOD->BSRR = BSRR_VAL;
                /* Reset PD01 and PD02 */
                GPIOD->BRR = BSRR_VAL;
               
                /* Set PD01 and PD02 */
                GPIOD->BSRR = BSRR_VAL;
                /* Reset PD01 and PD02 */
                GPIOD->BRR = BSRR_VAL;
               
                /* Set PD01 and PD02 */
                GPIOD->BSRR = BSRR_VAL;
                /* Reset PD01 and PD02 */
                GPIOD->BRR = BSRR_VAL;
               
                /* Set PD01 and PD02 */
                GPIOD->BSRR = BSRR_VAL;
                /* Reset PD01 and PD02 */
                GPIOD->BRR = BSRR_VAL;
               
                /* Set PD01 and PD02 */
                GPIOD->BSRR = BSRR_VAL;
                /* Reset PD01 and PD02 */
                GPIOD->BRR = BSRR_VAL;
        }
}

#ifdef  USE_FULL_ASSERT

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

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/**
  * @}
  */

/**
  * @}
  */


使用特权

评论回复
沙发
gejigeji521|  楼主 | 2023-3-19 18:08 | 只看该作者
都是通过一个数据结构体传送参数初始化,很棒,很习惯。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

177

主题

2229

帖子

8

粉丝