【发布时间】:2020-03-27 16:31:52
【问题描述】:
我正在使用 PIC 并已成功通过 UART 接收到单个字符,但是我现在需要捕获传入的字符序列,建立一个字符串并在接收到 carrage return 后执行操作。我以前有一些 PHP 经验,我认为事情会比原来容易得多。
我已经使用正常工作的 UART 函数修改了我的简单代码,以尝试如下连接接收到的字符并构建一个字符串:
#include "mcc_generated_files/mcc.h"
#include "string.h"
unsigned char InChar;
char Temp[5];
char Command[32];
void UART_Demo_Command_INT(void)
{
if(eusartRxCount!=0)
{
InChar=EUSART_Read(); // read a byte for RX
strcat(Command,InChar); //concat Command with InChar, result in Command
printf = printf("Command String: %s \n", Command);
}
}
我收到了一些错误:
UART_Demo.c:115:24: warning: incompatible integer to pointer conversion passing 'unsigned char' to parameter of type 'const char *' [-Wint-conversion]
strcat(Command,InChar); //concat Command with InChar, result in Command
^~~~~~
C:\Program Files (x86)\Microchip\xc8\v2.10\pic\include\c99\string.h:36:55: note: passing argument to parameter here
char *strcat (char *__restrict, const char *__restrict);
^
UART_Demo.c:116:16: error: non-object type 'int (const char *restrict, ...)' is not assignable
printf = printf("Command String: %s \n", Command);
~~~~~~ ^
1 warning and 1 error generated.
在花了几个小时试图解决这个问题后,我希望你们中的一些人能提供帮助。
【问题讨论】:
标签: string concatenation pic uart