zhuotuzi 发表于 2023-1-30 20:23

基于官方库函数的点灯操作

/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*                  opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file main.c
**
** \brief This sample demonstrates how to set GPIO as output function.
**
**   - 2021-04-16 CDT first version for Device Driver Library of GPIO.
**
******************************************************************************/

/*******************************************************************************
* Include files
******************************************************************************/
#include "hc32_ddl.h"

/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/

/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/* LED0 Port/Pin definition */
#defineLED0_PORT      (PortD)
#defineLED0_PIN         (Pin03)

/* LED1 Port/Pin definition */
#defineLED1_PORT      (PortD)
#defineLED1_PIN         (Pin04)

/* LED2 Port/Pin definition */
#defineLED2_PORT      (PortD)
#defineLED2_PIN         (Pin05)

/* LED3 Port/Pin definition */
#defineLED3_PORT      (PortD)
#defineLED3_PIN         (Pin06)

/* LED0~3 toggle definition */
#defineLED0_TOGGLE()    (PORT_Toggle(LED0_PORT, LED0_PIN))
#defineLED1_TOGGLE()    (PORT_Toggle(LED1_PORT, LED1_PIN))
#defineLED2_TOGGLE()    (PORT_Toggle(LED2_PORT, LED2_PIN))
#defineLED3_TOGGLE()    (PORT_Toggle(LED3_PORT, LED3_PIN))

#defineDLY_MS         (100ul)

/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/

/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/

/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/

/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \briefMain function of GPIO output
**
** \paramNone
**
** \retval int32_t Return value, if needed
**
******************************************************************************/
int32_t main(void)
{
    stc_port_init_t stcPortInit;

    /* configuration structure initialization */
    MEM_ZERO_STRUCT(stcPortInit);

    stcPortInit.enPinMode = Pin_Mode_Out;
    stcPortInit.enExInt = Enable;
    stcPortInit.enPullUp = Enable;

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

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

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

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

    while(1)
    {
      LED0_TOGGLE();
      Ddl_Delay1ms(DLY_MS);
      LED1_TOGGLE();
      Ddl_Delay1ms(DLY_MS);
      LED2_TOGGLE();
      Ddl_Delay1ms(DLY_MS);
      LED3_TOGGLE();
      Ddl_Delay1ms(DLY_MS);
      /* de-init if necessary */
      //PORT_DeInit();
    };
}

/*******************************************************************************
* EOF (not truncated)
******************************************************************************/


zhuotuzi 发表于 2023-1-30 20:23

PORT_Toggle(LED0_PORT, LED0_PIN)
官方代码命名的风格挺好的,符合我的习惯。

xinpian101 发表于 2023-1-30 21:01

参数传递方法是跟ST很像,应该就是仿照ST的做的。
页: [1]
查看完整版本: 基于官方库函数的点灯操作