将float数据类型转换为str

时间:2021-08-17 15:54:35

示例程序:

  #include <stdio.h>

  .

  .

  void UART_send_byte(char dat);

  void UART_send_string(unsigned char *buf);

  .

  unsigned char TX_Buf[10];

  sprintf(TX_Buf,"D%f",Distance);

  UART_send_string(TX_Buf);

  Delay_ms(500);

  

  /*
  * UART 发送一字节
  */

  void UART_send_byte(char dat)
  {
    SBUF = dat;
    while (TI == 0);
    TI = 0;
  }

  /*
  * UART 发送字符串
  */
  void UART_send_string(unsigned char *buf)
  {
    while (*buf != '\0'){
      UART_send_byte(*buf++);
    }
  }