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

📄 lpc_rtc.c

📁 给大家提供一个在inram/exram中调试的示例,在周公的lpc2200上调试过.
💻 C
📖 第 1 页 / 共 2 页
字号:
 * Function Name: RTC_GetTime
 * Parameters: LPC_Rtc_Time_t *pTime
 * Return: void 
 *
 * Description: Set the current time
 *  
 *************************************************************************/
void RTC_GetTime (LPC_Rtc_Time_t *pTime)
{
	pTime->hour = RTC_HOUR;
	pTime->minute = RTC_MIN;
	pTime->second = RTC_SEC;
}


/*************************************************************************
 * Function Name: RTC_GetDateTime
 * Parameters: LPC_Rtc_DateTime_t *pDateTime
 * Return: void 
 *
 * Description: Get the current date and time
 *  
 *************************************************************************/
void RTC_GetDateTime (LPC_Rtc_DateTime_t *pDateTime)
{
	pDateTime->day = RTC_DOM;
	pDateTime->month = RTC_MONTH;
	pDateTime->year = RTC_YEAR;

	pDateTime->hour = RTC_HOUR;
	pDateTime->minute = RTC_MIN;
	pDateTime->second = RTC_SEC;

	pDateTime->DOW = RTC_DOW;
	pDateTime->DOY = RTC_DOY;
}


/*************************************************************************
 * Function Name: RTC_SetInctInt
 * Parameters: lpc_uint8 IncIntType
 * Return: void 
 *
 * Description: Set increment interrupt type
 *  
 *************************************************************************/
void RTC_SetIncInt (lpc_uint8 IncIntType)
{
	RTC_CIIR = IncIntType & 0xFF;
}


/*************************************************************************
 * Function Name: RTC_DisableIncInt
 * Parameters: void
 * Return: void 
 *
 * Description: Disable RTC increment interrupt.
 *  
 *************************************************************************/
void RTC_DisableIncInt(void)
{
	RTC_CIIR = 0;
}


/*************************************************************************
 * Function Name: RTC_SetAlarmtInt
 * Parameters: lpc_uint8 AlarmIntType
 * Return: void 
 *
 * Description: Set alarm interrupt type
 *  
 *************************************************************************/
void RTC_SetAlarmInt (lpc_uint8 AlarmIntType)
{
	RTC_AMR = ~AlarmIntType & 0xFF;
}


/*************************************************************************
 * Function Name: RTC_DisableAlarmInt
 * Parameters: void
 * Return: void 
 *
 * Description: Disable RTC alarm interrupt.
 *  
 *************************************************************************/
void RTC_DisableAlarmInt(void)
{
	RTC_AMR = 0xFF;
}


/*************************************************************************
 * Function Name: RTC_SetAlarmDateTime
 * Parameters: LPC_Rtc_DateTime_t *pDateTime
 * Return: int 
 *             	0: sucess
 *			1: fail
 * Description: Set your specifying alarm date and time
 *  
 *************************************************************************/
int RTC_SetAlarmDateTime (LPC_Rtc_DateTime_t *pDateTime)
{
	/* Valid Judge */
	if (!IsValidDay(pDateTime->year, pDateTime->month, pDateTime->day))
		return 1;

	if ( pDateTime->hour > 23 || pDateTime->minute > 59 ||pDateTime->second > 59)
		return 1;

	/* Calulate DOW, DOY */
	pDateTime->DOY = GetDOY(pDateTime->year, pDateTime->month, pDateTime->day);
	pDateTime->DOW = GetDOW(pDateTime->year, pDateTime->month, pDateTime->day);

	RTC_ALDOM=pDateTime->day;
	RTC_ALMON=pDateTime->month;
	RTC_ALYEAR=pDateTime->year;
	RTC_ALDOW=pDateTime->DOW;
	RTC_ALDOY=pDateTime->DOY;

	RTC_ALHOUR = pDateTime->hour;
	RTC_ALMIN = pDateTime->minute;
	RTC_ALSEC = pDateTime->second;

	return 0;
}


/*************************************************************************
 * Function Name: RTC_ClearInt
 * Parameters: unsigned long IntType
 * Return: int 
 *             	0: sucess
 *			1: fail
 *
 * Description: Clear RTC interrupt.
 *  
 *************************************************************************/
int RTC_ClearInt(unsigned long IntType)
{
	if (IntType<1 || IntType>3)
		return 1;

	RTC_ILR = (IntType & 0x3);
	return 0;
}


/*************************************************************************
 * Function Name: RTC_CheckIntType
 * Parameters: void
 * Return: unsigned long
 *			RTCIncrementInt(1) | RTCAlarmInt(2)
 *
 * Description: Get RTC interrupt Type.
 *  
 *************************************************************************/
unsigned long RTC_CheckIntType(void)
{
	return (RTC_ILR & 0x3);
}


/*************************************************************************
 * Function Name: FormatDate
 * Parameters: int Type
 *			LPC_Rtc_Date_t *pDate
 *			char *s
 *
 * Return: void 
 *
 * Description: Format the current date into an ASCII string according to the Type.
 *			Type = 1, "YYYY-MM-DD" (11 chars)
 *			Type = 2, "DOW Month DD, YYYY" (30 chars)
 *  
 *************************************************************************/
void FormatDate (int Type, LPC_Rtc_Date_t *pDate, char *s)
{
	lpc_uint16 year;
	lpc_uint8 month, day,DOW, DOY;
	char str[5];

	year = pDate->year;
	month = pDate->month;
	day = pDate->day;
	DOW = pDate->DOW;
	DOY = pDate->DOY;
	
	switch(Type)
	{
		case 1:
			strcpy(s, "YYYY-MM-DD");
			s[0] = year / 1000 + '0';
			year = year % 1000;
			s[1] = year / 100 + '0';
			year = year % 100;
			s[2] = year / 10 + '0';
			s[3] = year % 10 + '0';
			s[5] = month / 10 + '0';
			s[6] = month % 10 + '0';
			s[8] = day / 10 + '0';
			s[9] = day % 10 + '0';
			break;

		case 2:
			strcpy(s, RTC_DOWTbl[DOW]);
			strcat(s, RTC_MonthTbl[month]);
			if (day < 10)
			{
				str[0] = day + '0';
				str[1] = 0;
			}
			else
			{
				str[0] = day / 10 + '0';
				str[1] = day % 10 + '0';
				str[2] = 0;
			}
			strcat(s, str);
			strcat(s, ", ");
			itoa(year, str, 10);
			strcat(s, str);
			break;
			
		default:
			strcpy(s,"?");
			break;
			
	}

	return;
}


/*************************************************************************
 * Function Name: FormatTime
 * Parameters: int Type
 *			LPC_Rtc_Time_t *pTime
 *			char *s
 *
 * Return: void 
 *
 * Description: Format the current time into an ASCII string according to the Type.
 *			Type = 1, "HH:MM:SS" (9 chars)
 *			Type = 2, "HH:MM:SS AM" (13 chars)
 *  
 *************************************************************************/
void FormatTime (int Type, LPC_Rtc_Time_t *pTime, char *s)
{
	lpc_uint8 hour, minute, second;

	hour = pTime->hour;
	minute = pTime->minute;
	second = pTime->second;
	
	switch(Type)
	{
		case 1:
			strcpy(s, "HH:MM:SS");
			s[0] = hour / 10 + '0';
			s[1] = hour % 10 + '0';
			s[3] = minute / 10 + '0';
			s[4] = minute % 10 + '0';
			s[6] = second / 10 + '0';
			s[7] = second % 10 + '0';
			break;

		case 2:
			strcpy(s, "HH:MM:SS AM");
			s[9] = (hour>=12) ? 'P' : 'A';
			if (hour>12)
				hour = hour -12;	
			
			s[0] = hour / 10 + '0';
			s[1] = hour % 10 + '0';
			s[3] = minute / 10 + '0';
			s[4] = minute % 10 + '0';
			s[6] = second / 10 + '0';
			s[7] = second % 10 + '0';
			break;
			
		default:
			strcpy(s,"?");
			break;
			
	}

	return;
}


/*************************************************************************
 * Function Name: FormatDateTime
 * Parameters: int Type
 *			LPC_Rtc_DateTime_t *pDateTime
 *			char *s
 *
 * Return: void 
 *
 * Description: Format the current date and time into an ASCII string according to the Type.
 *			Type = 1, "YYYY-MM-DD HH:MM:SS" (18 chars)
 *  
 *************************************************************************/
void FormatDateTime (int Type, LPC_Rtc_DateTime_t *pDateTime, char *s)
{
	lpc_uint16 year;
	lpc_uint8 month, day, DOW, DOY;
	lpc_uint8 hour, minute, second;

	year = pDateTime->year;
	month = pDateTime->month;
	day = pDateTime->day;
	DOW = pDateTime->DOW;
	DOY = pDateTime->DOY;
	
	hour = pDateTime->hour;
	minute = pDateTime->minute;
	second = pDateTime->second;
	
	switch(Type)
	{
		case 1:
			strcpy(s, "YYYY-MM-DD HH:MM:SS");
			s[0] = year / 1000 + '0';
			year = year % 1000;
			s[1] = year / 100 + '0';
			year = year % 100;
			s[2] = year / 10 + '0';
			s[3] = year % 10 + '0';
			s[5] = month / 10 + '0';
			s[6] = month % 10 + '0';
			s[8] = day / 10 + '0';
			s[9] = day % 10 + '0';
			
			s[11] = hour / 10 + '0';
			s[12] = hour % 10 + '0';
			s[14] = minute / 10 + '0';
			s[15] = minute % 10 + '0';
			s[17] = second / 10 + '0';
			s[18] = second % 10 + '0';
			break;

		default:
			strcpy(s,"?");
			break;
	}

	return;
}


⌨️ 快捷键说明

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