我相信有一个硬件错误阻止它工作。当我在这里耽搁(比时钟的滴答多一点)时,它就起作用了。否则:不去。请注意,对于这个测试,我使用内部时钟(RTCCONBITS.RTCLKSELL=0B01),因为我想绝对地确定这个问题与SOSC或XTAL或其他无关。从PIC16F19156(同样的RTCC模块作为您的芯片)的结果,使用XC8版本1.44(在自由模式下):1:RTCCONN=0x212:RTCCONN=0x81,这表明设置了RTCEN(MSB),并且它开始计数。(TAA DAA)在我的测试中,我只检查了循环中的秒寄存器,当它从先前的读取中改变时,打印出了值。(当然,因为我的测试是使用内部时钟而不是晶体,它不准确,但它确实计数。)另一方面……当我评论延迟,我得到1:RTCCONN=0x212:RTCCONN=0x01,这表明RTCN位还没有被设置。(这不算数)注意到我已经测试过这足以相信它不是印刷品,RTCEN真的没有设置,除非我在RTCRWEN清除之前延迟。这种延迟似乎只有在设置或清除RTCEN后立即清除RTCWRN才是必要的。在RTCC中,我还没有看到其他位或其他寄存器的问题。注意,在RTCJTimeTeSe()函数的末尾,几乎肯定有一个类似的序列,因此,如果调用该函数,它可能最终会被设置为RTCEN。对于初学者,为什么不在初始化代码中注释对RTCJTimeSeTe()的调用并查看它是否可以启动?一个快速测试(而不是改变初始化代码和代码在RTCccTimeSeTee()中可能会在你的初始化代码之后放置类似的东西:我也建议如果有更多的困难,从内部振荡器开始,这样我们就不必再打扰你了。再说一遍,SOSC,水晶等等。如果它能工作,那么你可以挖得更深一点。哦,顺便说一下,我也会推迟尝试使用中断,直到你有基本的功能正在进行中。我们不知道你打算用中断做什么,我们看不到你的ISR,所以,我顺便提一下,我看了MCC第3版,检查了它的一些功能,它使用了来自lt,t.h & gt的TM结构,而不是你的TAMPSY-RTCC定义。你有没有什么理由决定自己滚动,或者你的MCC真的生成它们吗?我的意思是,我的MCC的RTCccStTimeTimes()和RTCPCGETTIMEN()函数对StuttTMbTeLink的指针进行操作:很难帮助别人通过遥控器调试(特别是当他们的代码的一部分来自MCC),因为我看不到所有的代码,但是在设置或清除之后延迟了。清除RTCWRN之前的GRTCEN似乎是必要的第一步。至少这是我的经历,戴夫
以上来自于百度翻译
以下为原文
I believe there is a hardware bug that prevents this from working. When I put in a delay here (a little more than the tick of the clock), it works. Otherwise: no go. Note that, for this test I am using the internal clock (RTCCONbits.RTCCLKSEL = 0b01) since I wanted to make absolutely sure the problem was not related to SOSC or XTAL or anything else.
printf("1: RTCCON = 0x%02Xn", RTCCON);
RTCCONbits.RTCEN = 1;
__delay_us(50);
RTCWREN = 0;
printf("2: RTCCON = 0x%02Xn", RTCCON);
Results from my PIC16F19156 (same RTCC module as your chip), using XC8 version 1.44 (in Free mode):
1: RTCCON = 0x21
2: RTCCON = 0x81
This shows that RTCEN (the m***) is set, and it starts counting. (Taa-daa)
For my test I just checked the seconds register in a loop and printed out the value when it changed from the previous reading. (Of course, since my test is using the internal clock rather than a crystal, it's not accurate, but it does count.)
On the other hand...
When I comment out the delay, I get
1: RTCCON = 0x21
2: RTCCON = 0x01
This shows that the RTCEN bit has not been set. (And it does not count.)
Note that I have tested this enough to believe that it's not an artifact of printing; RTCEN really doesn't get set unless I put in a delay before clearing
RTCWREN!
This delay seems to be necessary only after setting or clearing
RTCEN immediately before clearing
RTCWREN. I haven't seen any problems with other bits or other registers in the RTCC.
Note that there is almost surely a similar sequence at the end of the
RTCC_TimeSet() function, so, if you call that function it will probably end up with
RTCEN not set. For starters, why not comment out the call to
RTCC_TimeSet() in your initialization code and see if it can get started?
A quick test (instead of changing your initialization code and the code in
RTCC_TimeSet() might to put something like the following after your initialization code:
// Make dang sure it's enabled
RTCCONbits.RTCWREN = 1;
RTCCONbits.RTCEN = 1;
// For now, leave RTCWREN set so that you can begin testing.
I also suggest that if there are further difficulties, start with the internal oscillator so that we won't have to bother you again and again about SOSC, crystals, etc.
If it works then you can dig a little deeper.
Oh, and, by the way, I would also put off trying to use interrupts until you have the basic functionality underway. We don't know what the heck you intend to do with the interrupt, and we can't see your ISR, so:
//PIR8bits.RTCCIF = 0; // Clear the RTCC interrupt flag
//PIE8bits.RTCCIE = 1; //Enable RTCC interrupt
I will mention in passing that I looked at MCC version 3 to examine some of its functions, and it uses the
tm structure from
instead of your temps_RTCC definitions. Is there any reason you decided to roll your own, or did your MCC actually generate them? I mean, my MCC's RTCC_SetTIme() and RTCC_GetTime() functions operate on pointers to struct tm
Bottom line: It's hard to help someone debug by remote control (especially when part of their code "comes from MCC") since I can't see all of your code, but the thing about delaying after setting or clearing RTCEN before clearing RTCWREN seems to be a necessary first step. At least that's my experience.
Regards,
Dave