要实现接收串口字符串信息就要进行数据对比,本来使用的是for循环
#include <stdio.h> int main() { char str[256]; scanf("%s",str); int a,b,c; 
for(int m=0;m<=254;m++) { if(str[m]=='L'&str[m+1]=='E'&str[m+2]=='D') return 
printf("LED亮"); } } 
特意在devC++上测试了一下可行性,发现可行然后就放到了工程主函数里面
经过测试,灯是亮了但是发送了20多次,然后询问学长,学了一下strstr函数,只能说是真的好用,上面那一堆变成了两行。
 if(strstr((const char *)str,"LED"))//判断参数二是否是1的子串 { LED1_TOGGLE;//LED1状态翻转翻转 }
完整主函数是这样的 
/* 包含头文件 ----------------------------------------------------------------*/ 
#include "stm32f10x.h" #include "usartx.h" #include "led.h" #include <string.h> 
uint8_t Rxflag=0; uint8_t ucTemp; int main(void) { uint8_t ucaRxBuf[256]; 
uint16_t usRxCount; LED_GPIO_Init(); /* USART 配置模式为 115200 8-N-1,中断接收 */ 
USARTx_Init(); Usart_SendString("这是一个串口中断接收回显实验\n"); 
Usart_SendString("输入数据并以回车键结束\n"); /* 简单的通信协议,遇到回车换行符认为1个命令帧 */ usRxCount = 0; 
/* 无限循环 */ while (1) { if(Rxflag) { if (usRxCount < 
sizeof(ucaRxBuf))//sizeof为占用空间字节数关键字 { ucaRxBuf[usRxCount++] = ucTemp; } else { 
usRxCount = 0; } /* 遇到换行字符,认为接收到一个命令 */ if (ucTemp == 0x0A) /* 换行字符 */ { // 
Usart_SendStr_length(ucaRxBuf,usRxCount);//串口发送字符串 // usRxCount = 0; unsigned 
char str[256]; for(unsigned int m=0;m<sizeof (ucaRxBuf);m++) { 
str[m]=ucaRxBuf[m]; } for(int m=0;m<=254;m++) { if(strstr((const char 
*)str,"LED"))//判断参数二是否是1的子串 { LED1_TOGGLE;//LED1状态翻转翻转 } else { 
Usart_SendStr_length(ucaRxBuf,usRxCount);//如果没有LEd,输出输入字符串 } } usRxCount = 0; } 
Rxflag=0; } } } 
/******************************************************************************/ 
/* STM32F10x Peripherals Interrupt Handlers */ /* Add here the Interrupt 
Handler for the used peripheral(s) (PPP), for the */ /* available peripheral 
interrupt handler's name please refer to the startup */ /* file 
(startup_stm32f10x_xx.s). */ 
/******************************************************************************/ 
//外设中断处理函数 void USARTx_IRQHANDLER(void) { if(USART_GetITStatus(USARTx, 
USART_IT_RXNE) != RESET)//判断中断函数是否置位 { Rxflag=1; ucTemp = 
USART_ReceiveData(USARTx);//串口接收数据函数,一次一字节 } } 
如果大家有更好的办法欢迎讨论。