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

📄 rtcc.c

📁 本代码包为该GUI LIB在PC上的测试移植. PIC_Graphics 为PIC GUI的源代码目录 Demo 为PIC GUI 测试代码目录 其他的代码和目录均是uCGUI
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
 *
 * Real Time Clock Calender
 *
 *****************************************************************************
 * FileName:        rtcc.c
 * Dependencies:    
 * Processor:       PIC24
 * Compiler:       	C30 xx.xx or higher
 * Linker:          MPLINK 03.20.01 or higher
 * Company:         Microchip Technology Incorporated
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the "Company") is intended and supplied to you, the Company's
 * customer, for use solely and exclusively with products manufactured
 * by the Company. 
 *
 * The software is owned by the Company and/or its supplier, and is 
 * protected under applicable copyright laws. All rights are reserved. 
 * Any use in violation of the foregoing restrictions may subject the 
 * user to criminal sanctions under applicable laws, as well as to 
 * civil liability for the breach of the terms and conditions of this 
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, 
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED 
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, 
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR 
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Chris Valenti		05-26-05	...	
 * Ross Fosler			06-06-2005	Several changes
 * Anton Alkhimenok     10-21-2005  Get/Set functions
 *****************************************************************************/
#include "MainDemo.h"

#include <string.h>
#include <time.h>	//for time,...
#include <stdio.h>
#include <locale.h>

/*****************************************************************************
 * Structures: _time and _time_chk
 *
 * Overview: These structures contain the time and date.
 * RTCCProcessEvents updates them. _time_chk is used as input/output for
 * get/set operations.
 *
 *****************************************************************************/
RTCC _time;
RTCC _time_chk;
/*****************************************************************************
 * Arrays: _time_str and _date_str
 *
 * Overview: These arrays contain the time and date strings. 
 * RTCCProcessEvents updates them.
 *
 *****************************************************************************/
char _time_str[16] = "                ";		// Sat 10:01:15
char _date_str[16] = "                ";		// Sep 30, 2005

// The flag stops updating time and date and used for get/set operations.
unsigned char _rtcc_flag;
/*****************************************************************************
 * Function: RTCCProcessEvents
 *
 * Preconditions: RTCCInit must be called before.
 *
 * Overview: The function grabs the current time from the RTCC and translate
 * it into strings.
 *
 * Input: None.
 *
 * Output: It update time and date strings  _time_str, _date_str,
 * and _time, _time_chk structures.
 *
 *****************************************************************************/
void RTCCProcessEvents(void)
{
#if 0	
	// Process time object only if time is not being set
	while (!_rtcc_flag) 
	{
		// Grab the time
		RCFGCALbits.RTCPTR = 0;			
		_time.prt00 = RTCVAL;
		RCFGCALbits.RTCPTR = 1;			
		_time.prt01 = RTCVAL;
		RCFGCALbits.RTCPTR = 2;			
		_time.prt10 = RTCVAL;
		RCFGCALbits.RTCPTR = 3;			
		_time.prt11 = RTCVAL;

		// Grab the time again 
		RCFGCALbits.RTCPTR = 0;			
		_time_chk.prt00 = RTCVAL;
		RCFGCALbits.RTCPTR = 1;			
		_time_chk.prt01 = RTCVAL;
		RCFGCALbits.RTCPTR = 2;			
		_time_chk.prt10 = RTCVAL;
		RCFGCALbits.RTCPTR = 3;			
		_time_chk.prt11 = RTCVAL;

		// Verify there is no roll-over
		if ((_time.prt00 == _time_chk.prt00) &&
			(_time.prt01 == _time_chk.prt01) &&
			(_time.prt10 == _time_chk.prt10) &&
			(_time.prt11 == _time_chk.prt11)
			)
		{
			switch (_time.mth) 
			{
				default:
				case 0x01: _date_str[0] = 'J'; _date_str[1] = 'a'; _date_str[2] = 'n'; break; 
				case 0x02: _date_str[0] = 'F'; _date_str[1] = 'e'; _date_str[2] = 'b'; break; 
				case 0x03: _date_str[0] = 'M'; _date_str[1] = 'a'; _date_str[2] = 'r'; break; 
				case 0x04: _date_str[0] = 'A'; _date_str[1] = 'p'; _date_str[2] = 'r'; break; 
				case 0x05: _date_str[0] = 'M'; _date_str[1] = 'a'; _date_str[2] = 'y'; break; 
				case 0x06: _date_str[0] = 'J'; _date_str[1] = 'u'; _date_str[2] = 'n'; break; 
				case 0x07: _date_str[0] = 'J'; _date_str[1] = 'u'; _date_str[2] = 'l'; break; 
				case 0x08: _date_str[0] = 'A'; _date_str[1] = 'u'; _date_str[2] = 'g'; break; 
				case 0x09: _date_str[0] = 'S'; _date_str[1] = 'e'; _date_str[2] = 'p'; break; 
				case 0x10: _date_str[0] = 'O'; _date_str[1] = 'c'; _date_str[2] = 't'; break; 
				case 0x11: _date_str[0] = 'N'; _date_str[1] = 'o'; _date_str[2] = 'v'; break; 
				case 0x12: _date_str[0] = 'D'; _date_str[1] = 'e'; _date_str[2] = 'c'; break; 
			}

			_date_str[3] = ' ';
			_date_str[6] = ',';
			_date_str[7] = ' ';
			_date_str[8] = '2';
			_date_str[9] = '0';

			_date_str[4] = (_time.day >> 4) + '0';
			_date_str[5] = (_time.day & 0xF) + '0';

			_date_str[10] = (_time.yr >> 4) + '0';
			_date_str[11] = (_time.yr & 0xF) + '0';

			switch (_time.wkd) {
				default:
				case 0x00: _time_str[0] = 'S'; _time_str[1] = 'u'; _time_str[2] = 'n'; break; 
				case 0x01: _time_str[0] = 'M'; _time_str[1] = 'o'; _time_str[2] = 'n'; break; 
				case 0x02: _time_str[0] = 'T'; _time_str[1] = 'u'; _time_str[2] = 'e'; break; 
				case 0x03: _time_str[0] = 'W'; _time_str[1] = 'e'; _time_str[2] = 'd'; break; 
				case 0x04: _time_str[0] = 'T'; _time_str[1] = 'h'; _time_str[2] = 'u'; break; 
				case 0x05: _time_str[0] = 'F'; _time_str[1] = 'r'; _time_str[2] = 'i'; break; 
				case 0x06: _time_str[0] = 'S'; _time_str[1] = 'a'; _time_str[2] = 't'; break;  
			}
			
			_time_str[3] = ' ';
			_time_str[6] = ':';
			_time_str[9] = ':';

			_time_str[4] = (_time.hr >> 4) + '0';
			_time_str[5] = (_time.hr & 0xF) + '0';

			_time_str[7] = (_time.min >> 4) + '0';
			_time_str[8] = (_time.min & 0xF) + '0';

			_time_str[10] = (_time.sec >> 4) + '0';
			_time_str[11] = (_time.sec & 0xF) + '0';

			break;
		}	
	}
#else
	time_t 	    now;
	struct tm * ts;
	
	time( &now );
	ts = localtime( &now );
	
	strftime( _time_str, sizeof(_time_str), "%a %H:%M:%S", ts ); //Thu 14:17:15	
	strftime( _date_str, sizeof(_date_str), "%b %d, %Y", ts ); //Sep 30, 2005
		
	//printf("%s:%s():%d %s\n", __FILE__, __FUNCTION__, __LINE__, _date_str);
#endif
}

/*****************************************************************************
 * Function: RTCCInit
 *
 * Preconditions: RTCCInit must be called before.
 *
 * Overview: Enable the oscillator for the RTCC
 *
 * Input: None.
 *
 * Output: None.
 *****************************************************************************/
void RTCCInit(void)
{
#if 0	
    // Enables the LP OSC for RTCC operation
	asm("mov #OSCCON,W1");
	asm("mov.b	#0x02, W0");
	asm("mov.b	#0x46, W2");
	asm("mov.b	#0x57, W3");
	asm("mov.b	W2, [W1]");
	asm("mov.b	W3, [W1]");
	asm("mov.b	W0, [W1]");		

    // Unlock sequence must take place for RTCEN to be written
	RCFGCAL	= 0x0000;			
    mRTCCUnlock();
    RCFGCALbits.RTCEN = 1;
	mRTCCOn();
	mRTCCSetSec(0x01);
	mRTCCSetMin(0x10);
	mRTCCSetHour(0x10);
	mRTCCSetWkDay(0x2);
	mRTCCSetDay(0x13);
	mRTCCSetMonth(0x11);
	mRTCCSetYear(0x07);
	mRTCCSet();
#endif	
}

/*****************************************************************************
 * Function: RTCCSet
 *
 * Preconditions: None.
 *
 * Overview: The function upload time and date from _time_chk into clock.
 *
 * Input: _time_chk - structure containing time and date.
 *
 * Output: None.
 *
 *****************************************************************************/
void RTCCSet(void)
{
#if 0		
	mRTCCUnlock();			// Unlock the RTCC

⌨️ 快捷键说明

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