Project details: (though I'm more interested in theoretical answers)
- MCU: PIC18F66K22
- IDE: MPLAB X IDE
- Programmer: PICKit 3
- Compiler: C18
- Project: Real Time Calendar Clock
I've started on getting the intern RTCC from my PIC to work. I find that there are little tutorials on this subject and none who are theoretical or withouth all too many (microcontroller specific) technical details. The datasheet, which is specific for my microcontroller, on the other hand, seems to lack information (not sure if it's common knowledge I'm missing?)
How do I set up the Clock/external Crystal and RTCC?
- Do I have to set TRIS (Tristate/Datadirection) registers for the Crystal pins?
- Do I have to set the input of the Crystal high for it in order to start oscillating? (or a short pulse or something?)
Is the part below the right configuration?
#pragma config RTCOSC = SOSCREF // RTCC Clock Select (RTCC uses SOSC)
RTSECSEL (RTCC Seconds Clock Output Select) should be set to (10)?:
RTCC source clock is selected for the RTCC pin (the pin can be LF-INTOSC or SOSC, depending on the RTCOSC (CONFIG3L<1>) bit setting)
? I have another peripheral connected to the RTCC pin, will this become an output for theClock Seconds
? (Somehow confusing, but I think the Clock Output Select can be used to select the input? :#)
For those who don't like theory
The test code
Maybe a quick error is spotted here. The assembly thing is from the datasheet.
(datasheet: "For the RTCWREN bit to be set, there is only one instruction cycle time window allowed between the 55h/AA sequence and the setting of RTCWREN.")
Also #pragma config RTCOSC = SOSCREF // RTCC Clock Select (RTCC uses SOSC)
And TRISC registers are set.
_asm
movlw 0x55
movwf EECON2,0
movlw 0xAA
movwf EECON2,0
bsf RTCCFG,5,0
_endasm
RtccInitClock();
PADCFG1bits.RTSECSEL1 = 1;
PADCFG1bits.RTSECSEL0 = 0;
RTCCFGbits.RTCEN = 1;
RTCCFGbits.RTCWREN = 0;