USART_SendArray(DEBUG_USARTx , a,10);没能输出a[10]中的元素?
在串口试验中,USART_SendArray(DEBUG_USARTx , a,10);没能输出a中的元素?例程中编写了以下程序,#include "stm32f10x.h"#include "bsp_led.h"#include "bsp_usart.h"int main(){ uint8_t ch; uint8_t a={1,2,3,4,5,6,7,8,9,10}; USART_Config(); USART_SendByte(DEBUG_USARTx , 0x64);//01100100 printf("\n"); USART_Send2Byte(DEBUG_USARTx , 0xff56); printf("\n"); USART_SendArray(DEBUG_USARTx , a,10); printf("\n"); USART_SendString(DEBUG_USARTx, "sendString"); printf("\n"); printf("chuankou printf函数测试\n"); putchar('b'); printf("\n"); while(1) {// ch = getchar(); ch = '1'; printf("ch = %c\n",ch); switch(ch) { case '1':LED_GREEN; break; case '2':LED_BLUE; break; case '3':LED_RED; break; default:LED_RGBOFF; break; } }} 我debug测试结果如下:dV schuankou printf函数测试bch = 1 问题是:USART_SendByte(DEBUG_USARTx , 0x64);//01100100输出结果是d USART_Send2Byte(DEBUG_USARTx , 0xff56);输出结果是 V USART_SendArray(DEBUG_USARTx , a,10);没能输出a中的元素。 USART_SendString(DEBUG_USARTx, "sendString");只输出了一个 s就没有了?本帖最后由 stm1024 于 2019-4-22 22:47 编辑
我想问一下,这个函数的定义是什么、
还有个问题是,你采用的是字符形式的显示,而在ASCII码中,0x20以前的都是不可打印字符,建议你用HEX形式显示看看,或者把a改成{0x30,0x31,...0x39},这样就可以显示0-9的字符了
本帖最后由 wenyangzeng 于 2019-4-23 11:52 编辑
数组a是从a到a而已,不包括a,要输出ASCII的0-9,应该把a+0x30; wenyangzeng 发表于 2019-4-23 11:50
数组a是从a到a而已,不包括a,要输出ASCII的0-9,应该把a+0x30;
USART_SendArray(DEBUG_USARTx , a,10);
for(ch=0;ch<10;ch++)
{printf("a[%d]=%d\n",ch,a);
}
这回打印出来了。感谢。
页:
[1]