STM32
直播中

杨勇

8年用户 1271经验值
私信 关注
[问答]

USART_SendArray(DEBUG_USARTx , a,10)没能输出a[10]中的元素是怎么回事?

在串口试验中,USART_SendArray(DEBUG_USARTx , a,10);没能输出a[10]中的元素?

例程中编写了以下程序,

#include "STM32f10x.h"

#include "bsp_led.h"

#include "bsp_usart.h"

int main()

{

        uint8_t ch;        

        uint8_t a[10]={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 = %cn",ch);

                switch(ch)

                {

                        case '1'ED_GREEN;

                                break;

                        case '2'ED_BLUE;

                                break;

                        case '3'ED_RED;

                                break;

                        default{:10:}ED_RGBOFF;

                                break;                

                }

        }

}        

debug测试结果如下:

d

V

        


s

chuankou printf函数测试

b

ch = 1


问题是:

USART_SendByte(DEBUG_USARTx , 0x64);//01100100

输出结果是d

        USART_Send2Byte(DEBUG_USARTx , 0xff56);

输出结果是 V

        USART_SendArray(DEBUG_USARTx , a,10);

没能输出a[10]中的元素。

        USART_SendString(DEBUG_USARTx, "sendString");

只输出了一个 s就没有了?



回帖(1)

陈秀珍

2024-4-22 14:28:36
数组a[10]是从a[0]到a[9]而已,不包括a[10],要输出ASCII的0-9,应该把a[n]+0x30;


USART_SendArray(DEBUG_USARTx , a,10);

        for(ch=0;ch<10;ch++)
        {printf("a[%d]=%dn",ch,a[ch]);        
        }
举报

更多回帖

发帖
×
20
完善资料,
赚取积分