1、说明
在freeRTOS中创建两个任务,当按键第一次被按下后,任务1挂起,当再按下按键后 任务1恢复,
2、添加任务
3、线程1代码实现
/* USER CODE BEGIN Header_LED_Thread1 */
/**
* @brief Function implementing the LED1 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_LED_Thread1 */
void LED_Thread1(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
static uint8_t timerCount = 0;
static uint8_t state = 0;
for(;;)
{
osDelay(10);
if( HAL_GPIO_ReadPin(GPIOE,Key1_Pin) == 0 ) {
timerCount++;
if(timerCount >=25 ) {
timerCount = 0;
state = !state;
}
}
if( state) {
osThreadResume(LED2Handle);
} else {
osThreadSuspend(LED2Handle);
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_SET);
}
}
/* USER CODE END 5 */
}
4、线程2代码实现
/* USER CODE BEGIN Header_LED2_Thread */
/**
* @brief Function implementing the LED2 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_LED2_Thread */
void LED2_Thread(void const * argument)
{
/* USER CODE BEGIN LED2_Thread */
/* Infinite loop */
for(;;)
{
osDelay(200);
HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_9);
}
/* USER CODE END LED2_Thread */
}
版权声明:本文为CSDN博主「新农民工2022」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m_l_z/article/details/122419356
1、说明
在freeRTOS中创建两个任务,当按键第一次被按下后,任务1挂起,当再按下按键后 任务1恢复,
2、添加任务
3、线程1代码实现
/* USER CODE BEGIN Header_LED_Thread1 */
/**
* @brief Function implementing the LED1 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_LED_Thread1 */
void LED_Thread1(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
static uint8_t timerCount = 0;
static uint8_t state = 0;
for(;;)
{
osDelay(10);
if( HAL_GPIO_ReadPin(GPIOE,Key1_Pin) == 0 ) {
timerCount++;
if(timerCount >=25 ) {
timerCount = 0;
state = !state;
}
}
if( state) {
osThreadResume(LED2Handle);
} else {
osThreadSuspend(LED2Handle);
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_SET);
}
}
/* USER CODE END 5 */
}
4、线程2代码实现
/* USER CODE BEGIN Header_LED2_Thread */
/**
* @brief Function implementing the LED2 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_LED2_Thread */
void LED2_Thread(void const * argument)
{
/* USER CODE BEGIN LED2_Thread */
/* Infinite loop */
for(;;)
{
osDelay(200);
HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_9);
}
/* USER CODE END LED2_Thread */
}
版权声明:本文为CSDN博主「新农民工2022」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m_l_z/article/details/122419356
暂无评论