完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
好啊。首先,我有RTFM在任何人说我应该。我很可能错过了一些东西,但我确实读过了。我正在努力让RTC工作,但没有成功。我的芯片时钟从内部振荡器在8MHz。我有一个32.768 kHz的晶体在T1输入在引脚11和12与18PF上限到地面上的两条腿。我已经验证了使用PICtiT3,我正在修改RTCCFG寄存器,虽然这样做的方法是绝对的疯子在我看来。我只是不知道还有什么可以让它发挥作用。也许我只是不明白这件事该怎么做。这就是我要做的。我总是很简单。我只希望RTC输出(引脚22)给我一个1秒的周期脉冲。我尝试过和没有启用警报,有和没有TMR1启用,有和没有高功率振荡器启用,我不知道还有什么要做。那么,有人能看一下这个,告诉我哪里搞砸了吗?下面是代码:
以上来自于百度翻译 以下为原文 OK. First, I have RTFM before anyone says I should. It's quite possible I missed something, but I did read it. I am trying to get the RTC to work and am not having any success. I have the chip clocked from the internal oscillator at 8MHz. I have a 32.768 KHz crystal on the T1 inputs at pins 11 and 12 with 18pF caps to ground on both legs. I have verified using Pickit3 that I am modifying the RTCCFG register, although the method for doing so is absolutely bonkers in my opinion. I just don't know what else to try to get it to work. Perhaps I just don't get what this thing is really supposed to be doing. Here's what I am TRYING to do. I always start simple. I just want the RTC output (pin 22) to give me a 1 second periodic pulse. I have tried with and without the alARM enabled, with and without tmr1 enabled, with and without hi-power oscillator enabled, I don't know what else to do. So will someone please look at this and tell me where I screwed up? Here is the code: // CONFIG1L #pragma config WDTEN = OFF // Watchdog Timer (Disabled - Controlled by SWDTEN bit) #pragma config STVREN = OFF // Stack Overflow/Underflow Reset (Disabled) #pragma config XINST = OFF // Extended Instruction Set (Disabled) // CONFIG1H #pragma config CP0 = OFF // Code Protect (Program memory is not code-protected) // CONFIG2L #pragma config OSC = INTOSCPLL // Oscillator (INTOSCPLL) #pragma config T1DIG = ON // T1OSCEN Enforcement (Secondary Oscillator clock source may be selected) #pragma config LPT1OSC = ON // Low-Power Timer1 Oscillator (Low-power operation) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor (Disabled) #pragma config IESO = OFF // Internal External Oscillator Switch Over Mode (Disabled) // CONFIG2H #pragma config WDTPS = 32768 // Watchdog Postscaler (1:32768) // CONFIG3L #pragma config DSWDTOSC = INTOSCREF// DSWDT Clock Select (DSWDT uses INTRC) #pragma config RTCOSC = T1OSCREF// RTCC Clock Select (RTCC uses T1OSC/T1CKI) #pragma config DSBOREN = OFF // Deep Sleep BOR (Disabled) #pragma config DSWDTEN = OFF // Deep Sleep Watchdog Timer (Disabled) #pragma config DSWDTPS = G2 // Deep Sleep Watchdog Postscaler (1:2,147,483,648 (25.7 days)) // CONFIG3H #pragma config IOL1WAY = OFF // IOLOCK One-Way Set Enable bit (The IOLOCK bit (PPSCON<0>) can be set and cleared as needed) #pragma config MSSP7B_EN = MSK7 // MSSP address masking (7 Bit address masking mode) // CONFIG4L #pragma config WPFP = PAGE_15 // Write/Erase Protect Page Start/End Location (Write Protect Program Flash Page 15) #pragma config WPEND = PAGE_WPFP// Write/Erase Protect Region Select (valid when WPDIS = 0) (Page WPFP<5:0> through Configuration Words erase/write protected) #pragma config WPCFG = OFF // Write/Erase Protect Configuration Region (Configuration Words page not erase/write-protected) // CONFIG4H #pragma config WPDIS = OFF // Write Protect Disable bit (WPFP<5:0>/WPEND region ignored) #include #define ON 1 #define OFF 0 //Global Variables volatile union { struct { unsigned f0:1; unsigned f1:1; unsigned f2:1; unsigned f3:1; unsigned f4:1; unsigned f5:1; unsigned f6:1; unsigned f7:1; }; struct { unsigned tmr3Int:1; unsigned :7; }; } FLAGbits; //void T1_Init() //{ // T1CON = 0x8d; // external source, 1:1, enabled // PIE1bits.TMR1IE = 1; // tmr1 int enabled // IPR1bits.TMR1IP = 1; // tmr1 int hi priority //} void T3_Init() { T3CON = 0x30; // 1:8 = 262mS int IPR2bits.TMR3IP = 1; // tmr1 hi priority PIE2bits.TMR3IE = 1; // tmr1 int enabled } void RTC_Init() { //Dumbest thing ever! This sequence needs to be performed to set the //rtc write enable bit. Won't work with inline assembler or anything else //I tried. Code is C version of what is listed in the data sheet for the //under section 17.2.7 Write Lock. BSR = 0x0f; EECON2 = 0x55; EECON2 = 0xaa; RTCCFG = 0x20; //Set date/time to Oct. 12, 2014 @ 9:45:30 AM - not sure if this is necessary RTCCFGbits.RTCPTR0 = 1; RTCCFGbits.RTCPTR1 = 1; RTCVALL = 0x14; // year = 14 RTCVALH = 0; // automatic decrement to ptr = 2 RTCVALL = 0x12; // day = 12 RTCVALH = 0x10; // month = 10 - automatic decrement ptr to 1 RTCVALL = 0x09; // hrs = 9 RTCVALH = 0x00; // weekday = sunday - automatic decrement ptr to 0 RTCVALL = 0x30; // sec = 30 RTCVALH = 0x45; // min = 45 RTCCFGbits.RTCOE = 1; // rtc output enabled PADCFG1 = 0x02; RTCCFGbits.RTCEN = 1; // rtc enabled } void main(void) { OSCCON = 0x70; // Internal 8MHz //OSCTUNE = 0x40; // PLL enabled RCONbits.IPEN = 1; // int priority enabled INTCONbits.GIE = 1; // global ints enabled INTCONbits.PEIE = 1; // peripheral ints enabled ANCON0 = 0xff; // all digital ANCON1 = 0x0f; LATCbits.LATC3 = 0; // C3 low TRISCbits.TRISC3 = 0; // C3 output T3_Init(); T3CONbits.TMR3ON = ON; RTC_Init(); while(1) { if(FLAGbits.tmr3Int) { FLAGbits.tmr3Int = 0; if(LATCbits.LC3) LATCbits.LC3 = 0; // toggle C3 else LATCbits.LC3 = 1; } } return; } /************************High priority ISR ********************************/ void interrupt high_priority high_isr (void) { //isr for high priority interrupts goes here if(PIR2bits.TMR3IF) // tmr3 interrupt { PIR2bits.TMR3IF = 0; FLAGbits.tmr3Int = 1; } if(PIR1bits.TMR1IF) // tmr1 interrupt - 1 second { PIR1bits.TMR1IF = 0; if(LATCbits.LATC4) LATCbits.LATC4 = 0; else LATCbits.LATC4 = 1; } // if(PIR3bits.RTCCIF) // { // PIR3bits.RTCCIF = 0; // if(LATCbits.LATC4) LATCbits.LATC4 = 0; // else LATCbits.LATC4 = 1; // } } |
|
相关推荐
2个回答
|
|
|
您好,我可能认为RTCC不工作的2个主要原因:晶体不起作用,晶体断裂,晶体质量不正确,连接不好,连接短路,错误引脚和类似的不太可能的错误。定时器1振荡器的低功率设置是非常低的驱动电平,并且可能是挑剔的。在晶体质量和连接上,您可以尝试使用γ-PrimaMac配置LPT1OSC=OFF为PrimaPrimaMatrg LPT1OSC1=,它仍然是一个具有增益控制的低功耗晶体驱动模式。第二个陷阱是振荡器不启用。UT…试着检查定时器1是否会在启用定时器1振荡器的情况下运行:或者尝试您已经拥有的代码作为注释。如果在调试器中运行和停止程序,如果TMR1L或TMR1H寄存器发生更改,请与调试器进行检查。不要进入调试器,在任何事情之前都会有很多步骤。如果Time1正在计数,晶体振荡器正在工作。问候,Mysil
以上来自于百度翻译 以下为原文 Hi, I may think of 2 main reasons for RTCC not working: Crystal not functional, crystal broken, crystal quality not correct, connection not good, short circuit in connection, wrong pin and similar unlikely mistakes. Low power setting for the Timer 1 oscillator is very low drive level, and may be picky on crystal quality and connection. You may try with #pragma config LPT1OSC = OFF or #pragma config LPT1OSC = 1 instead, it is still a Low power crystal drive mode with gain control. The second pitfall is Oscillator not Enabled. There is specified #pragma config T1DIG = ON in the code shown, so seem good, but ... Try to check if Timer 1 will run with Timer 1 Oscillator enabled: T1CONbits.T1OSCEN = 1; T1CONbits.TMR1CS = 2; T1CONbits.TMR1ON = 1; T1GCONbits.TMR1GE = 0; Or try the code you already have as comments. Then check with debugger if TMR1L or TMR1H registers change when you run and stop program in debugger. Do not step in the debugger, there will be an awful lot of steps before anything happen. If Timer1 is counting, crystal oscillator is working. Regards, Mysil |
|
|
|
|
|
嗯,这是可行的,虽然我不太清楚为什么。我离开了LPT1OSC并关闭了T1GID。我启用了Time1并能够看到它的变化状态。在一点上,我有一个接近32 kHz的输出从RTCC引脚。还不能解释。我不记得在那之后我改变了什么,但是现在我有一个从RTC输出的1秒50%的占空比。谢谢你的帮助。
以上来自于百度翻译 以下为原文 Well, It's working, though I'm not really sure why. I left the LPT1OSC ON and turned off the T1DIG. I enabled Timer1 and was able to see it change states. At one point I had something close to a 32kHz output from the RTCC pin. Can't explain that yet. I don't remember what I changed after that, but I now have a 1 second 50% duty cycle output from the RTC. Thanks for the help. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 07:00 , Processed in 1.071238 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
504