我正在尝试通过Beaglebone Black的UART0打印字符串。引导加载程序初始化了UART0,我只需要写字符。我已经编写了一个简单的函数。
void uart_put(unsigned char c)
{
while((UART0->LSR_r & 32) == 0);
UART0->THR = c;
}
从启动代码调用以下函数,在此函数中我只是打印字符。
#define SIZE_OF_ARRAY 7
int c_entry(void)
{
unsigned char s_name[SIZE_OF_ARRAY] = "Hello";
unsigned char a_name[SIZE_OF_ARRAY] = {'H','e','l','l','o','\0'};
unsigned int a_int[SIZE_OF_ARRAY] = {9,8,7,6,5,4};
int i = 0;
for(i = 0; i<6; i++)
{
uart_put('0'+i); /*print value of i*/
uart_put(9); /*print a tab*/
uart_put(s_name[i]); /*print char from string*/
uart_put(9); /*print a tab*/
uart_put(a_name[i]); /*print char from array*/
uart_put(9); /*print a tab*/
uart_put('0'+a_int[i]); /*print int from array*/
uart_put('\n');
uart_put('\r');
}
while(1);
return 0;
}
该函数的字符数组和整数的打印正常,但字符串的打印不正确。
![enter image description here](https://istack.dev59.com/ujapB.webp)
s_name[i] == a_name[i]
来确认字符打印之前的差异吗? - grek40