您的位置:首页技术文栏单片机C51
内容搜索:
阅读内容
背景:#EDF0F5 #FAFBE6 #FFF2E2 #FDE6E0 #F3FFE1 #DAFAF3 #EAEAEF 默认  

100年日历带星期计算

[日期:2008-02-16 ] [来源:net 作者:佚名] [字体: (投递新闻)

100年日历带星期计算


发布时间:2008年1月5日 1时37分


// CalculateVC.cpp : Defines the entry point for the console application by VC6.0
// Function : simulate  singlechip Demo program
// Create time: 2006-11-21
// lhx_127@126.com

#include "stdafx.h"
#include <windows.h>
static unsigned char ucCount;
unsigned char const pWeek_tab[] = {0,1,4,4,0,2,5,0,3,6,1,4,6};
unsigned char const pMonth_tab[] = {0,
31,  //1
28,  //2
31,  //3
30,  //4
31,  //5
30,  //6
31,  //7
31,  //8
30,  //9
31,  //10
30,  //11
31   //2

};

typedef struct _SoftTime
{
 unsigned char Seconds;
 unsigned char Minutes;
 unsigned char Hours;
 unsigned char WeekDays;
 unsigned char Days;
 unsigned char Months;
 unsigned char Years;
 
} SoftTime, *pSoftTime ;

SoftTime structSoftTime;
//===================================================================
//Function Name :CalculateWeekDay
// Function     : According to date calculation weeks from the first
//                 year to the year 5535, no matter from the system
//       when the week began and ended
//input         : Year,Month,Day
//OutPut        : Week
//global        : None
//===================================================================

unsigned char CalculateWeekDay(unsigned int Year,unsigned char Month,unsigned char Date)
{
 unsigned char err;
 
 if((Month<3) && (!(Year&0x03) && (Year%1000) || (!(Year%400)))) {
  Date--;
 }
 err = (Date + Year + Year/4 + Year/400 - Year/100 + pWeek_tab[Month]-
  2)%7;
 
 return err;
}

 

void SoftTime_UpdataData(void)

 
 if( structSoftTime.Days >= pMonth_tab[structSoftTime.Months])
    {
  
  if( structSoftTime.Months == 2)
  {
   if(!(structSoftTime.Years & 0x03 ))
   {
    if(structSoftTime.Days >= 29 ) structSoftTime.Days = 1;
    else{structSoftTime.Days++; structSoftTime.Months--; }
   }
   else   structSoftTime.Days = 1;
  } else   structSoftTime.Days = 1;
  
  if( structSoftTime.Months >= 12)
  {
   structSoftTime.Months = 1;
   structSoftTime.Years++;
   if(structSoftTime.Years == 100) structSoftTime.Years = 0;
  }else structSoftTime.Months++;
   //{if( !(!(structSoftTime.Years & 0x03) && (structSoftTime.Months == 2)) )structSoftTime.Months++; }
  
  
  
 }else structSoftTime.Days++;
}


int main(int argc, char* argv[])
{
 
 unsigned char temp;
    unsigned char Week;
 structSoftTime.Years = 20;
 structSoftTime.Months = 11;
 structSoftTime.Days  = 21;
 structSoftTime.Hours = 12;
 structSoftTime.Minutes = 10;
 
 Week = CalculateWeekDay(2006,1,21);
 printf("this Week is %d \n",Week);
    while (1)
    {
 // Sleep(1);
  ucCount++;
  if(ucCount == 2)
  {
   ucCount = 0;
   structSoftTime.Seconds++;
    }
   if(structSoftTime.Seconds >= 59  )
   {
    
    structSoftTime.Seconds = 0;
    if(structSoftTime.Minutes >= 59)
    { printf(" data -- %2d-%2d-%2d---%2d-%2d\n",structSoftTime.Years,
    structSoftTime.Months,
    structSoftTime.Days,structSoftTime.Hours,structSoftTime.Minutes);
    
    structSoftTime.Minutes = 0;
    if(structSoftTime.Hours >= 23 )
    {
     structSoftTime.Hours = 0;
     SoftTime_UpdataData();
     
    }
    else structSoftTime.Hours++;
    }
    else
     structSoftTime.Minutes++;
   }
  
    
 
    }
 return 0;
}

 

阅读:
录入:petta

推荐 】 【 打印
本文评论
      全部评论
发表评论


点评: 字数
姓名:
站长推荐