stm32u5串口点灯
通过对单个字符输入的拼接暂存,实现对字符串的比较控制灯的亮灭
char buf[32];
char temp[32];
while (1)
{
printf("start\n\r");
memset(temp,0, sizeof(temp));
memset(buf,0, sizeof(buf));
while(temp[0] !='\r'){
memset(temp,0, sizeof(temp));
HAL_UART_Receive(&huart1,(uint8_t*)temp,1, 10000);
printf("temp::%c\n\r", temp[0]);
strcat(buf, temp);
}
LED_on_off(buf);
int LED_on_off(char *buf)
{
printf("buf::%s\n\r", buf);
if(strncmp(buf,"LED_ON", 6)==0)//LED_ON
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);
printf("LED_ON\n\r");
return 1;
}else if(strncmp(buf,"LED_OFF", 7)==0)//LED_OFF
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET);
printf("LED_OFF\n\r");
return 1;
}else//不是led灯的打开或者熄灭
{
printf("errorLED\n\r");
return 0;
}