コード例 #1
0
ファイル: wkup.c プロジェクト: wugoukanle/smart_key
void Sys_Standby(void)
{
	stop_flag=1;
	  
// 	while(1)
// 	{
			NVIC_SystemLPConfig(NVIC_LP_SLEEPDEEP,ENABLE);	   
			RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);	//使能PWR和BKP外设时钟    
			PWR_WakeUpPinCmd(ENABLE);  //使能唤醒管脚功能

			//PWR_EnterSTANDBYMode();	  //进入待命(STANDBY)模式 	
			PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); 			//在停机模式时,程序停在这个函数中
			//PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); 			//在停机模式时,程序停在这个函数中
			
		
			//WFI表示wait for interrupt,WFE表示wait for event
			//如果发生中断唤醒,会先执行中断程序 ,再执行PWR_EnterSTOPMode的下1行代码
			
			//重新初始化
			SystemInit();
			
		  //SoftReset();
			
// 		 	if(Check_WKUP())
// 		 		break;
	
	
// 			if(longpress==0)
// 					break;
//  	}
	
			//重新初始化
			//SystemInit();	
	
}
コード例 #2
0
ファイル: lowpower.c プロジェクト: NjordCZ/opentag-eval
/**
  * @brief  Enters MCU in STANDBY mode. The wake-up from STANDBY mode is performed 
  *         when a rising edge is detected on WakeUp pin.
  * @param  None
  * @retval None
  */
void LowPower_EnterSTANDBYMode_WAKEUP_1(void)
{
//  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
//  LCD_SetBackColor(LCD_COLOR_BLUE);
  /* Set the LCD Text Color */
//  LCD_SetTextColor(LCD_COLOR_WHITE);
  
//  LCD_DisplayStringLine(LCD_LINE_7, " MCU in STANDBY Mode");
//  LCD_DisplayStringLine(LCD_LINE_8, " To exit press SEL  ");
  /* Check if the StandBy flag is set */
  if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
  {       
    /* Clear StandBy flag */
    PWR_ClearFlag(PWR_FLAG_SB);
    
    RTC_WaitForSynchro();
  }
  
  RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
  
  /* Enable WakeUp pin */
  PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE);
  
  /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
  PWR_EnterSTANDBYMode();
}
コード例 #3
0
ファイル: BSP_CARTE.c プロジェクト: jdaheron/BLDR
/**-----------------------------------------------------------------------------
 * @brief	Entree en mode Stop.
 */
void STOP_MODE() {

	EXTI_InitTypeDef EXTI_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;

	// Config IT
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);	// Connect EXTI Line0 to PA0 pin

	// Configure EXTI Line0
	EXTI_InitStructure.EXTI_Line = EXTI_Line0;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);

	// Enable and set EXTI Line0 Interrupt to the lowest priority
	NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	// Config Mode Stop
	PWR_WakeUpPinCmd(ENABLE);
	PWR_BackupRegulatorCmd(DISABLE);
	PWR_FlashPowerDownCmd(ENABLE);

	/* Enable PWR and BKP clock */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

	// Entree Mode Stop
	PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
}
コード例 #4
0
/**
  * @brief  This function configures the system to enter Standby mode for
  *         current consumption measurement purpose.
  *         STANDBY Mode
  *         ============
  *           - IWDG and LSI OFF
  *           - Current Consumption ~0.3uA
  *           - Wakeup using WakeUp Pin 1 (PA.00)    
  * @param  None
  * @retval None
  */
void StandbyMode_Measure(void)
{
  /*  Configure Key Button*/
  STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO);

  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET)
  {
  }
  /* Wait Until Key button pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET)
  {
  }

  /* Enable Ultra low power mode */
  PWR_UltraLowPowerCmd(ENABLE);

  /* Clear PWR WakeUp flag */
  PWR_ClearFlag(PWR_FLAG_WU);

  /* Enable WKUP pin 1 */
  PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE);

  /* Request to enter STANDBY mode */
  PWR_EnterSTANDBYMode();
  
  /* Infinite loop */
  while (1)
  {
  }
}
コード例 #5
0
ファイル: power.c プロジェクト: webom2008/bf512.project
/*********************************************************************************************************
** Function name:           enter_low_power_mode
** Descriptions:            enter_low_power_mode
** input parameters:        none
** output parameters:       none
** Returned value:          none
*********************************************************************************************************/
void enter_low_power_mode(POWER_MODE mode)
{
    switch(mode)
    {
        case SLEEP:
            PWR_EnterSLEEPMode(PWR_Regulator_ON,PWR_SLEEPEntry_WFI);
            break;
        
        case STOP:
            PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
            break;
        
        case LPSTOP:
            PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
            break;
        
        case STANDBY:
            PWR_EnterSTANDBYMode();
            PWR_WakeUpPinCmd(ENABLE);
            break;
        
        default:
            break;
    }
}
コード例 #6
0
ファイル: standby.c プロジェクト: orkash/Library_Jacob
/************************************************ 
* 函  数: Standby_SysEnter(void)
* 功  能: 系统进入待机模式
*
* 参  数: 无
*
* 返回值: 无
*************************************************/
void Standby_SysEnter(void)
{
  RCC_APB2PeriphResetCmd(0x01FC, DISABLE);  // 复位所有IO口
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // 使能PWR外设时钟
  PWR_WakeUpPinCmd(ENABLE); // 使能唤醒引脚唤醒功能
  PWR_EnterSTANDBYMode(); // 进入待机模式
} // Standby_SysEnter()
コード例 #7
0
ファイル: main.c プロジェクト: Joonaskaru/STM32F4librad
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */     

  /* Initialize LEDs mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  
  /* Initialize Key Button mounted on EVAL board */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

  /* RTC configuration */
  RTC_Config();

  /* Turn on LED1 */
  STM_EVAL_LEDOn(LED1);

  /* Enable WKUP pin  */
  PWR_WakeUpPinCmd(ENABLE);

  /* Configure the SysTick to generate an interrupt each 250 ms */
  SysTick_Configuration();

  while (1)
  {
  }
}
コード例 #8
0
void HAL_Core_Execute_Stop_Mode(void)
{
    /* Enable WKUP pin */
    PWR_WakeUpPinCmd(ENABLE);

    /* Request to enter STOP mode with regulator in low power mode */
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);

    /* At this stage the system has resumed from STOP mode */
    /* Enable HSE, PLL and select PLL as system clock source after wake-up from STOP */

    /* Enable HSE */
    RCC_HSEConfig(RCC_HSE_ON);

    /* Wait till HSE is ready */
    if(RCC_WaitForHSEStartUp() != SUCCESS)
    {
        /* If HSE startup fails try to recover by system reset */
        NVIC_SystemReset();
    }

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08);
}
コード例 #9
0
ファイル: ui.c プロジェクト: equinoxorg/standalone_v2
void pwr_sw_init (void)
{
	EXTI_InitTypeDef   EXTI_InitStructure;
  NVIC_InitTypeDef   NVIC_InitStructure;
	
	//Enable PA0 as WKUP Pin, this will Wake up Chip from Standby Mode on rising edge
	//Configures pin as input with Pull-down resistor
	PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE);
	
	//Enable interrupt on PA0 Pin
	// Enable SYSCFG clock 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  
  // Connect EXTI0 Line to PA0 pin 
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

  // Configure EXTI0 line 
  EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  // Enable and set EXTI0_1_IRQn Interrupt 
  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
	
}
コード例 #10
0
ファイル: wkup.c プロジェクト: li77leprince/Venipuncture
void Sys_Standby(void)
{
	NVIC_SystemLPConfig(NVIC_LP_SLEEPDEEP,ENABLE);	   
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);	//使能PWR和BKP外设时钟    
	PWR_WakeUpPinCmd(ENABLE);  //使能唤醒管脚功能

	PWR_EnterSTANDBYMode();	  //进入待命(STANDBY)模式 		 
}
コード例 #11
0
ファイル: example.c プロジェクト: GCY/STM32F1-Nano
void PWR_StandbyMode( void )
{
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  PWR_WakeUpPinCmd(ENABLE);
  PWR_BackupAccessCmd(ENABLE);
  PWR_ClearFlag(PWR_FLAG_SB);
  PWR_EnterSTANDBYMode();
}
コード例 #12
0
/**
  * @brief  This function configures the system to enter Standby mode for
  *         current consumption measurement purpose.
  *         STANDBY Mode
  *         ============
  *           - RTC OFF
  *           - IWDG and LSI OFF
  *           - Wakeup using WakeUp Pin2 (PC.13)
  * @param  None
  * @retval None
  */
void StandbyMode_Measure(void)
{
  /* Disable wake-up source(Wake up pin) to guarantee free access to WUT level-OR input */ 
  PWR_WakeUpPinCmd(PWR_WakeUpPin_2, DISABLE);  
  /* Clear Wake-up flag */
  PWR_ClearFlag(PWR_FLAG_WU);
  PWR_ClearFlag(PWR_FLAG_SB);
  /* Enable WKUP pin 1 */
  PWR_WakeUpPinCmd(PWR_WakeUpPin_2,ENABLE);
  
  /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
  PWR_EnterSTANDBYMode();
  
  /* Infinite loop */
  while (1)
  {
  }
}
コード例 #13
0
/*******************************************************************************
* Function Name  : LowPower_Init
* Description    : Initializes Low Power application. 
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LowPower_Init(void)
{
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Enable WakeUp pin */
  PWR_WakeUpPinCmd(ENABLE);

  /* Enable Clock Security System(CSS) */
  RCC_ClockSecuritySystemCmd(ENABLE);
}
コード例 #14
0
void HAL_Core_Execute_Standby_Mode(void)
{
    /* Enable WKUP pin */
    PWR_WakeUpPinCmd(ENABLE);

    /* Request to enter STANDBY mode */
    PWR_EnterSTANDBYMode();

    /* Following code will not be reached */
    while(1);
}
コード例 #15
0
ファイル: wakeup.c プロジェクト: ShowerXu/Elink407Board
 //进入待机模式
 void StandbyMode(void)
 {	
	//关闭不需要的外设
		
	RCC_AHB1PeriphResetCmd(0X01FF,ENABLE);  //复位所有 IO 口
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//使能 PWR 时钟
	PWR_ClearFlag(PWR_FLAG_WU);//清除 Wake-up  标志
	PWR_WakeUpPinCmd(ENABLE);//设置 WKUP 用于唤醒
	PWR_EnterSTANDBYMode();//进入待机模式
		
 }
コード例 #16
0
ファイル: usr_cmd.c プロジェクト: KNCheung/AlarmClockBeta
void StandBy(void)
{
	PushREG(REGA,REG_Shut,0x00,0x00);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); 
	NVIC_SystemLPConfig(NVIC_LP_SEVONPEND,ENABLE);
	PWR_WakeUpPinCmd(ENABLE);
	PWR_ClearFlag(PWR_FLAG_WU);
	PWR_ClearFlag(PWR_FLAG_SB);
	PWR_EnterSTANDBYMode();
	return;
}
コード例 #17
0
/**
  * @brief  This function configures the system to enter Standby mode for
  *         current consumption measurement purpose.
  *         STANDBY Mode
  *         ============
  *           - Backup SRAM and RTC OFF
  *           - IWDG and LSI OFF
  *           - Wakeup using WakeUp Pin (PA.00)
  * @param  None
  * @retval None
  */
void StandbyMode_Measure(void)
{
  /* Enable WKUP pin 1 */
  PWR_WakeUpPinCmd(ENABLE);

  /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
  PWR_EnterSTANDBYMode();
  
  /* Infinite loop */
  while (1)
  {
  }
}
コード例 #18
0
ファイル: lowpower.c プロジェクト: NjordCZ/opentag-eval
/**
  * @brief  Enters MCU in STANDBY mode. The wake-up from STANDBY mode is performed 
  *         by an RTC Alarm event.
  * @param  None
  * @retval None
  */
void LowPower_EnterSTANDBYMode_RTCAlarm(void)
{
 // LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
//  LCD_SetBackColor(LCD_COLOR_BLUE);
  
  /* Set the LCD Text Color */
 // LCD_SetTextColor(LCD_COLOR_WHITE);
  
  /* External Interrupt Disable */
  //Demo_IntExtOnOffCmd(DISABLE);
  
  /* Enable WakeUp pin */
  PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE);
    
  /* Check if the StandBy flag is set */
  if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
  {       
    /* Clear StandBy flag */
    PWR_ClearFlag(PWR_FLAG_SB);
   
    RTC_WaitForSynchro();
  }
  
  if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x5AA5)
  {
  //  LCD_DisplayStringLine(LCD_LINE_1, "Time and Date are   ");
   // LCD_DisplayStringLine(LCD_LINE_2, "not configured,     ");
  //  LCD_DisplayStringLine(LCD_LINE_3, "please go to the    ");
  //  LCD_DisplayStringLine(LCD_LINE_4, "calendar menu and   ");
  //  LCD_DisplayStringLine(LCD_LINE_5, "set the time and    ");
  //  LCD_DisplayStringLine(LCD_LINE_6, "date parameters.    ");
  //  LCD_DisplayStringLine(LCD_LINE_7, "Press JoyStick to   ");
  //  LCD_DisplayStringLine(LCD_LINE_8, "continue...         ");
    
    
    /* External Interrupt Enable */
    //Demo_IntExtOnOffCmd(ENABLE);
    return;
  }
  
  Calendar_AlarmPreAdjust_A();

 // LCD_DisplayStringLine(LCD_LINE_7, " MCU in STANDBY Mode");
 // LCD_DisplayStringLine(LCD_LINE_8, " Wait For RTC Alarm ");
  
  /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
  PWR_EnterSTANDBYMode();
}
コード例 #19
0
ファイル: stm32f4xx_lp_modes.c プロジェクト: xrecord/pocker
/**
  * @brief  This function configures the system to enter Standby mode for
  *         current consumption measurement purpose.
  *         STANDBY Mode
  *         ============
  *           - Backup SRAM and RTC OFF
  *           - IWDG and LSI OFF
  *           - Wakeup using WakeUp Pin (PA.00)
  * @param  None
  * @retval None
  */
void StandbyMode_Measure(void)
{
  /* Enable WKUP pin 1 */
  PWR_WakeUpPinCmd(ENABLE);

  /* Clear Power WakeUp (CWUF) pending flag */
  PWR_ClearFlag(PWR_FLAG_WU);

  /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
  PWR_EnterSTANDBYMode();

  /* Infinite loop */
  while (1)
  {
  }
}
コード例 #20
0
ファイル: main.c プロジェクト: perrylau/web
/* Check whether goto standby
  * If PA0==0, goto standby mode. 
  * 
  */
static void check_gotostandby(void)
{
	wakeUpIOInit();
	if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == Bit_RESET) {
		//enable interrupt
		EXTI->IMR |= EXTI_Line0;
		
		//stm32 enter standby mode
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
		PWR_WakeUpPinCmd(ENABLE);
		PWR_EnterSTANDBYMode();
		
		while(1);
	} else {
		//enable_watchdog(5);
	}
}
コード例 #21
0
ファイル: main.c プロジェクト: rabryan/stm32f4examples
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */

  /* Initialize LEDs and Key Button mounted on STM32F4-Discovery board */
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED3);

  /* Configure Button EXTI line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line1;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set Button EXTI Interrupt to the lowest priority */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  /* RTC configuration */
  RTC_Config();

  /* Turn on LED4 */
  STM_EVAL_LEDOn(LED4);

  /* Enable WKUP pin  */
  PWR_WakeUpPinCmd(ENABLE);

  /* Configure the SysTick to generate an interrupt each 250 ms */
  SysTick_Configuration();

  while (1)
  {
  }
}
コード例 #22
0
ファイル: core_hal.c プロジェクト: spark/firmware
void HAL_Core_Execute_Standby_Mode(void)
{
	/* Should we execute System Standby mode */
	if(BKP_ReadBackupRegister(BKP_DR9) == 0xA5A5)
	{
		/* Clear Standby mode system flag */
		BKP_WriteBackupRegister(BKP_DR9, 0xFFFF);

        /* Enable WKUP pin */
        PWR_WakeUpPinCmd(ENABLE);

		/* Request to enter STANDBY mode */
		PWR_EnterSTANDBYMode();

		/* Following code will not be reached */
		while(1);
	}
}
コード例 #23
0
/**
  * @brief  This function configures the system to enter Standby mode for
  *         current consumption measurement purpose.
  *         STANDBY Mode
  *         ============
  *           - RTC OFF
  *           - IWDG and LSI OFF
  *           - Wakeup using WakeUp Pin1 (PA.00)
  * @param  None
  * @retval None
  */
void StandbyMode_Measure(void)
{
  /* Check if the StandBy flag is set */
  if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
  {       
    /* Clear StandBy flag */
    PWR_ClearFlag(PWR_FLAG_SB);
  }
  /* Enable WKUP pin 1 */
  PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE);

  /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
  PWR_EnterSTANDBYMode();
  
  /* Infinite loop */
  while (1)
  {
  }
}
コード例 #24
0
void platform_mcu_enter_standby(uint32_t secondsToWakeup)
{ 
  platform_rtc_time_t time;
  uint32_t currentSecond;
  RTC_AlarmTypeDef  RTC_AlarmStructure;

  PWR_WakeUpPinCmd(ENABLE);

  if(secondsToWakeup == MICO_WAIT_FOREVER)
    PWR_EnterSTANDBYMode();

  platform_log("Wake up in %d seconds", secondsToWakeup);
 
  platform_rtc_get_time(&time);
  currentSecond = time.hr*3600 + time.min*60 + time.sec;
  currentSecond += secondsToWakeup;
  RTC_AlarmStructure.RTC_AlarmTime.RTC_H12     = RTC_HourFormat_24;
  RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours   = currentSecond/3600%24;
  RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = currentSecond/60%60;
  RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = currentSecond%60;
  RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31;
  RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
  RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay ;

  RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
  /* Disable the Alarm A */
  RTC_ITConfig(RTC_IT_ALRA, DISABLE);

  /* Clear RTC Alarm Flag */ 
  RTC_ClearFlag(RTC_FLAG_ALRAF);

  RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);

  /* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from
     STANDBY mode (RTC Alarm IT not enabled in NVIC) */
  RTC_ITConfig(RTC_IT_ALRA, ENABLE);

  /* Enable the Alarm A */
  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

  PWR_EnterSTANDBYMode();
}
コード例 #25
0
ファイル: power.c プロジェクト: JizhouZhang/stm32f4-labs
/**
 * @brief Sets up User button to wake system from STOP mode
 *
 * This function configures the User button (PA0) as a digital 
 * input that triggers an interrupt, which may be used to wake the 
 * system from STOP mode.
 * 
 * You must define an interrupt handler (EXTI0_IRQHandler) to handle
 * this interrupt.
 */
void initWakeupPin() {

    /* Copy in your initButton() function from the `interrupt-button' 
       project in lab 5.                                             */
    NVIC_InitTypeDef NVIC_InitStructure;
    EXTI_InitTypeDef EXTI_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    
    // Enable GPIOA clock for User button peripheral on GPIOA
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    // Enable SYSCFG clock for interrupts
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
    
    // Configure PA0 pin as input
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;		
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    
    // Connect EXTI Line0 (external interrupt line 0) to PA0 pin
    // This is the library function equivalent of running
    // SYSCFG->EXTICR[0] &= SYSCFG_EXTICR1_EXTI0_PA;    
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
    
    // Configure the interrupt using library functions
    EXTI_InitStructure.EXTI_Line = EXTI_Line0;             
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;    
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; 
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;            
    EXTI_Init(&EXTI_InitStructure);                         
    
    // Enable and set priorities for the EXTI0 interrupt in NVIC 
    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;                
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;   
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;         
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;               
    NVIC_Init(&NVIC_InitStructure);
    PWR_WakeUpPinCmd(ENABLE);                         
}
コード例 #26
0
ファイル: main.c プロジェクト: bisle/34_GW_G100
int  get_reset_reason( void )
{
  int   sts = 0;
  
  if( RCC_GetFlagStatus( RCC_FLAG_PINRST ) == SET )
  {
    sts |= MAIN_RST_FOR_PIN;
  }
  if( RCC_GetFlagStatus( RCC_FLAG_PORRST ) == SET )
  {
    sts |= MAIN_RST_FOR_POR;
  }
  if( RCC_GetFlagStatus( RCC_FLAG_SFTRST ) == SET )
  {
    sts |= MAIN_RST_FOR_SFT;
  }
  if( RCC_GetFlagStatus( RCC_FLAG_IWDGRST ) == SET )
  {
    sts |= MAIN_RST_FOR_IWD;
    if( main_is_enter_stby_mode == MAIN_ENTER_STBY_MODE )
    {
      main_is_enter_stby_mode = 0;
      PWR_WakeUpPinCmd( ENABLE );
      PWR_EnterSTANDBYMode();
    }
  }
  if( RCC_GetFlagStatus( RCC_FLAG_WWDGRST ) == SET )
  {
    sts |= MAIN_RST_FOR_WWD;
  }
  if( RCC_GetFlagStatus( RCC_FLAG_LPWRRST ) == SET )
  {
    sts |= MAIN_RST_FOR_LPR;
  }
  
  RCC_ClearFlag();    // clear all reset flags
  
  return  sts;
  
} // end of get_reset_reason()
コード例 #27
0
ファイル: main.c プロジェクト: WaelG/Thinner-Client
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     

  /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */       
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

  /* Turn on LED1 */
  STM_EVAL_LEDOn(LED1);

  /* Enable PWR and BKP clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Enable WKUP pin */
  PWR_WakeUpPinCmd(ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Configure RTC clock source and prescaler */
  RTC_Configuration();

  /* Configure the SysTick to generate an interrupt each 250 ms */
  SysTick_Configuration();
 
  while (1)
  {
  }
}
コード例 #28
0
ファイル: main.c プロジェクト: neirons/pythondatalogger
void Board_main(void)
{   
  
  
    uint8_t i;
    uint16_t flash_flag = 0;
    uint16_t copy_file_flag = 0;
    
    /* RCC system reset(for debug purpose) */
    RCC_DeInit();
    
    /* Enable HSE */
    RCC_HSEConfig(RCC_HSE_ON);
    
    /* Wait till HSE is ready */
    HSEStartUpStatus = RCC_WaitForHSEStartUp();
    
    if(HSEStartUpStatus == SUCCESS)
    {
    #if 0
        /* Enable Prefetch Buffer */
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
	FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);
        /* Flash 2 wait state */
        FLASH_SetLatency(FLASH_Latency_2);

	#else
     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
	FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Enable);
	        /* Flash 2 wait state */
        /*FLASH_SetLatency(FLASH_Latency_2);*/
	FLASH_SetLatency(FLASH_Latency_0);	/*abin@ */
	#endif
        

        
        /* HCLK = SYSCLK */
        RCC_HCLKConfig(RCC_SYSCLK_Div1); 
        
        /* PCLK2 = HCLK */
        RCC_PCLK2Config(RCC_HCLK_Div1); 
        
        /* PCLK1 = HCLK/2 */
        RCC_PCLK1Config(RCC_HCLK_Div2);


	#if 0
        /* PLLCLK = 8MHz * 9 = 72 MHz */
	/*abin:note*/
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
//        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_8);
        
        /* Enable PLL */ 
        RCC_PLLCmd(ENABLE);
      
        /* Wait till PLL is ready */
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
        {
        }
        
        /* Select PLL as system clock source */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
	        /* Wait till PLL is used as system clock source */
        while(RCC_GetSYSCLKSource() != 0x08)
        {
        }	
	#else
 RCC_PLLCmd(DISABLE);
	        /* Select HSE as system clock source */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
	        /* Wait till PLL is used as system clock source */
        while(RCC_GetSYSCLKSource() != 0x04)
        {
        }	
         #endif
		  

    }
    
    /* Enable GPIOA, GPIOB, and AFIO clocks */
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO, ENABLE);
    
        /* Enable DMA1 ,DMA2 clock */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1|RCC_AHBPeriph_DMA2, ENABLE);
    
    /* Enable ADC1 ADC2,and GPIOC clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 |RCC_APB2Periph_ADC2| RCC_APB2Periph_GPIOC, ENABLE);


    /* Enable PWR and BKP clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
  
    /* Enable write access to Backup domain */
    PWR_BackupAccessCmd(ENABLE);
    
    /* Clear Tamper pin Event(TE) pending flag */
    BKP_ClearFlag();

     #if ABIN_DEBUG
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  STM_EVAL_COMInit(COM1, &USART_InitStructure);

  /* Output a message on Hyperterminal using printf function */
  //sys_printf("\n\r abin 8M is ok moify flash latency :USART Init end \n\r");    
    
#endif 
  
    /*------------------- Resources Initialization -----------------------------*/
    /* GPIO Configuration */
    GPIO_Config();
  //sys_printf("\n\r abin mul2 :GPIO_Config \n\r");    

#if ABIN_CPU_UPGRADE2HIGHSPEED_OPTION
   USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
   if(USB_Plugin_State == 1)
   {
       //sys_printf("\n\r abin switch to high speed !!\n\r"); 
      UpgradeToHighSpeed(); 
     
   }
#endif

    /* Interrupt Configuration */
    InterruptConfig();
    
    /* Configure the systick */    
    SysTick_Configuration();
    
    /*------------------- Drivers Initialization -------------------------------*/
    
    /* Initialize the Low Power application */
    LowPower_Init();
    
    
    /* Enable WKUP pin */
    PWR_WakeUpPinCmd(ENABLE);
    
    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);
    
    
    RTC_Init();  
    
    
    /* If HSE is not detected at program startup */
    if(HSEStartUpStatus == ERROR)
    {
        /* Generate NMI exception */
        SCB->ICSR |= SCB_ICSR_NMIPENDSET;
    }  
    

    USB_Disconnect_Config();       
    GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);/*???abin@20100714*/
    
    WakupPin_Init();
    
          //sys_printf("\n\r abin before CheckPowerOnReason\n\r"); 
    CheckPowerOnReason();


      //sys_printf("\n\r abin after CheckPowerOnReason\n\r");    
    
      
    Board_ADC_Init();        

        
    /*init the flag*/  
    flash_flag = *(uint16_t *)FLASH_READY_ADDRESS;
    if( flash_flag != FLAG_FLASH_READY)
    {
    	     //sys_printf("\n\r abin ready to erase flash \n\r");  
        FLASH_Unlock();
        FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);	        
        //Erase the 32 page 32K
        for(i = 0;i< DATA_PAGES;i++)
        {
        	 //sys_printf("\n\r abin ready to erase aa"); 
            FLASH_ErasePage(DATA_LOGGER_ADDRESS_START + i * 1024);/*数据在Page1...page32存放*/
        }
        FLASH_ErasePage(FLASH_READY_ADDRESS); /*abin@20100715 没添加保护*/
        FLASH_ProgramHalfWord(FLASH_READY_ADDRESS , FLAG_FLASH_READY);

        FLASH_ErasePage(REOCRD_COUNT_ADDRESS);        
        FLASH_ProgramHalfWord(REOCRD_COUNT_ADDRESS , 0x0000);
        
        FLASH_Lock();
         //sys_printf("\n\r abin mul2 :erase flash end!!!\n\r"); 
    }
    
     //sys_printf("\n\r abin ready to erase flash end \n\r");  
    USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
    
    if(USB_Plugin_State == 0)
    {
        
      
        record_count =   *(uint16_t *)REOCRD_COUNT_ADDRESS;
        
        if(record_count >= 15428)
        {
            //Write the full flag
            //Do nothing....          
          while(1)
          {
           //sys_printf("\n\r sample end !!!!!!!!!!!!!!!!!!!!!\n\r"); 
            Led_One_By_One(4);
			/*应该进入standy 模式 abin@20100715*/
          }
        }
        else
        {
        //sys_printf("\n\r abin ready to add sample count \n\r");  
            FLASH_Unlock();
            FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);	        
            FLASH_ProgramHalfWord(DATA_LOGGER_ADDRESS_START + record_count * 2, GetTemperature());
            //Erase first
            FLASH_ErasePage(REOCRD_COUNT_ADDRESS);
            //Update the count
            record_count = record_count + 1;
            
            FLASH_ProgramHalfWord(REOCRD_COUNT_ADDRESS , record_count);
            FLASH_Lock();
            
            //sys_printf("\n\r abin add sample count :end\n\r"); 
        }
        

      	     //sys_printf("\n\r %000\n\r");
      GPIO_SetBits(GPIOA, GPIO_Pin_1);
	  #if 0
      Delay(25);
	  #else
      Delay(5);
	  
	  #endif
	  	     //sys_printf("\n\r %111\n\r");

    }
    else
    {
      
        Enable_SDcard();
        /*
        if there is usb connect, copy the data to sdcard. and start the mass storage
        */
        
        copy_file_flag =   *(uint16_t *)COPY_FILE_ADDRESS;

        if(copy_file_flag == FLAG_FILE_COPYED)
        {

              Write_Copy_File_Flag(FLAG_FILE_NO_COPYED);                    

              USB_Disconnect_Config();       
              GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
              Delay(10);
              GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
              
               /* Enable and GPIOD clock */
               Mass_Storage_Start ();                  
               while( bDeviceState != CONFIGURED)
               {
                  Led_Both(1);
               }
               
               USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
               while(    USB_Plugin_State == 1)/* U-DISK success ,then CPU Loop in here*/
              {
                        USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
                        Led_One_By_One(1);
                         //sys_printf("\n\r abin :mul2  u disk !!!\n\r"); 
              }
              PowerOff();    
              Write_Copy_File_Flag(FLAG_FILE_NO_COPYED);                    
               
        }
        else
        {
              Write_Copy_File_Flag(FLAG_FILE_COPYED);
              Led_Green_Flink(3);
              NAND_FAT();  
              CreateDataLoggerFile();                          
              Write_Copy_File_Flag(FLAG_FILE_COPYED);
              //sys_printf("\n\r abin :mul2  NAND_FAT!!!\n\r"); 
        }
         //sys_printf("\n\r abin :mul2  Disable_SDcard!!!\n\r"); 
        Disable_SDcard();        
        BKP_WriteBackupRegister(BKP_POWER_ON, FLAG_POWER_OFF); 
        PWR_EnterSTANDBYMode();    

        /* Generate a system reset */  
        //NVIC_SystemReset();    
    }
    
     //sys_printf("\n\r @111 \n\r"); 
    /* Set the RTC Alarm after 60s */
    RTC_SetAlarm(RTC_GetCounter()+ 3);
	     //sys_printf("\n\r @222:RTC_GetCounter()=0x%x \n\r",RTC_GetCounter()); 

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    	     //sys_printf("\n\r @333\n\r");
    PWR_EnterSTANDBYMode();    
    
    
}
コード例 #29
0
ファイル: main.c プロジェクト: tymbys/Watch
int main(void)
{


	RCC_APB1PeriphClockCmd( RCC_APB1Periph_PWR, ENABLE);//!!!!

	// тактирование ядра низкоскоростным внутренним генератором 4мгц
	RCC->ICSCR &= ~RCC_ICSCR_MSIRANGE;//!!!!
	RCC->ICSCR |= RCC_ICSCR_MSIRANGE_6;//!!!!
	//RTC_Initilithahion();//!!!!
	////////////////////////////////////////////////////////////////////

	delay_ms(1000);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



	curent_cmd = 0;
	PCount_Start = 0;
	/////////////////// настройка пробуждения
		RCC_HSICmd(DISABLE);
		PWR_PVDCmd(DISABLE);
		PWR_UltraLowPowerCmd(ENABLE);
		PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE);
		PWR_UltraLowPowerCmd(ENABLE);

	////////////// настройка прирывания для будильника в неспящем режиме
		EXTI_InitTypeDef exti;
		NVIC_InitTypeDef NVIC_InitStructure;

		EXTI_ClearITPendingBit(EXTI_Line17);
		exti.EXTI_Line = EXTI_Line17;
		exti.EXTI_Mode = EXTI_Mode_Interrupt;
		exti.EXTI_Trigger = EXTI_Trigger_Rising;
		exti.EXTI_LineCmd = ENABLE;
		EXTI_Init(&exti);

		NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
		NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
		NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
		NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
		NVIC_Init(&NVIC_InitStructure);

		//////////////////




	if(PWR_GetFlagStatus(PWR_FLAG_SB)!=RESET)//Если МК вышел из режима standby
	{
		WkupFlag=1;
		curent_cmd = 1;


		if(RTC_GetFlagStatus(RTC_FLAG_ALRAF)!=RESET)//Если МК вышел из режима ALARM
		{
							//RTC_Initilithahion();//!!!!
						//PWR_RTCAccessCmd(ENABLE);
						//RTC_ClearFlag(RTC_FLAG_ALRAF);
						//PWR_RTCAccessCmd(DISABLE);
							//f_WakeupToAlarm=1;
						curent_cmd = 5;
		}




		//RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
		PWR_ClearFlag(PWR_FLAG_SB); //Сброс флага, который указывает на то, что МК вышел из режима standby


		PWR_RTCAccessCmd(ENABLE); // Доступ в RTC
		//RTC_ClearITPendingBit(RTC_IT_WUT);
		//RTC_ClearFlag(RTC_FLAG_WUTF);
		RTC_ClearFlag(RTC_FLAG_ALRAF);
		PWR_RTCAccessCmd(DISABLE);





	}
	else
	{


		WkupFlag=0;

		RTC_TimeTypeDef alarmTime;
		alarmTime.RTC_H12 = RTC_H12_PM;//!!!!;
		alarmTime.RTC_Hours = 20;
		alarmTime.RTC_Minutes = 0;
		alarmTime.RTC_Seconds = 20;


		RTC_Initilithahion();//!!!!
		//RTC_Set_Alarm(alarmTime);/// Магическая последовательность, 1. RTC_Set_Alarm, 2. RTC_Set_Time иначе не работает будильник


		RTC_TimeTypeDef RTC_Time;
		RTC_DateTypeDef RTC_Date;

		RTC_Time.RTC_H12 = RTC_H12_PM;//!!!!;
		RTC_Time.RTC_Hours = 20;
		RTC_Time.RTC_Minutes = 00;
		RTC_Time.RTC_Seconds = 00;


		RTC_Date.RTC_WeekDay = RTC_Weekday_Sunday;

		RTC_Date.RTC_Year = 14;
		RTC_Date.RTC_Month = 8;
		RTC_Date.RTC_Date = 17;

		RTC_Set_TimeDate(RTC_Time, RTC_Date);///


	}





	//else curent_cmd = 0;//f_WakeupToAlarm=0;











	//RTC_Initilithahion();//!!!!
	//RTC_Set_Time();






OLED_Init();
OLED_Clear();
char i,j;






/*
RCC_GetClocksFreq(&Frequency);
f=Frequency.SYSCLK_Frequency/1000;
IntToStr(a,f);
OLED_DrawString_fast(30,30,a,10);
*/


OLED_LcdCache_Clear();



//if(0==WkupFlag) //Если МК до этого не находился в режиме STANDBY!!!!!!!!!!!!!!!!!
//PWR_EnterSTANDBYMode(); //Перейди в режим STANDBY!!!!!!!!!!!!!!!!!!!


//OLED_DrawBitmap_fast(3,12,menu1_sprait,123,40);
//delay_ms(10000);


WaitToSleep = 0;



TACT_Config();

BackTimeAndData.hour=0;
BackTimeAndData.minute=0;
BackTimeAndData.second=0;

globa_menu = 1;
f_aktive_menu = 0;
//curent_cmd = 0;

PWatch_Setup_Step = 0;

key_up = 0;
key_down = 0;
key_ok = 0;

PCount_Start = 0;

while(1)
{

	key = 0;

	key_ok = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0);
	key_down = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2);
	key_up = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12);


/*
	OLED_DrawString_fast(0,0,"            ",10);

	IntToStr(bbb,key_ok);
	OLED_DrawString_fast(0,0,bbb,10);

	IntToStr(bbb,key_down);
	OLED_DrawString_fast(30,0,bbb,10);

	IntToStr(bbb,key_up);
	OLED_DrawString_fast(60,0,bbb,10);
*/

	if (key_ok!=0)
	{
		key_ok = 0;
		key = 1;



		//OLED_DrawString_fast(0,0,"000000000",10);
		//f_aktive_menu = 1;


		/*
		if (f_aktive_menu == 1)
		{
			//f_work_comand = 1;
			f_aktive_menu = 0;
			f_clearScrin = 1;
			curent_cmd = menu_cmd[globa_menu-1];

		}
		else curent_cmd = 255 ;
		*/
	}


	if (key_down==0)
	{
		key_down = 0;
		key = 2;

		/*
		if ((globa_menu>1)&&(f_work_comand == 0)) globa_menu--;
		else globa_menu = 1;

		//IntToStr(bbb,globa_menu);
		//OLED_DrawString_fast(0,0,bbb,10);

		 */

	}


	if (key_up==0)
	{

		key_up = 0;
		key = 12;

		/*
		if ((globa_menu<4)&&(f_work_comand == 0)) globa_menu++;
		else globa_menu = 4;

		//IntToStr(bbb,globa_menu);
		//OLED_DrawString_fast(0,0,bbb,10);

		 */

	}


	if (key!=0)
		{
			GPIO_SetBits(GPIOA, GPIO_Pin_1);
			delay_ms(30);
			GPIO_ResetBits(GPIOA, GPIO_Pin_1);
		}



/*
	if (f_clearScrin==1)
	{
		OLED_Clear();
		f_clearScrin=0;
	}
*/


	//if (f_aktive_menu==0)
	//{

	switch(curent_cmd)
	{
		case 0:			//нет команды

				PWatch_Menu();

				break;
		case 1:			//Программа показа часов (главная страница)

				//OLED_Clear();
				//f_work_comand = 1;
				PWatch_Anim();
				break;
		case 2:			//Программа настройки даты/времени и др.

				//OLED_Clear();
				OLED_DrawString_fast(0,0,"Календарь",10);
				curent_cmd = 0;
				break;

		case 3:

				//OLED_Clear();
				PWatch_Set_Alarm();
				break;

		case 4:

				//OLED_Clear();
				//OLED_DrawString_fast(0,0,"Настройки",10);

				//f_work_comand = 1;
				PWatch_Setup();

				break;

		case 5:

				PWatch_Vibration();

				break;


		case 254:

				OLED_Clear();

				break;

		/*case 255:

				OLED_Clear();
				OLED_DrawBitmap_fast(3,12,menu1_sprait,123,40);
				f_aktive_menu = 1;
				//f_work_comand = 0;
				//key=0;
				break;
		*/
		default: 		//выполнить, если ни один вариант не подошел

				break;
	}
	//}
	//else
	//{
		//PWatch_Menu();
	//}

/*
				if(WainToAlarm == 1)
				{
					OLED_DrawString_fast(0,0,"alarm1",10);
					WainToAlarm =0;
				}
*/


				//if(WaitToSleep>=5)
				//{
					//WaitToSleep=0;


					//PWR_ClearFlag(PWR_FLAG_SB); //Сброс флага, который указывает на то, что МК вышел из режима standby


/*
					for (i=255; i>0; i--)
					{
						OLED_SetContrast(i);
						IntToStr(a,i);
						OLED_DrawString_fast(0,0,a,10);
						//delay_ms(500);
					}*/




					//OLED_DrawBitmap_fast(32,10,Fallout_Bitmaps,58,60);
					//delay_ms(1000);

					//OLED_Display_Off();!!!!!!!!!!!!!!!!!!!!!!!!1

					//RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, DISABLE);
					//походу стабилитрон кушает 0.1 мА, общее потребление 0.15мА


					//PWR_EnterSTANDBYMode();!!!!!!!!!!!!!!!!!!!!!



				//}


				//WaitToSleep++;

/*
				RCC_GetClocksFreq(&Frequency);
				f=Frequency.SYSCLK_Frequency/1000;
				IntToStr(a,f);
				OLED_DrawString_fast(0,0,a,10);
*/






	delay_ms(250);



}

}
コード例 #30
0
ファイル: pwr.c プロジェクト: offchooffcho/STM32-Logger
void shutdown() {
	PWR_WakeUpPinCmd(ENABLE);			//enable the pin
	PWR_EnterSTANDBYMode();				//only wakes on RTC signals or WKUP pin
}