本帖最后由 ee168 于 2022-11-1 14:34 编辑
如果是文件夹
可通过Option->User,After Build放置"<path>\DoVer xxx"实现。
xxx 为keil输出文件夹。
注意这个程序要放在输出文件(夹)同级或上级目录中
另外付版本计算
typedef struct //
{
unsigned short int year; //
unsigned char month; // 1-0x0C
unsigned char day; // 1-0x1F
}DateX_s;
unsigned int VerYear = 2020;
int GetAbsDays(DateX_s x)
{
int i;
int month_day[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
int year = x.year - 1; // 因为欲求距离1年1月1日的距离
int days = year * 365 + year / 4 - year / 100 + year / 400; // 求得之前闰年的数量并在天数上进行想加
if ((x.year % 4 == 0 && x.year % 100 != 0) || x.year % 400 == 0)
month_day[1]++; // 当前年为闰年,二月加 1
for (i = 0; i<x.month - 1; i++)
days += month_day;
days += x.day - 1; // 今天应该是不算如天数计数
return days;
}
unsigned int keil_compile_ver(unsigned char *pAsc)
{
unsigned char DataStr[] = __DATE__;
DateX_s sDefaultDay, sToday;
uint32_t u32tmp;
// 年
sscanf((const char*)(&DataStr[7]), "%4u", &u32tmp);
if (u32tmp < VerYear)
{
*pAsc = 0;
return 0;
}
sToday.year = u32tmp;
// 月
if (memcmp(DataStr, "Jan", 3) == 0) // 1月
sToday.month = 1;
else if (memcmp(DataStr, "Feb", 3) == 0) // 2月
sToday.month = 2;
else if (memcmp(DataStr, "Mar", 3) == 0) // 3月
sToday.month = 3;
else if (memcmp(DataStr, "Apr", 3) == 0)
sToday.month = 4;
else if (memcmp(DataStr, "May", 3) == 0)
sToday.month = 5;
else if (memcmp(DataStr, "Jun", 3) == 0)
sToday.month = 6;
else if (memcmp(DataStr, "Jul", 3) == 0)
sToday.month = 7;
else if (memcmp(DataStr, "Aug", 3) == 0)
sToday.month = 8;
else if (memcmp(DataStr, "Sep", 3) == 0)
sToday.month = 9;
else if (memcmp(DataStr, "Oct", 3) == 0)
sToday.month = 10;
else if (memcmp(DataStr, "Nov", 3) == 0)
sToday.month = 11;
else if (memcmp(DataStr, "Dec", 3) == 0)
sToday.month = 12;
else
{
*pAsc = 0;
return 0;
}
sscanf((const char*)(&DataStr[4]), "%2u", &u32tmp);
if(u32tmp < 1 || u32tmp > 31)
{
*pAsc = 0;
return 0;
}
sToday.day = u32tmp;
sDefaultDay.year = VerYear;
sDefaultDay.month = 1;
sDefaultDay.day = 1;
u32tmp = GetAbsDays(sToday) - GetAbsDays(sDefaultDay);
if (pAsc)
sprintf((char*)pAsc,"%04X", u32tmp);
return u32tmp;
}
|