ARM学习笔记--RTC编程(二)
RTC的寄存器比较简单,主要有时钟计数器寄存器包括秒SEC 分MIN 小时HOUR 日期(月)DOM 星期DOW 日期(年)DOY 月MONTH 年YEAR, 这些寄存器为R/W 可以从中读出具体的时间信息。其中的秒计数由1HZ时钟驱动。报警寄存器组中的值将和时间计数器寄存器中的值比较,如果所有为屏蔽的报警寄存器都与他们对应的时间计数器相匹配,那么将产生一次中断。报警屏蔽在报警屏蔽寄存器AMR中设置。中断设置在中断位置寄存器ILR中设置。RTC中断不仅可以在报警寄存器和时间计数器匹配时产生,我们也可以配置计数器增量中断寄存器CIIR,使计数器每增加1就产生一次中断。RTC的控制在时钟控制寄存器CCR中,我们可以使能或禁止时钟,以及复位等。
下面这段代码就是RTC寄存器结构体,里面包含了关于RTC的寄存器的一个列举:/*------------- Real-Time Clock (RTC) ----------------------------------------*/
typedef struct
{
__IO uint8_t ILR;
uint8_t RESERVED0[7];
__IO uint8_t CCR;
uint8_t RESERVED1[3];
__IO uint8_t CIIR;
uint8_t RESERVED2[3];
__IO uint8_t AMR;
uint8_t RESERVED3[3];
__I uint32_t CTIME0;
__I uint32_t CTIME1;
__I uint32_t CTIME2;
__IO uint8_t SEC;
uint8_t RESERVED4[3];
__IO uint8_t MIN;
uint8_t RESERVED5[3];
__IO uint8_t HOUR;
uint8_t RESERVED6[3];
__IO uint8_t DOM;
uint8_t RESERVED7[3];
__IO uint8_t DOW;
uint8_t RESERVED8[3];
__IO uint16_t DOY;
uint16_t RESERVED9;
__IO uint8_t MONTH;
uint8_t RESERVED10[3];
__IO uint16_t YEAR;
uint16_t RESERVED11;
__IO uint32_t CALIBRATION;
__IO uint32_t GPREG0;
__IO uint32_t GPREG1;
__IO uint32_t GPREG2;
__IO uint32_t GPREG3;
__IO uint32_t GPREG4;
__IO uint8_t RTC_AUXEN;
uint8_t RESERVED12[3];
__IO uint8_t RTC_AUX;
uint8_t RESERVED13[3];
__IO uint8_t ALSEC;
uint8_t RESERVED14[3];
__IO uint8_t ALMIN;
uint8_t RESERVED15[3];
__IO uint8_t ALHOUR;
uint8_t RESERVED16[3];
__IO uint8_t ALDOM;
uint8_t RESERVED17[3];
__IO uint8_t ALDOW;
uint8_t RESERVED18[3];
__IO uint16_t ALDOY;
uint16_t RESERVED19;
__IO uint8_t ALMON;
uint8_t RESERVED20[3];
__IO uint16_t ALYEAR;
uint16_t RESERVED21;
__IO uint32_t ERSTATUS;
__IO uint32_t ERCONTROL;
__IO uint32_t ERCOUNTERS;
uint32_t RESERVED22;
__IO uint32_t ERFIRSTSTAMP0;
__IO uint32_t ERFIRSTSTAMP1;
__IO uint32_t ERFIRSTSTAMP2;
uint32_t RESERVED23;
__IO uint32_t ERLASTSTAMP0;
__IO uint32_t ERLASTSTAMP1;
__IO uint32_t ERLASTSTAMP2;
} LPC_RTC_TypeDef;
void RTC_Init (LPC_RTC_TypeDef *RTCx)
{
/* Set up clock and power for RTC module */
CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, ENABLE); //开启RTC功能,配置寄存器PCONP
// Clear all register to be default
RTCx->ILR = 0x00; // 中断地址寄存器,增量中断、报警中断
RTCx->CCR = 0x00; // 时钟控制寄存器(控制使能、复位、是否校准)
RTCx->CIIR = 0x00;// 计数增量中断寄存器 (控制按秒或分等变化一次发生中断)
RTCx->AMR = 0xFF; // 报警中断寄存器
RTCx->CALIBRATION = 0x00; //校准寄存器,看时间走多长然后校准一次(1s或2s)
}
void RTC_ResetClockTickCounter(LPC_RTC_TypeDef *RTCx)
{
RTCx->CCR |= RTC_CCR_CTCRST;
RTCx->CCR &= (~RTC_CCR_CTCRST) & RTC_CCR_BITMASK; // RTC_CCR_BITMASK:1101
}
void RTC_Default_Set(void)
{
//Set current time
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);//参数:(LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t TimeValue)
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 30);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 11);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 31);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 8);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 12);
}
RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
/* Enable RTC interrupt */
NVIC_EnableIRQ(RTC_IRQn);中
ARMRTC编 相关文章:
- ARM学习笔记—RTC编程(一)(11-10)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)