void configureRTC()
{
    RtccInit();
    while (RtccGetClkStat() != RTCC_CLK_ON);
    //printf("RTCC OK\r\n");

    // set time and date
    // time is MSb: hour, min, sec, rsvd. date is MSb: year, mon, mday, wday.
    // please note that the rsvd field has to be 0 in the time field!
    // Time is in Hex!
    RtccOpen(0x17040000, 0x08100604, 0);

    // set the RTCC priority in the INT controller
    INTSetVectorPriority(INT_RTCC_VECTOR, INT_PRIORITY_LEVEL_5);
    // set the RTCC sub-priority in the INT controller
    INTSetVectorSubPriority(INT_RTCC_VECTOR, INT_SUB_PRIORITY_LEVEL_1);
    // enable the RTCC event interrupts in the INT controller.
    INTEnable(INT_RTCC, INT_ENABLED);

    // enable alaram or endless alaram -
    // it allows the alarm rpt to move back to the beginning
    //RtccChimeDisable(); - this is now changeable
    // how much repats - 0 means run the alarm only once
    //RtccSetAlarmRptCount(0);
    //the above means once we have alarm interrupt the alarm will be disabled

    // used for marching (i.e. window) when cpmparing
    RtccSetAlarmRpt(RTCC_RPT_MON);
}
//************************************************************************
void init()
{

#ifdef _ENABLE_PIC_RTC_
	// Configure the device for maximum performance but do not change the PBDIV
	// Given the options, this function will change the flash wait states, RAM
	// wait state and enable prefetch cache but will not change the PBDIV.
	// The PBDIV value is already set via the pragma FPBDIV option above..
	__PIC32_pbClk	=	SYSTEMConfig(F_CPU, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
#else
	__PIC32_pbClk	=	SYSTEMConfigPerformance(F_CPU);
#endif


	OpenCoreTimer(CORE_TICK_RATE);

	// set up the core timer interrupt with a prioirty of 2 and zero sub-priority
	mConfigIntCoreTimer((CT_INT_ON | CT_INT_PRIOR_2 | CT_INT_SUB_PRIOR_0));

	// enable multi-vector interrupts
	INTEnableSystemMultiVectoredInt();


#ifdef _ENABLE_PIC_RTC_
	RtccInit();									// init the RTCC
//	while(RtccGetClkStat() != RTCC_CLK_ON);		// wait for the SOSC to be actually running and RTCC to have its clock source
												// could wait here at most 32ms

	delay(50);
	// time is MSb: hour, min, sec, rsvd. date is MSb: year, mon, mday, wday.
	RtccOpen(0x10073000, 0x11010901, 0);
	RtccSetTimeDate(0x10073000, 0x10101701);
	// please note that the rsvd field has to be 0 in the time field!
#endif


	//*	as per [email protected], Jan 7, 2011
	//*	Disable the JTAG interface.
	DDPCONbits.JTAGEN	=	0;


#if defined (_BOARD_MEGA_)
	//*	Turn Secondary oscillator off
	//*	this is only needed on the mega board because the mega uses secondary ocsilator pins
	//*	as general I/O
	{
	unsigned int dma_status;
	unsigned int int_status;
	
		mSYSTEMUnlock(int_status, dma_status);

		OSCCONCLR	=	_OSCCON_SOSCEN_MASK;


		mSYSTEMLock(int_status, dma_status);
	}
	
#endif

}
void init_config_RTCC(void){
    RtccInit();  
}