熬红了眼

导航

将float数据类型转换为str

示例程序:

  #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++);
    }
  }

 

posted on 2017-08-28 01:26  熬红了眼  阅读(976)  评论(0编辑  收藏  举报