哈哈,俺做CM0菜鸟已经一年了~~~void rtc_t::SetWeek(uint32_t Year, uint32_t Month, uint32_t Day)
{
uint32_t DayOfWeek;
#if WEEK_M == 1
//月表=(13*Month+8)/5
static const char WeekTable[]="\x2\x5\x0\x3\x5\x1\x4\x6\x2\x0";
#endif
if (WriteEnable())
{
if (Month < 2)
{
//去年
if (Year > 0) Year --;//2000.3~2099.12
else Year = 9999;
//今年的1月2月是去年的13月14月
// Month += 12;
//今年的1月2月是去年的5月6月
Month += 4;
}
#if WEEK_M == 0
//世纪内星期算法
//工程编译长度合计3480个字节
DayOfWeek = ((Year%100)+((Year%100)>>2)+(13*Month+8)/5+Day)%7;
#else
#if WEEK_M == 1
//菜农星期表格=((百年%4)*5+年+年/4+月表+日)%7
//月表=(13*Month+8)/5
//工程编译长度合计3492个字节
DayOfWeek = (((Year/100)&3)*5+(Year%100)+((Year%100)>>2)+WeekTable[Month-3]+Day)%7;
#else
#if WEEK_M == 2
//菜农星期公式=((百年&3)*5+年+(年>>2)+(13*月+8)/5+日)%7
//工程编译长度合计3500个字节
DayOfWeek = (((Year/100)&3)*5+(Year%100)+((Year%100)>>2)+(13*Month+8)/5+Day)%7;
#else
#if WEEK_M == 3
//菜农星期公式2=((百年*5)%20+年+(年>>2)+(13*月+8)/5+日)%7
//工程编译长度合计3492个字节
DayOfWeek = (((Year/100)*5)%20+(Year%100)+((Year%100)>>2)+(13*Month+8)/5+Day)%7;
#else
#if WEEK_M == 4
//基姆拉尔森星期公式=(百年/4+百年*5+年+年/4+(13*月+8)/5+日)%7
//工程编译长度合计3516个字节
DayOfWeek = (Year/400+(Year/100)*5+(Year%100)+((Year%100)>>2)+(13*Month+8)/5+Day)%7;
#else
#if WEEK_M == 5
//蔡勒完整星期公式=(203+百年/4-2*百年+年+年/4+(13*月+3)/5+日+1)%7
//工程编译长度合计3516个字节
DayOfWeek = (203+Year/400-(Year/100)*2+(Year%100)+((Year%100)>>2)+(13*Month+8)/5+Day)%7;
#else //WEEK_M == 6
//蔡勒星期公式=(百年/4-2*百年+年+年/4+(13*月+3)/5+日+1)%7 (此公式不能在计算机实战)
//工程编译长度合计3508个字节
DayOfWeek = (Year/400-(Year/100)*2+(Year%100)+((Year%100)>>2)+(13*Month+8)/5+Day)%7;
#endif
#endif
#endif
#endif
#endif
#endif
#if LOOK_H == 0
RTCs.DWR.Bits.DWR = DayOfWeek;
#else
RTC.DWR().DWR = DayOfWeek;
#endif
rtc_t::DayOfWeek = DayOfWeek;
}
}
|