在线时间445 小时
UID2011467
注册时间2013-5-17
NXP金币0
该用户从未签到
金牌会员
 
- 积分
- 5781
- 最后登录
- 1970-1-1
|
发表于 2015-9-6 10:28:57
|
显示全部楼层
本帖最后由 FSL_TICS_ZP 于 2015-9-6 10:29 编辑
我这边在FRDM-KL05Z上试过啊,也是可以使用的,我把代码贴上来,你对比一下rtc.c
- /********************************************************************/
- /*
- * Initialize the RTC
- *
- *
- * Parameters:
- * seconds Start value of seconds register
- * alarm Time in seconds of first alarm. Set to 0xFFFFFFFF to effectively disable alarm
- * c_interval Interval at which to apply time compensation can range from 1 second (0x0) to 256 (0xFF)
- * c_value Compensation value ranges from -127 32kHz cycles to +128 32 kHz cycles
- * 80h Time prescaler register overflows every 32896 clock cycles.
- * FFh Time prescaler register overflows every 32769 clock cycles.
- * 00h Time prescaler register overflows every 32768 clock cycles.
- * 01h Time prescaler register overflows every 32767 clock cycles.
- * 7Fh Time prescaler register overflows every 32641 clock cycles.
- * rtc_irqc interrupt configuration
- * |__RTC_INT_DIS -disable interrupt
- * |__RTC_INT_INVALID -Time Invaild Interrupt
- * |__RTC_INT_OVERFLOW -Time Overflow Interrupt
- * |__RTC_INT_ALARM -Time Alarm Interrupt
- * isr_func point to interrupt service function
- */
- uint8 RTC_Init(uint32 seconds, uint32 alarm, uint8 c_interval, uint8 c_value,uint8 rtc_irqc, RTC_ISR_CALLBACK isr_func)
- {
- int i;
-
- SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;
- SIM_SOPT1 = SIM_SOPT1_OSC32KSEL(0);
- disable_irq(20);
- disable_irq(21);
- RTC_CR = RTC_CR_SWR_MASK;
- RTC_CR &= ~RTC_CR_SWR_MASK;
- if (RTC_SR & RTC_SR_TIF_MASK){
- RTC_TSR = 0x00000000; // this action clears the TIF
- printf("RTC Invalid flag was set - Write to TSR done to clears RTC_SR = %#02X \n", (RTC_SR) ) ;
- }
- /*Set time compensation parameters*/
- RTC_TCR = RTC_TCR_CIR(c_interval) | RTC_TCR_TCR(c_value);
- /*Enable the oscillator*/
- RTC_CR |= RTC_CR_OSCE_MASK|RTC_CR_SC16P_MASK;
-
- /*Wait to all the 32 kHz to stabilize, refer to the crystal startup time in the crystal datasheet*/
- for(i=0;i<0x600000;i++);
-
- RTC_SR &= ~RTC_SR_TCE_MASK;
-
- if(rtc_irqc)
- {
- RTC_IER = (rtc_irqc & 0x07);
-
- RTC_ISR[0]=isr_func;
-
- enable_irq(20);
- }
- // RTC_CR |RTC_CR_SC16P_MASK;
- RTC_TSR = seconds;
- RTC_TAR = alarm;
- RTC_SR |= RTC_SR_TCE_MASK;
-
- return 1;
- }
- /*
- RTC interrupt service function
- */
- void rtc_isr(void)
- {
- if((RTC_SR & RTC_SR_TIF_MASK)== 0x01)
- {
-
- RTC_ISR[0]();
- //clear flag
- RTC_SR |= RTC_SR_TIF_MASK;
-
- }
- else if((RTC_SR & RTC_SR_TOF_MASK) == 0x02)
- {
-
- RTC_ISR[0]();
- RTC_SR |= RTC_SR_TOF_MASK;
- }
- else if((RTC_SR & RTC_SR_TAF_MASK) == 0x04)
- {
- RTC_ISR[0]();
- RTC_SR |= RTC_SR_TAF_MASK;
- printf("\nInterrupt happen .\n");
- }
- }
复制代码
rtc.h
- /*
- * File: rtc.h
- * Purpose: Provide common rtc functions
- *
- * Notes:
- */
- #include "common.h"
- #ifndef __RTC_H__
- #define __RTC_H__
- void rtc_reset( void );
- #define RTC_INT_DIS 0
- #define RTC_INT_INVALID 1
- #define RTC_INT_OVERFLOW 2
- #define RTC_INT_ALARM 4
- typedef void (*RTC_ISR_CALLBACK)(void);
- uint8 RTC_Init(uint32,uint32,uint8,uint8,uint8,RTC_ISR_CALLBACK);
- #endif /* __RTC_H__ */
复制代码
|
|