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

📄 rtc.c.bak

📁 uCos应用
💻 BAK
字号:
#include <includes.h>

TIME_FORMAT time;
TIME_COUNTER time_second;	 
unsigned char Start_Time = 0;

void RTC_int(void)
{
                   
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);		// 使能定时器0外设。

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);		// 使能GPIO D口外设。

    IntMasterEnable();									// 处理器使能。

	GPIOPinTypeTimer(GPIO_PORTD_BASE ,CCP0);			//设置PD5为32K输入口
    
	TimerConfigure(TIMER1_BASE, TIMER_CFG_32_RTC|TIMER_CFG_32_BIT_PER);   
														// 设置RTC模式。
    TimerMatchSet(TIMER1_BASE,TIMER_A,2);				// 设置RTC的匹配值
	TimerLoadSet(TIMER1_BASE, TIMER_A, 1);
	TimerRTCEnable(TIMER1_BASE);						//使能RTC计数
	
	TimerIntEnable(TIMER1_BASE,TIMER_RTC_MATCH);		//使RTC中断

    TimerEnable(TIMER1_BASE, TIMER_A);		 //	RTC模式使能
	
	IntEnable(INT_TIMER1A);					// 使能中断

}

static unsigned char leap_month[12]={31,29,31,30,31,30,31,31,30,31,30,31};
static unsigned char non_leap_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void Data_Time(void)
{
	if(time.second == 60)	// 实现时钟的进制转换
	{
	 	time.second = 0;
		if(time.minute == 59)
		{
			time.minute = 0;
			if(time.hour == 23)
			{
				time.hour = 0;
				if(time.year/400!=0)		//非闰年
				{
					if(time.date == non_leap_month[time.month-1])
					{
						time.date = 1;
						time.month ++;
					}
					else
						time.date++;
				}
				else						//闰年
				{
					if(time.date == leap_month[time.month-1])
					{
						time.date = 1;
						if(time.month == 12)
						{
							time.month = 1;
							time.year++;
						}
						else
							time.month ++;
					}
					else
						time.date++;
				}
			}
			else
				time.hour ++;				
		}
		else
			time.minute ++;
	}
}

void  Timer1A_ISR(void)
{
	TimerIntClear(TIMER1_BASE, TIMER_RTC_MATCH);
	TimerLoadSet(TIMER1_BASE, TIMER_A, 1);
	TimerEnable(TIMER1_BASE, TIMER_A);
	time.second++;
	Data_Time();
	if( Start_Time ==1)
	{
		time_second.second++;
	}
}

⌨️ 快捷键说明

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