Can anyone tell me how to make the RTCC in the pic32 chips operate correctly?
The code i have is here but it is not working.
Any help appreciated.
Code: Select all
program RTCC;
var Seconds_bit : sbit at LATD6_bit;
var time : dword;
var date : dword;
begin
AD1PCFG := 0xFFFF; // Initialize AN pins as digital
TRISG := 0; // Set PORTD as output
LATG := 0; // Clear PORTD
TRISD := 0;
LatD := 0;
// RTCC registers unlock procedure
SYSKEY := 0xAA996655; // Write first unlock key to SYSKEY
SYSKEY := 0x556699AA; // Write second unlock key to SYSKEY
RTCWREN_bit := 1; // RTC Value registers can be written to by the user
OSCCON.SOSCEN := 1; // OSCCON.SOSCEN = 1;
// enable secondary oscillator
SOSCEN_bit := 1;
OSCCONSET := 2;
while( not SOSCRDY_bit) do// wait for secondary oscillator to stabilize
;
RTCOE_bit := 1; // RTCC pin clock output enabled
RTSECSEL_bit := 1; // RTCC Seconds Clock is selected for the RTCC pin
ON__RTCCON_bit:= 1; // Turn on the RTCC module
while(not (RTCCON and 0x40)) do // Wait for clock to be turned on
;
LATA := 0; // Clear PORTD
while(1) do LATD.2 := RTCTIME.B8; // Toggle Seconds_bit every second
end.