本帖最后由 pengxizhen0 于 2015-12-7 21:15 编辑
void Sleep()
{
RCC_DeInit(); // RCC 时钟系统重启
/* Flash 0 wait state */
FLASH_SetLatency(FLASH_Latency_0);
/* Disable Prefetch Buffer */
FLASH_PrefetchBufferCmd(DISABLE);
/* Disable 64-bit access */
FLASH_ReadAccess64Cmd(DISABLE);
/* Enable the PWR APB1 Clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Select the Voltage Range 2 (1.5V) */
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);
/* Wait Until the Voltage Regulator is ready */
while(PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET)
{
}
/* HCLK = SYSCLK/2 = ~32KHz */
RCC_HCLKConfig(RCC_SYSCLK_Div2);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK */
RCC_PCLK1Config(RCC_HCLK_Div1);
/* Set MSI clock range to 65.536KHz */
RCC_MSIRangeConfig(RCC_MSIRange_0);
/* Select MSI as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI);
/* Wait till PLL is used as system clock source */
while (RCC_GetSYSCLKSource() != 0x00)
{}
/* Enable The ultra Low Power Mode */
PWR_UltraLowPowerCmd(ENABLE);
/* Enable the power down mode during Sleep mode */
FLASH_SLEEPPowerDownCmd(ENABLE);
/* Request to enter SLEEP mode with regulator in low power mode */
PWR_EnterSleepMode(PWR_Regulator_LowPower, PWR_SLEEPEntry_WFI);
}
main(){
if(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_7)==0){
if(flagSLEEP == false){
Sleep();
flagSLEEP = true;
}
else{
if(t == true){
GPIO_SetBits(GPIOB,GPIO_Pin_5);
t = false;
}
else{
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
t = true;
}
}
}
}
其中函数Sleep是从STM32L1的例程中拿来的
在Datasheet中可以看到,Sleep模式下,CPU是关闭的,但感觉程序还可以运行,我按按钮PC7时,为什么IO还是可以翻转的?
|