编写任务函数:
/* USER CODE BEGIN Header_StartTask02 */
/**
* @brief Function implementing the LED thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask02 */
void StartTask02(void const * argument)
{
/* USER CODE BEGIN StartTask02 */
/* Infinite loop */
for(;;)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);//取反
osDelay(1000);//延时1秒钟
}
/* USER CODE END StartTask02 */
}
/* USER CODE BEGIN Header_StartTask03 */
/**
* @brief Function implementing the KEY thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask03 */
void StartTask03(void const * argument)
{
/* USER CODE BEGIN StartTask03 */
/* Infinite loop */
for(;;)
{
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_7)==0)
{
while(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_7)==0);
printf(" press key1 \r\n");
}
osDelay(10);
}
/* USER CODE END StartTask03 */
}
任务StartTask02每隔1000ms取反小灯,任务StartTask03每次PB7按键按下向串口发送数据。
|