mcu_def.h
/******************************************************************************
文 件 名 : mcu_def.h
版 本 号 : 初稿
作 者 :
生成日期 :
最近修改 :
功能描述 : 此文件定义芯片类型文件
函数列表 :
修改历史 :
1.日 期 :
作 者 :
修改内容 : 创建文件
******************************************************************************/
#ifndef __MCU_DEF_H__
#define __MCU_DEF_H__
// #define STM32F10X_MD
#if defined (STM32F10X_MD) || defined(STM32F10X_HD)
#ifndef STM32F10X_MCU
#define STM32F10X_MCU
#endif
#endif
#if defined (STM32F030)
#ifndef STM32F0XX_MCU
#define STM32F0XX_MCU
#endif
#endif
#if defined (STM32F0XX_MCU)
#include "stm32f0xx.h"
#endif
#if defined (STM32F10X_MCU)
#include "stm32f10x.h"
#endif
#endif /* __MCU_DEF_H__ */
top_type.h
/******************************************************************************
文 件 名 : top_type.h
版 本 号 : 初稿
作 者 :
生成日期 :
最近修改 :
功能描述 : 此文件定义数据类型文件
函数列表 :
修改历史 :
1.日 期 :
作 者 :
修改内容 : 创建文件
******************************************************************************/
#ifndef __TOP_TYPE_H__
#define __TOP_TYPE_H__
#include <stdint.h>
#include "mcu_def.h"
#define __NULL__ ((void *) 0)
typedef enum {__FALSE = 0, __TRUE = !__FALSE} __BOOL__;
/* 双字节高低位数据交换*/
#define __SWAP_U16(val) \
( (((val) & (0xffu << 8)) >> 8) \
| (((val) & 0xffu) << 8) )
/* 四字节高低位数据交换*/
#define __SWAP_U32(val) \
( (((val) & (0xfful << 24)) >> 24) \
| (((val) & (0xfful << 16)) >> 8) \
| (((val) & (0xfful << 8)) << 8) \
| (((val) & 0xfful) << 24) )
/* 八字节高低位数据交换*/
#define __SWAP_U64(val) \
( (((val) & (0xffull << 56)) >> 56) \
| (((val) & (0xffull << 48)) >> 40) \
| (((val) & (0xffull << 40)) >> 24) \
| (((val) & (0xffull << 32)) >> 8) \
| (((val) & (0xffull << 24)) << 8) \
| (((val) & (0xffull << 16)) << 24) \
| (((val) & (0xffull << 8)) << 40) \
| (((val) & 0xffull) << 56) )
typedef signed short s16;
typedef signed char s8;
typedef const int32_t sc32; /*!< Read Only */
typedef const int16_t sc16; /*!< Read Only */
typedef const int8_t sc8; /*!< Read Only */
typedef __IO int32_t vs32;
typedef __IO int16_t vs16;
typedef __IO int8_t vs8;
typedef __I int32_t vsc32; /*!< Read Only */
typedef __I int16_t vsc16; /*!< Read Only */
typedef __I int8_t vsc8; /*!< Read Only */
typedef uint32_t u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef unsigned short const uc16; /*!< Read Only */
typedef unsigned char const uc8; /*!< Read Only */
typedef __IO uint32_t vu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_t vu8;
typedef __I uint32_t vuc32; /*!< Read Only */
typedef __I uint16_t vuc16; /*!< Read Only */
typedef __I uint8_t vuc8; /*!< Read Only */
typedef uint8_t bool;
#endif /* __TOP_TYPE_H__ */
compile_time.h
/******************************************************************************
文 件 名 : compile_time.h
版 本 号 : 初稿
作 者 :
生成日期 :
最近修改 :
功能描述 : 编译时间H文件,定义编译时间类型,并提供获取时间函数
函数列表 :
修改历史 :
1.日 期 :
作 者 :
修改内容 : 创建文件
******************************************************************************/
#ifndef __COMPILE_TIME_H__
#define __COMPILE_TIME_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "top_type.h"
/**
* @ 编译时间: 例子(18-1-5-9-37-40)
* @
*/
typedef struct tag_compile_time
{
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t min;
uint8_t sec;
}__attribute__((packed))compile_time_t;
void compile_time_get (compile_time_t * p_compile_time);
#ifdef __cplusplus
}
#endif
#endif // end __COMPILE_TIME_H__
compile_time.c
/******************************************************************************
文 件 名 : compile_time.c
版 本 号 : 初稿
作 者 :
生成日期 :
最近修改 :
功能描述 : 编译时间C文件:通过预编译__DATE__和__TIME__实现获取编译时间函
数
函数列表 :
compile_time_get
修改历史 :
1.日 期 :
作 者 :
修改内容 : 创建文件
******************************************************************************/
#ifndef __COMPILE_TIME_C__
#define __COMPILE_TIME_C__
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
/* */
/* 头文件包含 */
/* */
/******************************************************************************/
#include "compile_time.h"
#include <stdio.h>
#include <string.h>
/******************************************************************************/
/* */
/* 宏定义 */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* 静态变量定义 */
/* */
/*******************************************************************************/
/******************************************************************************/
/* */
/* 全局变量定义 */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* 静态函数定义 */
/* */
/*******************************************************************************/
/******************************************************************************/
/* */
/* 全局函数定义 */
/* */
/******************************************************************************/
/*****************************************************************************
函 数 名 : compile_time_get
功能描述 : 编译时间:获取编译时间
输入参数 : compile_time_t * p_compile_time
输出参数 : 无
返 回 值 :
调用函数 :
被调函数 :
修改历史 :
1.日 期 : 2018年1月5日
作 者 :
修改内容 : 新生成函数
*****************************************************************************/
void compile_time_get (compile_time_t * p_compile_time)
{
uint8_t time_buf[20];
/* 将time_buf缓存区数据全部设置成0*/
memset(time_buf, 0, sizeof(time_buf));
/* 将p_compile_time缓存区数据全部设置成0*/
memset(p_compile_time, 0, sizeof(compile_time_t));
/* 中断输出编译时间*/
sprintf((char *)time_buf,"%s",__DATE__);
/* 取 2018 中18 */
p_compile_time->year = time_buf[10] - '0';
p_compile_time->year += (time_buf[9] - '0')*10;
/* 月份*/
switch ( time_buf[0] )
{
case 'A' :
{
if ( time_buf[1] == 'p' )
{
p_compile_time->month = 4;
}
else
{
p_compile_time->month = 8;
}
}break;
case 'D' :
{
p_compile_time->month = 12;
}break;
case 'F' :
{
p_compile_time->month = 2;
}break;
case 'J' :
{
if ( time_buf[1] == 'a' )
{
p_compile_time->month = 1;
}
else
{
if ( time_buf[2] == 'n' )
{
p_compile_time->month = 6;
}
else
{
p_compile_time->month = 7;
}
}
}break;
case 'M' :
{
if ( time_buf[2] == 'r' )
{
p_compile_time->month = 3;
}
else
{
p_compile_time->month = 5;
}
}break;
case 'N' :
{
p_compile_time->month = 11;
}break;
case 'O' :
{
p_compile_time->month = 10;
}break;
case 'S' :
{
p_compile_time->month = 9;
}break;
default:
break;
}
/* 日*/
p_compile_time->day = time_buf[5] - '0';
if ( time_buf[4] != ' ' )
{
p_compile_time->day += (time_buf[4] - '0')*10;
}
memset(time_buf, 0, sizeof(time_buf));
sprintf((char *)time_buf,"%s",__TIME__);
/* 时 */
p_compile_time->hour = (time_buf[0] - '0')*10 + (time_buf[1] - '0');
/* 分 */
p_compile_time->min = (time_buf[3] - '0')*10 + (time_buf[4] - '0');
/* 秒 */
p_compile_time->sec = (time_buf[6] - '0')*10 + (time_buf[7] - '0');
}
#ifdef __cplusplus
}
#endif
#endif // end __COMPILE_TIME_C__
main.c
#include "compile_time.h"
/*
* @ 编译时间: 例子(18-1-5-9-37-40)
* @
typedef struct tag_compile_time
{
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t min;
uint8_t sec;
}__attribute__((packed))compile_time_t;
*/
void main(void)
{
compile_time_t compile_time;
/* 获取编译时间 */
compile_time_get (&compile_time);
while(1)
{
}
}