新手入门
- 积分
- 14
- 金钱
- 14
- 注册时间
- 2016-5-19
- 在线时间
- 14 小时
|
5金钱
/***************** 发送一个字符 **********************/
static void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch )
{
/* 发送一个字节数据到USARTx */
USART_SendData(pUSARTx,ch);
/* 等待发送完毕 */
while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
}
/***************** 发送字符串 **********************/
void Usart_SendString( USART_TypeDef * pUSARTx, uint8_t *str)
{
unsigned int k=0;
do
{
Usart_SendByte( pUSARTx, *(str + k) );
k++;
} while(*(str + k)!='\0');
}
int main(void)
{
//初始化延时函数
delay_init(180);
//初始化串口,波特率设置为115200
My_USART1_Init();
//初始化LED
LED_Init();
//开启红灯
LED_RED=0;
LED_RED=1;
Usart_SendString( USART2, (uint8_t *)"ATD10086;\r\n" );
USART_Cmd(USART2 ,DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,DISABLE);//使能USART2时钟
LED_RED=0;
while(1)
{
}
}
这是我的代码,Usart_SendString()函数输出字符串,但是明明加了\r\n,输出在串口调试助手上的还是没有显示换行!求大神帮忙看看错在哪里,或者其他还有什么方法
|
最佳答案
查看完整内容[请看2#楼]
你的 Usart_SendString()应该修改为:
void Usart_SendString( USART_TypeDef * pUSARTx, uint8_t *str)
{
while(*str ) //内容不为“空”
{
Usart_SendByte( pUSARTx, *str );
str++;
}
}
|