📄 common.h
字号:
#include <absacc.h>
#include <intrins.h>
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
//判断是否闰年
uchar isLeapyear(uint year)
{
//闰年判断:year被4整除但不被100整除
// 或year被4整除且被400整除
if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
{
return 1;
}
else
{
return 0;
}
}
///根据给定风格日期计算星期
uchar GetWeek(uint year, uchar month, uchar day)
{
uchar leapFlag = 0;
uchar week = 0;
uchar i = 0;
uchar a[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //每月天数数组
uint count = 0;
leapFlag = isLeapyear( year );
if (leapFlag == 1)
{
a[2]++;
}
for (i = 1; i < month; i++)
{
count = count + a[i];
} //计算从给定年份的1月1日到给定日之前的天数
count = count + day;
//计算星期
week = (year - 1 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + count) % 7;
return week;
}
void delay(uint time)
{
uint i = 0;
uint j = 0;
for (i = 0; i < 100; i ++)
{
for (j = 0; j < time; j++)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -