This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
我使用 CCS 启用 SCI、
并制作一个小程序,尝试显示十六进制细节与我收到的其他接口,
例如 UART (或 SCI?) /SPI/I2c 或 CAN
因此、我的变量是 uint16_t
如何以十六进制而不是8位字符显示接收内容。
uint16_t rData = 0; uint16_t receivedChar; unsigned char *msg; rData= 31; //want to show 1F instead of 31 msg=(rData<<8); //fail msg=(rData)&0xFF; //fail SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 13);
如果 RDATA 为49、则 SCI_WRITE 将显示1
如果 RDATA 为31、SCI 写入将不显示任何内容(因为 49不是8位字符)
是否可以显示无符号 int 内容
就像31=0x1F (我要显示的内容)
我尝试了 include stdio.h 和 snprintf 、但失败了。
尊敬的 CK:
您是否将此数据发送到计算机的 UART COM 端口? 这似乎与接收端的编码更相关、因为 MCU 将以按位方式发送数据。 您可以使用 https://docklight.de/ 更 方便地查看 UART 数据并更改编码
此致、
Peter
感谢您回复、
看起来 SCI_WRITE 不能像 printf 或 snprint 那样轻松完成。
我是否正确?
我只是解决了它,
static char hex_digits2[] = "0123456789ABCDEF"; void uint16tohex(uint16_t indata, uint16_t tail){ unsigned char* msg; msg=(unsigned char*)&hex_digits2[(indata >> 4) & 0x0F]; SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 1); msg=(unsigned char*)&hex_digits2[indata & 0x0F]; SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 1); if(tail==0){ msg="-"; SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 1); }else { msg="\r\n"; SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 4); } }
然后调用 uint16tohex (RDATA、0或1)
打印我收到的十六进制值。