Exemplo n.º 1
0
void Timerx_Init(GPTM_TypeDef* GPTMx,u16 arr,u16 psc)
{
   GPTM_TimeBaseInitTypeDef  GPTM_TimeBaseStructure;
	//NVIC_InitTypeDef NVIC_InitStructure;
	Assert_Param(IS_GPTM(GPTMx));
		if(GPTMx==GPTM0)
	{
		CKCU_APBPerip1ClockConfig(CKCU_APBEN1_GPTM0,ENABLE);
	}
	else if(GPTMx==GPTM1)
	{
		CKCU_APBPerip1ClockConfig(CKCU_APBEN1_GPTM1,ENABLE);
	}
	
	GPTM_DeInit(GPTMx);

	GPTM_TimeBaseStructure.CounterReload = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值	 计数到5000为500ms
	GPTM_TimeBaseStructure.Prescaler =(7200-1); //设置用来作为TIMx时钟频率除数的预分频值  10Khz的计数频率  
	GPTM_TimeBaseStructure.PSCReloadTime = GPTM_PSC_RLD_UPDATE;//无事件发生,等待下一次重载//TIM 中断源
	GPTM_TimeBaseStructure.CounterMode = GPTM_CNT_MODE_UP;  //TIM向上计数模式
	GPTM_TimeBaseInit(GPTMx, &GPTM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
 
	/* TIM IT enable */
	GPTM_IntConfig(  //使能或者失能指定的TIM中断
		GPTMx, //TIMx
		TIM_IT_Update  |  //TIM 中断源
		TIM_IT_Trigger,   //TIM 触发中断源 
		ENABLE  //使能
		);
		/* Enable the TIMx global Interrupt */

	if(GPTMx==GPTM0)
	{
		NVIC_SetPriority(GPTM0_IRQn,NVIC_EncodePriority(5,0,3));
		NVIC_EnableIRQ(GPTM0_IRQn);
		GPTM_IntConfig(GPTM0,GPTM_INT_UEV,ENABLE);
	}
	else
	if(GPTMx==GPTM1)
	{
		NVIC_SetPriority(GPTM1_IRQn,NVIC_EncodePriority(5,0,3));
		NVIC_EnableIRQ(GPTM1_IRQn);
		GPTM_IntConfig(GPTM1,GPTM_INT_UEV,ENABLE);
	}		
		/*
	NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;  //TIM3中断
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //先占优先级0级
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  //从优先级3级
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
	NVIC_Init(&NVIC_InitStructure);  //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
*/
	GPTM_Cmd(GPTMx, ENABLE);  //使能TIMx外设
							 
}
Exemplo n.º 2
0
/*********************************************************************************************************//**
  * @brief  Configures the system clocks.
  * @brief  None
  ***********************************************************************************************************/
void CKCU_Configuration(void)
{
  /*------------------------------------------------------------------------------------------------------*/
  /* APB Peripheral 1 Enable                                                                              */
  /* - CKCU_APBEN1_WDT,  CKCU_APBEN1_RTC,  CKCU_APBEN1_GPTM0, CKCU_APBEN1_GPTM1                           */
  /* - CKCU_APBEN1_OPA0, CKCU_APBEN1_OPA1, CKCU_APBEN1_ADC                                                */
  /*------------------------------------------------------------------------------------------------------*/
  CKCU_APBPerip1ClockConfig(CKCU_APBEN1_WDT, ENABLE);
}
Exemplo n.º 3
0
/*********************************************************************************************************
  * @brief  Calendar program.
  * @retval None
  ********************************************************************************************************/
void Calendar(void)
{
    CKCU_APBPerip1ClockConfig(CKCU_APBEN1_RTC, ENABLE);
    if(PWRCU_CheckReadyAccessed() != PWRCU_OK)
    {
        while(1);
    }

    /* Init LED3 and USART */
    LED_Configuration();
    USART_Configuration();

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

    /* Check if the Power On Reset flag is set */
    if(PWRCU_GetFlagStatus() == PWRCU_FLAG_BAKPOR)
    {
        printf("\r\n\n Power On Reset occurred....");
    }

    if(PWRCU_ReadBackupRegister(PWRCU_BAKREG_0) != 0x5A5A)
    {
        u32 wInitTime = 0;
        /* Backup data register value is not correct or not yet programmed (when
           the first time the program is executed) */

        printf("\r\n\n RTC not yet configured....");

        /* RTC Configuration */
        RTC_Configuration();

        printf("\r\n RTC configured....");

        /* Adjust time by values entred by the user on the hyperterminal,
           Then store the init time to PWRCU_BAKREG_1. */
        wInitTime = Time_Regulate() ;
        PWRCU_WriteBackupRegister(PWRCU_BAKREG_1, wInitTime);

        /* Reset RTC Counter when Time is 23:59:59 */
        RTC_SetCompare(86400 - wInitTime) ;

        PWRCU_WriteBackupRegister(PWRCU_BAKREG_0, 0x5A5A);
        /* Enable RTC */
        RTC_Cmd(ENABLE) ;
    }
    else
    {
        printf("\r\n No need to configure RTC....");
    }

    /* Display current time in infinite loop */
    printf("\n\r");

    while (1)
    {
        /* If 1s has paased */
        if(gwTimeDisplay == 1)
        {
            /* Display current time.
               Current time is sum of the RTC counter value and the init time(stored in PWRCU_BAKREG_1 register).
               The init time (PWRCU_BAKREG_1 register) will be clear if the RTC Match flag(CMFLAG) is set.
               Refer to RTC_IRQHandler. */
            Time_Display(RTC_GetCounter() + PWRCU_ReadBackupRegister(PWRCU_BAKREG_1));
            gwTimeDisplay = 0;
        }
    }
}