在代码部分中,stringData++ 行似乎根本没有增加指针。我有什么遗漏的吗?
bool WriteString(const char* stringData)
{
if(*stringData == '\0')
{
return true;
}
/* Write a character at a time, only if transmitter is empty */
while (PLIB_USART_TransmitterIsEmpty(USART_ID_1))
{
/* Send character */
PLIB_USART_TransmitterByteSend(USART_ID_1, *stringData);
/* Increment to address of next character */
stringData++;
if(*stringData == '\0')
{
return true;
}
}
return false;
}
下面是默认的示例代码,可以使用
bool WriteString(void)
{
if(*appData.stringPointer == '\0')
{
return true;
}
/* Write a character at a time, only if transmitter is empty */
while (PLIB_USART_TransmitterIsEmpty(USART_ID_2))
{
/* Send character */
PLIB_USART_TransmitterByteSend(USART_ID_2, *appData.stringPointer);
/* Increment to address of next character */
appData.stringPointer++;
if(*appData.stringPointer == '\0')
{
return true;
}
}
return false;
}
这里的“appData”只是一个结构实例,其中有一个 const char 指针。
最佳答案
只是为了确认代码没问题并且确实增加了指针。我错误地认为问题是因为指针没有增加。经过进一步调试,发现是硬件时序问题。详情请参阅上面的评论。
关于c - 无法增加指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41902250/