示例程序:
#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 != ' '){
UART_send_byte(*buf++);
}
}