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

📄 calender.c

📁 使用avr--cc2420模块程序,需要原理图的联系 QQ:120304948
💻 C
📖 第 1 页 / 共 3 页
字号:
//@@***********************************************************
//-------------------------------------------------------------
//
// 文件名   :Calender.c
// 描述     :日历时钟模块,用于不带时钟芯片的系统
// 语言     :C
// 作者     :Jean J. Labrosse
// 修改     :李艳平  
// 日期     :2002-05-17
// 说明     :原来的程序用于UCII_RTOS中,现移植C51中
//@@***********************************************************
//
//#define   SYS_CLOCK_EN  1
//#if       SYS_CLOCK_EN
//#include "include.h"
//#include  "typedef.h"
//#include "calender.h"
//#include <iom128.h>
//#include  "string.h"
//#include  "stdlib.h"
//#include  "Stdio.h"
//
//#define   FOSC                    22118400L
//#define   MACHINE_NUM             12            /*根据需要调整,如:W777E58=4*/
//#define   TICKS_PER_SEC           10            /* # of clock ticks to obtain 1 second               */
//
//#define   CLK_DATE_EN             1             /* Enable DATE (when 1)                               */  
//
//#define   ENTER_CRITICAL()        EA=1
//#define   EXIT_CRITICAL()         EA=0                         
//
//#if CLK_DATE_EN
//
//
//CLK_DAY * clk_cur_pCLK = NULL;
//
//
//typedef struct clk_month 
//{         
//    UCHAR  MonthDays;                /* Number of days in each month                                 */
//    char  *MonthName;                /* Name of the month                                            */
//    UCHAR  MonthVal;                 /* Value used to compute day of the week                        */
//} CLK_MONTH;
//#endif
//
//static UCHAR   ClkTickCtr;           /* Counter used to keep track of system clock ticks             */
//
//static UCHAR   ClkHr;
//static UCHAR   ClkMin;
//static UCHAR   ClkSec;               /* Counters for local TIME 
//                                     */
//#if    CLK_DATE_EN
//static UCHAR   ClkDay;               /* Counters for local DATE                                      */
//static UCHAR   ClkDOW;               /* Day of week (0 is Sunday)                                    */
//static UCHAR   ClkMonth;
//static UINT    ClkYear;
//#endif
///**********************************************************************************************************
//*                                          FUNCTION PROTOTYPES
//**********************************************************************************************************/       
//static  BOOL       ClkUpdateTime(void);
//
//
//void Send()
//{
//	BYTE szBuffer[15];
//	
//	char szBuffera[32];
//	char szBuf1[15];
//	char szBuf2[15];
//
//	
//    disp_real();
//	if (sclk)
//        return;
//        
//	memset(szBuffera, 0x00, 32);
//	memset(szBuf2, 0x00, 15);
//	Clk_format_date(3,	szBuf2);           
//	
//	memset(szBuf1,0x00, 15);
//	Clk_format_time(1, szBuf1);
//	
//	sprintf(szBuffera, "%s %s", szBuf2, szBuf1);
//	
//	disp_string(6,111,szBuffera);
//
//	memset(szBuffer, 0x00, 15);
//	Clk_format_time(1, (char*)szBuffer);
//	sp_send(szBuffer);
//	sp_send(" ");
//	memset(szBuffer,0x00, 15);
//	Clk_format_date(3,	(char*)szBuffer);
//	sp_send(szBuffer);
//	memset(szBuffer, 0x00, 15);
//	sprintf((char*)szBuffer, " OM = %d\r\n", ombro_getcount());
//	sp_send(szBuffer);
//	sp_send("\r");
//	
//}
//
//#if     CLK_DATE_EN
//static  BOOL       ClkIsLeapYear(UINT year);
//static  void       ClkUpdateDate(void);
//static  void       ClkUpdateDOW(void);
//#endif
//
//void   Init_sys_timer(void);
//void   Sys_clk_init(void); 
//void   Sys_clk_task(void);
//
//void   Clk_format_time(UCHAR mode, char *s);
//void   Clk_set_time(UCHAR hr, UCHAR min, UCHAR sec);
//int    Cmp_now_time(UCHAR hr, UCHAR min, UCHAR sec);
//
//#if    CLK_DATE_EN
//void   Clk_format_date(UCHAR mode, char *s);
//void   Clk_set_date(UCHAR month, UCHAR day, UINT year);
//void   Clk_set_date_time(UCHAR month, UCHAR day, UINT year, UCHAR hr, UCHAR min, UCHAR sec);
//int    Cmp_now_date_time(UCHAR month, UCHAR day, UINT year, UCHAR hr, UCHAR min, UCHAR sec);
//#endif
///*********************************************************************************************************/
//
//
//#if CLK_DATE_EN
//static  char *ClkDOWTbl[] = {          /* NAME FOR EACH DAY OF THE WEEK                                */
//    "Sunday ",
//    "Monday ",
//    "Tuesday ",
//    "Wednesday ",
//    "Thursday ",
//    "Friday ",
//    "Saturday "
//};
//
//
//static CLK_MONTH ClkMonthTbl[] = {    /* MONTHS TABLE                                                 */
//    {0,  "",           0},             /* Invalid month                                                */
//    {31, "January ",   6},             /* January                                                      */
//    {28, "February ",  2},             /* February (note leap years are handled by code)               */
//    {31, "March ",     2},             /* March                                                        */
//    {30, "April ",     5},             /* April                                                        */
//    {31, "May ",       0},             /* May                                                          */
//    {30, "June ",      3},             /* June                                                         */
//    {31, "July ",      5},             /* July                                                         */
//    {31, "August ",    1},             /* August                                                       */
//    {30, "September ", 4},             /* September                                                    */
//    {31, "October ",   6},             /* October                                                      */
//    {30, "November ",  2},             /* November                                                     */
//    {31, "December ",  4}              /* December                                                     */
//};
//#endif  
///*
//*********************************************************************************************************
//*                                        TIME-OF-DAY CLOCK TASK
//*
//* Description : This task is created by Sys_clk_init() and is responsible for updating the time and date.
//*               Sys_clk_task() executes every second.
//* Arguments   : None.
//* Returns     : None.
//* Notes       : CLK_DLY_TICKS must be set to produce 1 second delays.
//*********************************************************************************************************
//*/
//void  Sys_clk_task (void)
//{
//     if(++ClkTickCtr==TICKS_PER_SEC)   
//      {
//      	
//         ClkTickCtr=0;
//         //Send();                      
//         if (ClkUpdateTime() == TRUE)
//         {     
//          #if CLK_DATE_EN
//              ClkUpdateDate();                 /* And date if a new day (i.e. MM-DD-YY)       */
//          #endif
//         }
//      }
//}  
//
////@@***********************************************************
////
////   功能:  系统时钟中断服务函数
////   函数:  void Sys_tick_isr(void)
////   语言:  C
////   输入:  NONE
////   输出:  NONE
////   作者:  李艳平
////   日期:  2002-05-17
////
////@@***********************************************************
////-------------------------------------------------------------
//
//
////@@***********************************************************
////
////   功能:  系统定时器初始化
////   函数:  void Vtimer_init(void)
////   语言:  C
////   输入:  NONE
////   输出:  NONE
////   作者:  李艳平
////   日期:  2002-05-17
////
////@@***********************************************************
////-------------------------------------------------------------
//void Init_sys_timer(void)
//{
////  BYTE_WORD Init_value; 
//
//  
//  Sys_clk_init();  
//    
//  //Init_value.word=0;//FOSC/(TICKS_PER_SEC*MACHINE_NUM); 
//  //TH2=RCAP2H=-Init_value.bytes.high;
//  //TL2=RCAP2L=-Init_value.bytes.low;
//
//  //ET2=1;
//  //TR2=1;  	
//  
//  //TMOD&=0xF0;			      //使用定时器0,但在中断中需要重新赋初值,因而我更倾向用Timer2
//  //TMOD|=0x01;
//  
// // Init_value.word=FOSC/(TICKS_PER_SEC*MACHINE_NUM); 
//  //TH0=-Init_value.bytes.high;
//  //TL0=-Init_value.bytes.low;
//
//  //ET0=1;
//  //TR0=1;
//}
//
///*
//*********************************************************************************************************
//*                                        TIME MODULE INITIALIZATION
//*                                     TIME-OF-DAY CLOCK INITIALIZATION
//*
//* Description : This function initializes the time module.  The time of day clock task will be created
//*               by this function.
//* Arguments   : None
//* Returns     : None.
//*********************************************************************************************************
//*/
//void  Sys_clk_init (void)
//{
//    ClkTickCtr = 0;
//    Clk_set_time(6,0,0);
//#if CLK_DATE_EN
//    Clk_set_date(6,6,2005);
//#endif    
//}
///*
//*********************************************************************************************************
//*                                    FORMAT CURRENT DATE INTO STRING
//*
//* Description : Formats the current date into an ASCII string.
//* Arguments   : mode   is the format type:
//*                      1   will format the time as "MM-DD-YY"           (needs at least  9 characters)
//*                      2   will format the time as "Day Month DD, YYYY" (needs at least 30 characters)
//*                      3   will format the time as "YYYY-MM-DD"         (needs at least 11 characters)
//*               s      is a pointer to the destination string.  The destination string must be large
//*                      enough to hold the formatted date.
//*                      contain
//* Returns     : None.
//* Notes       : - A 'switch' statement has been used to allow you to add your own date formats.  For
//*                 example, you could display the date in French, Spanish, German etc. by assigning
//*                 numbers for those types of conversions.
//*               - This function assumes that strcpy(), strcat() and itoa() are reentrant.
//*********************************************************************************************************
//*/
//#if  CLK_DATE_EN
//void  Clk_format_date (UCHAR mode, char *s)
//{
//    UINT  year;
//    char    str[5];
//    year = ClkYear;
//    switch (mode) 
//       {
//        case  1:
//              strcpy(s, "MM-DD-YY");             /* Create the template for the selected format        */
//              s[0] = ClkMonth / 10 + '0';        /* Convert DATE to ASCII                              */
//              s[1] = ClkMonth % 10 + '0';
//              s[3] = ClkDay   / 10 + '0';
//              s[4] = ClkDay   % 10 + '0';
//              year = ClkYear % 100;
//              s[6] = year / 10 + '0';
//              s[7] = year % 10 + '0';
//              break;
//
//        case  2:
//              strcpy(s, ClkDOWTbl[ClkDOW]);                  /* Get the day of the week                */
//              strcat(s, ClkMonthTbl[ClkMonth].MonthName);    /* Get name of month                      */
//              if (ClkDay < 10)
//               {
//                 str[0] = ClkDay + '0';

⌨️ 快捷键说明

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