NUCLEO-G071RB:009——HAL库-显示编译时间
- 编译时间
- 设计目标
- 程序修改
- 运行测试
编译时间
这里的编译时间指的是烧录文件的编译时间,它由编译环境的日期和时间共同决定。
设计目标
1、获取编译时间,默认是ASC码格式
2、将编译时间转换为HEX
程序修改
typedef struct
{
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
}compile_time_st;
compile_time_st st_compile_time = {0,};
//调用以下函数时,将结构体st_compile_time的地址丢在入口参数上
void bsp_get_compile_time(compile_time_st * time_buf)
{
const uint8_t Month_Table[12][3] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
uint8_t i;
const uint8_t date[12] = __DATE__,
time[9] = __TIME__;
//日期 ASC-->HEX
time_buf -> year = (date[7]-'0')*1000 + (date[8]-'0')*100 + (date[9]-'0')*10 + (date[10]-'0')*1;
for (i = 0;i <12;i ++)
{
if ((Month_Table[i][0] == date[0]) && (Month_Table[i][1] == date[1]) && (Month_Table[i][2] == date[2])){
time_buf -> month = i + 1;
break;
}
}
//时间 ASC-->HEX
time_buf -> day = (date[4] == ' ') ? ((date[5]-'0')*1):((date[4]-'0')*10 + (date[5]-'0')*1);
time_buf -> hour = (time[0]-'0')*10 + (time[1]-'0')*1;
time_buf -> minute = (time[3]-'0')*10 + (time[4]-'0')*1;
time_buf -> second = (time[6]-'0')*10 + (time[7]-'0')*1;
}