字符串在stm32串口中的应用
串口控制流水灯
pc通过串口发送字符串命令控制流水灯
open 流水灯打开
close 流水灯关闭
speed 1~9速度控制
if(strcmp((char *)usart1_rec_buff,"open")==0)
{
led_flag =1;
}
else if(strcmp((char *)usart1_rec_buff,"close")==0)
{
led_flag =0;
led_all_off();
}
else if(strcmp((char *)usart1_rec_buff,"sp1")>=0 && strcmp((char *)usart1_rec_buff,"sp9")<=0 && led_flag && strlen((char *)usart_rec_buff)==3)//led_flag开机调速strcmp比1-9ascall码
{
speed =usart1_rec_buff[2]-48;//字符-48变成数组
}