当前位置:首页 > 单片机 > 单片机
[导读]********************************************************************************************************** DETERMINE IF WE HAVE A LEAP YEAR** Description : This function determines whether the 'ye

*********************************************************************************************************
* DETERMINE IF WE HAVE A LEAP YEAR
*
* Description : This function determines whether the 'year' passed as an argument is a leap year.
* Arguments : year is the year to check for leap year.
* Returns : TRUE if 'year' is a leap year.
* FALSE if 'year' is NOT a leap year.
*********************************************************************************************************
*/
#if CLK_DATE_EN
static BOOL ClkIsLeapYear(UINT year)
{
if (!(year % 4) && (year % 100) || !(year % 400))
{
return TRUE;
}
else
{
return (FALSE);
}
}
#endif
/*
*********************************************************************************************************
* SET DATE ONLY
*
* Description : Set the date of the time-of-day clock
* Arguments : month is the desired month (1..12)
* day is the desired day (1..31)
* year is the desired year (CLK_TS_BASE_YEAR .. CLK_TS_BASE_YEAR+63)
* Returns : None.
* Notes : It is assumed that you are specifying a correct date (i.e. there is no range checking
* done by this function).
*********************************************************************************************************
*/
#if CLK_DATE_EN
void Clk_set_date (UCHAR month, UCHAR day, UINT year)
{
ENTER_CRITICAL();
ClkMonth = month;
ClkDay = day;
ClkYear = year;
ClkUpdateDOW();
EXIT_CRITICAL();
}
#endif
/*
*********************************************************************************************************
* SET DATE AND TIME
*
* Description : Set the date and time of the time-of-day clock
* Arguments : month is the desired month (1..12)
* day is the desired day (1..31)
* year is the desired year (2xxx)
* hr is the desired hour (0..23)
* min is the desired minutes (0..59)
* sec is the desired seconds (0..59)
* Returns : None.
* Notes : It is assumed that you are specifying a correct date and time (i.e. there is no range
* checking done by this function).
*********************************************************************************************************
*/

#if CLK_DATE_EN
void Clk_set_date_time (UCHAR month, UCHAR day, UINT year, UCHAR hr, UCHAR min, UCHAR sec)
{
ENTER_CRITICAL(); /* Gain exclusive access to time-of-day clock */
ClkMonth = month;
ClkDay = day;
ClkYear = year;
ClkHr = hr;
ClkMin = min;
ClkSec = sec;
ClkUpdateDOW(); /* Compute the day of the week (i.e. Sunday ...) */
EXIT_CRITICAL(); /* Release access to time-of-day clock */
}
#endif
/*
*********************************************************************************************************
* UPDATE THE DATE
*
* Description : This function is called to update the date (i.e. month, day and year)
* Arguments : None.
* Returns : None.
* Notes : This function updates ClkDay, ClkMonth, ClkYear and ClkDOW.
*********************************************************************************************************
*/
#if CLK_DATE_EN
static void ClkUpdateDate (void)
{
BOOL newmonth;

newmonth = TRUE;
if (ClkDay >= ClkMonthTbl[ClkMonth].MonthDays) { /* Last day of the month? */
if (ClkMonth == 2) { /* Is this February? */
if (ClkIsLeapYear(ClkYear) == TRUE) { /* Yes, Is this a leap year? */
if (ClkDay >= 29) { /* Yes, Last day in february? */
ClkDay = 1; /* Yes, Set to 1st day in March */
} else {
ClkDay++;
newmonth = FALSE;
}
} else {
ClkDay = 1;
}
} else {
ClkDay = 1;
}
} else {
ClkDay++;
newmonth = FALSE;
}
if (newmonth == TRUE) { /* See if we have completed a month */
if (ClkMonth >= 12) { /* Yes, Is this december ? */
ClkMonth = 1; /* Yes, set month to january... */
ClkYear++; /* ...we have a new year! */
} else {
ClkMonth++; /* No, increment the month */
}
}
ClkUpdateDOW(); /* Compute the day of the week (i.e. Sunday ...) */
}
#endif
/*
*********************************************************************************************************
* COMPUTE DAY-OF-WEEK
*
* Description : This function computes the day of the week (0 == Sunday) based on the current month,
* day and year.
* Arguments : None.
* Returns : None.
* Notes : - This function updates ClkDOW.
* - This function is called by ClkUpdateDate().
*********************************************************************************************************
*/
#if CLK_DATE_EN
static void ClkUpdateDOW (void)
{
UINT dow;

dow = ClkDay + ClkMonthTbl[ClkMonth].MonthVal;
if (ClkMonth < 3)
{
if (ClkIsLeapYear(ClkYear))
{
dow--;
}
}
dow += ClkYear + (ClkYear / 4);
dow += (ClkYear / 400) - (ClkYear / 100);
dow %= 7;
ClkDOW = dow;
}
#endif

//@@***********************************************************
//
// 功能: 给定的时间与当前时间比较
// 函数: int Cmp_now_time(UCHAR hr, UCHAR min, UCHAR sec)
// 语言: C
// 输入:
// 输出: 0 相等
// >0 给定时间大于当前时间
// <0 给定时间小于当前时间
//@@***********************************************************
//-------------------------------------------------------------
int Cmp_now_time(UCHAR hr, UCHAR min, UCHAR sec)
{
if(ClkHr!=hr)
return(hr-ClkHr);
else if(ClkMin!= min)
return(min-ClkMin);
else
return(sec-ClkSec);
}

//@@***********************************************************
//
// 功能: 给定的时间与当前时间比较
// 函数: int Cmp_now_date_time(UCHAR month, UCHAR day, UINT year, UCHAR hr, UCHAR min, UCHAR sec)
// 语言: C
// 输入:
// 输出: 0 相等
// >0 给定时间大于当前时间
// <0 给定时间小于当前时间
//@@***********************************************************
//-------------------------------------------------------------
#if CLK_DATE_EN
int Cmp_now_date_time(UCHAR month, UCHAR day, UINT year, UCHAR hr, UCHAR min, UCHAR sec)
{
if(ClkYear!=year)
return(year-ClkYear);
else if(ClkMonth!=month)
return(month-ClkMonth);
else if(ClkDay!=day)
return(day-ClkDay);
else if(ClkHr!=hr)
return(hr-ClkHr);
else if(ClkMin!= min)
return(min-ClkMin);
else
return(sec-ClkSec);
}
#endif


#endif


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

单片机内部有很多的特殊功能寄存器,每个寄存器在单片机内部都分配有唯一的地址,一般我们会根据寄存器功能的不同给寄存器赋予各自的名称,当我们需要在程序中操作这些特殊功能寄存器时,必须要在程序的最前面将这些名称加以声明,声明的...

关键字: C51 数据类型 扩充定义

数据元(Data Element),也称为数据元素,是用一组属性描述其定义、标识、表示和允许值的数据单元,在一定语境下,通常用于构建一个语义正确、独立且无歧义的特定概念语义的信息单元。数据元可以理解为数据的基本单元,将若...

关键字: C51 数据类型

▼点击下方名片,关注公众号▼欢迎关注【玩转单片机与嵌入式】公众号,回复关键字获取更多免费资料。回复【加群】,限时免费进入知识共享群;回复【3D封装库】,常用元器件的3D封装库;回复【电容】,获取电容、元器件选型相关的内容...

关键字: C51 MDK RealView

在Keil C51软件中51单片机的中断服务和外设驱动程序的开发

关键字: keil5 编译 C51

Intel公司1980年推出了MCS-51系列单片机:集成 8位CPU、4K字节ROM、128字节RAM、4个8位并口、1个全双工串行口、2个16位定时/计数器。寻址范围64K,并有控制功能较强的布尔处理器。 80C5...

关键字: C51 KEIL 编程

c上标3下标5怎么算用计算机,c上标3下标5怎么算

关键字: C51 KEIL

▼点击下方名片,关注公众号▼大家好,很高兴和各位一起分享我的第16篇原创文章,喜欢和支持我的工程师,一定记得给我点赞、收藏、分享。加微信[xyzn3333]与作者沟通交流,免费获取更多单片机与嵌入式的海量电子资料。很多初...

关键字: 51单片机 C51

常看见初学者要求使用_at_,这是一种谬误,把C当作ASM看待了。在C中变量的定位是编译器的事情,初学者只要定义变量和变量的作 用域,编译器就把一个固定地址给这个变量。

关键字: C51 单片机 误区 注意事项

简介:编程首要是要考虑程序的可行性,然后是可读性、可移植性、健壮性以及可测试性。这是总则。但是很多人忽略了可读性、可移植性和健壮性(可调试的方法可能歌不相同),这是不对的。

关键字: C51 编程规范 文件配置

如果你用 Keil C51 进行编译,记住一点:它不区分大小写!!!卧槽,今天编程序那个调错啊,就因为一个数组名和一个变量名完全一样,只是大小写不一样罢了,标准 C 我怎么记得这样可以啊……上网一查,卧槽,Keil C5...

关键字: C51 单片机 编程要点
关闭
关闭