⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sectodata.c

📁 单片机C源程序souce
💻 C
字号:
/**************************************
File          :  SECTODATA.C
Project       :  BDTRV20_MCU_V07
Description   :  将秒值转换成时分秒,日月年。秒从1969年1月1日开始计
Created       :  2006.11.7
Last updata   :  
Author        :  Sunzehui   sunzehui@zzvcom.com
Compile Tool  :  Keil uVision2
Target Device :  SST89V564RD
Circuit Board :  BD7700
************************************
Modification History
************************************
 Version      : v2.0
 Date         : MM/DD/YYYY
 Modifier     :
 Description  :

 **********************************
 -- Copyright (c)
*************************************/

extern unsigned char *sectodata(unsigned long tod)
	{
	unsigned char xdata hour;
	unsigned char xdata day;
	unsigned char xdata minute;
	unsigned char xdata second;
	unsigned char xdata month;
	unsigned int xdata year;
	unsigned long xdata p;
//	unsigned long xdata whole_minutes;
//	unsigned long xdata whole_hours;
//	unsigned long xdata whole_days;
	unsigned long xdata whole_days_since_1968;
	unsigned long xdata leap_year_periods;
	unsigned long xdata days_since_current_lyear;
//	unsigned long xdata whole_years;
	unsigned long xdata days_since_first_of_year;
	unsigned long xdata days_to_month;
	unsigned int DaysToMonth[] = {0,0,31,59,90,120,151,181,212,243,273,304,334};
	unsigned char xdata b[7];
	if (tod == 0) return 0;

     p= tod / 60;//whole_minutes
    //second = binary - (60 * whole_minutes); /* leftover seconds*/
	second = tod%60;
    
    //minute = whole_minutes - (60 * whole_hours); /* leftover minutes*/
	minute = p%60;
	p = p / 60;//whole_hours
    
   // hour = whole_hours - (24 * whole_days); /* leftover hours*/
   hour = p%24;
    p= p / 24;//whole_days

    whole_days_since_1968 = p;// + 365 + 366;//whole_days
    leap_year_periods = whole_days_since_1968 / ((4 * 365) + 1);
    days_since_current_lyear = whole_days_since_1968 % ((4 * 365) + 1);
    /* if days are after a current leap year then add a leap year period*/
    if ((days_since_current_lyear >= (31 + 29)))
        {leap_year_periods++;} 
    p = (whole_days_since_1968 - leap_year_periods)  / 365;//whole_years
    days_since_first_of_year = whole_days_since_1968 - (p * 365) - leap_year_periods;
  
    if ((days_since_current_lyear <= 365) && (days_since_current_lyear >= 60)) 
        {days_since_first_of_year++;}
    year = p + 1980;//68;
 
    /* setup for a search for what month it is based on how many days have past*/
    /* within the current year*/
    month = 13;
    days_to_month = 366;
    while (days_since_first_of_year < days_to_month)
        { 
        month--; 
        days_to_month = DaysToMonth[month]; 
        if ((month >= 2) && ((year % 4) == 0)) 
        {days_to_month++;}
        } 
    day = days_since_first_of_year - days_to_month + 1;
	b[0]=hour; //时
	b[1]=minute;//分
	b[2]=second;//秒
	b[3]=year>>8;
	b[4]=year;//年
	b[5]=month;//月
	b[6]=day;  //日
    return b;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -