[单片机]头文件、源文件和函数注释模板

头文件(中文)

/**
 ******************************************************************************
 * @file    example.h
 * @author  [作者名]
 * @version [版本号]
 * @date    [日期]
 * @brief   [简要说明头文件功能,例如模块定义与函数声明]
 ******************************************************************************
 * @attention
 *
 * [附加注意事项,例如版权信息或使用限制]
 *
 ******************************************************************************
 */

#ifndef __EXAMPLE_H
#define __EXAMPLE_H

#ifdef __cplusplus
extern "C" {
#endif

/* 包含标准库头文件和相关依赖 */
#include "stm32f10x.h"

/* 宏定义 ------------------------------------------------------------------*/
/**
 * @brief 定义模块相关的宏
 */
#define EXAMPLE_MACRO  100    /*!< 示例宏的用途 */

/* 类型定义 ----------------------------------------------------------------*/
/**
 * @brief 定义模块使用的结构体
 */
typedef struct {
    uint16_t field1;  /*!< 字段1说明 */
    uint8_t  field2;  /*!< 字段2说明 */
} ExampleTypeDef;

/* 函数声明 ----------------------------------------------------------------*/
/**
 * @brief  初始化模块
 * @param  无
 * @retval 无
 */
void Example_Init(void);

/**
 * @brief  处理模块任务
 * @param  无
 * @retval 无
 */
void Example_Process(void);

#ifdef __cplusplus
}
#endif

#endif /* __EXAMPLE_H */

源文件(中文)

/**
 ******************************************************************************
 * @file    example.c
 * @author  [作者]
 * @version [版本号]
 * @date    [日期]
 * @brief   [模块实现代码,包括功能描述]
 ******************************************************************************
 * @attention
 *
 * [附加注意事项,例如调试说明]
 *
 ******************************************************************************
 */

/* 包含头文件 ----------------------------------------------------------------*/
#include "example.h"

/* 私有宏 --------------------------------------------------------------------*/
#define PRIVATE_MACRO  50 /*!< 内部使用的宏定义 */

/* 私有变量 ------------------------------------------------------------------*/
/**
 * @brief 模块内部状态变量
 */
static uint16_t example_state = 0;

/* 私有函数声明 --------------------------------------------------------------*/
static void Private_Function(void);

/* 函数实现 ------------------------------------------------------------------*/

/**
 * @brief  初始化模块
 * @param  无
 * @retval 无
 */
void Example_Init(void) {
    // 初始化代码
    example_state = 1;
}

/**
 * @brief  处理模块任务
 * @param  无
 * @retval 无
 */
void Example_Process(void) {
    if (example_state) {
        // 任务处理代码
        Private_Function();
    }
}

/**
 * @brief  内部使用的私有函数
 * @param  无
 * @retval 无
 */
static void Private_Function(void) {
    // 私有功能代码
}

头文件(英文)

/**
 ******************************************************************************
 * @file    example.h
 * @author  [Author]
 * @version [Version]
 * @date    [Date]
 * @brief   [Brief description of the header file functionality]
 ******************************************************************************
 * @attention
 *
 * [Additional notes, such as copyright information or usage restrictions]
 *
 ******************************************************************************
 */

#ifndef __EXAMPLE_H
#define __EXAMPLE_H

#ifdef __cplusplus
extern "C" {
#endif

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

/* Macro Definitions --------------------------------------------------------*/
/**
 * @brief Defines related macros for the module
 */
#define EXAMPLE_MACRO  100    /*!< Purpose of the example macro */

/* Type Definitions ---------------------------------------------------------*/
/**
 * @brief Defines structures used by the module
 */
typedef struct {
    uint16_t field1;  /*!< Description of field 1 */
    uint8_t  field2;  /*!< Description of field 2 */
} ExampleTypeDef;

/* Function Declarations ----------------------------------------------------*/
/**
 * @brief  Initialize the module
 * @param  None
 * @retval None
 */
void Example_Init(void);

/**
 * @brief  Handle module tasks
 * @param  None
 * @retval None
 */
void Example_Process(void);

#ifdef __cplusplus
}
#endif

#endif /* __EXAMPLE_H */

源文件(英文)

/**
 ******************************************************************************
 * @file    example.c
 * @author  [Author]
 * @version [Version]
 * @date    [Date]
 * @brief   [Implementation of module functionality, including detailed description]
 ******************************************************************************
 * @attention
 *
 * [Additional notes, such as debugging instructions]
 *
 ******************************************************************************
 */

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

/* Private Macros -----------------------------------------------------------*/
#define PRIVATE_MACRO  50 /*!< Macro for internal use only */

/* Private Variables --------------------------------------------------------*/
/**
 * @brief Internal state variable of the module
 */
static uint16_t example_state = 0;

/* Private Function Declarations --------------------------------------------*/
static void Private_Function(void);

/* Function Implementations -------------------------------------------------*/

/**
 * @brief  Initialize the module
 * @param  None
 * @retval None
 */
void Example_Init(void) {
    // Initialization code
    example_state = 1;
}

/**
 * @brief  Handle module tasks
 * @param  None
 * @retval None
 */
void Example_Process(void) {
    if (example_state) {
        // Task handling code
        Private_Function();
    }
}

/**
 * @brief  Private function for internal use
 * @param  None
 * @retval None
 */
static void Private_Function(void) {
    // Code for private functionality
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值