Пример #1
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* Initialize and configure RTC */
	RTC_Init(LPC_RTC);

	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);

	/* Set alarm time = 5s.
	 * So, after each 5s, RTC will generate and wake-up system
	 * out of Deep PowerDown mode.
	 */
	RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 5);

	RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, DISABLE);
	/* Set the AMR for 5s match alarm interrupt */
	RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
	RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM);

	_DBG_("Press '1' to enter system in Deep PowerDown mode");
	while(_DG !='1');

	RTC_Cmd(LPC_RTC, ENABLE);
	NVIC_EnableIRQ(RTC_IRQn);

	_DBG_("Enter Deep PowerDown mode...");
	_DBG_("Wait 5s, RTC will wake-up system...\n\r");

	// Enter target power down mode
	CLKPWR_DeepPowerDown();

	while(1);
	return 1;
}
Пример #2
0
static void init_RTC() 
{	
		/* Enable GPIO register interface clock                                     */
		LPC_CCU1->CLK_M4_GPIO_CFG     |= 1;
		while (!(LPC_CCU1->CLK_M4_GPIO_STAT   & 1)) ;
	
    /* RTC Block section ------------------------------------------------------ */
    /* Init RTC module */
    RTC_Init(LPC_RTC);

    /* Set ALARM time for second */
    RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 30);

    /* Set the AMR for 30s match alarm interrupt */
    RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);

    /* Set the CIIR for minute counter interrupt*/
    RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_MINUTE, ENABLE);

    /* Enable rtc (starts increase the tick counter and second counter register) */
    RTC_Cmd(LPC_RTC, ENABLE);
				
}
/*********************************************************************//**
 * @brief		c_entry: Main RTC program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	RTC_TIME_Type RTCFullTime;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* RTC Block section ------------------------------------------------------ */
	// Init RTC module
	RTC_Init(LPC_RTC);

    /* Disable RTC interrupt */
    NVIC_DisableIRQ(RTC_IRQn);
    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(RTC_IRQn, ((0x01<<3)|0x01));

	/* Enable rtc (starts increase the tick counter and second counter register) */
	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);
	RTC_CalibCounterCmd(LPC_RTC, DISABLE);

	/* Set current time for RTC */
	// Current time is 8:00:00PM, 2009-04-24
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 20);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 4);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2009);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 24);

	/* Set ALARM time for second */
	RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 10);

	// Get and print current time
	RTC_GetFullTime (LPC_RTC, &RTCFullTime);
	_DBG( "Current time set to: ");
	_DBD((RTCFullTime.HOUR)); _DBG (":");
	_DBD ((RTCFullTime.MIN)); _DBG (":");
	_DBD ((RTCFullTime.SEC)); _DBG("  ");
	_DBD ((RTCFullTime.DOM)); _DBG("/");
	_DBD ((RTCFullTime.MONTH)); _DBG("/");
	_DBD16 ((RTCFullTime.YEAR)); _DBG_("");

	_DBG("Second ALARM set to ");
	_DBD (RTC_GetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND));
	_DBG_("s");

	/* Set the CIIR for second counter interrupt*/
	RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
	/* Set the AMR for 10s match alarm interrupt */
	RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);

    /* Enable RTC interrupt */
    NVIC_EnableIRQ(RTC_IRQn);

    /* Loop forever */
    while(1);
    return 1;
}