二、代码展示
1.主函数
代码如下(示例):
-------------------主函数---------------------------
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN WHILE */
HAL_SuspendTick(); //屏蔽tick中断,即系统时钟中断。
while (1)
{
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); //先把灯关了
if(HAL_GPIO_ReadPin(GPIOB,KEY2_Pin)== GPIO_PIN_RESET) //判断是否进入立即睡眠
{
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON,PWR_SLEEPENTRY_WFI);//睡起来
}
}
}
|