void UART1_int (void) interrupt UART1_VECTOR
{
if(RI)
{
RI = 0;
if(COM1.B_RX_OK == 0)
{
if(COM1.RX_Cnt >= COM_RX1_Lenth) COM1.RX_Cnt = 0;
RX1_Buffer[COM1.RX_Cnt++] = SBUF;
COM1.RX_TimeOut = TimeOutSet1;
}
}
if(TI)
{
TI = 0;
if(COM1.TX_read != COM1.TX_write)
{
SBUF = TX1_Buffer[COM1.TX_read];
if(++COM1.TX_read >= COM_TX1_Lenth) COM1.TX_read = 0;
}
else COM1.B_TX_busy = 0;
}
}
void Usart_Send(u8 *dat,u8 len)
{
u8 i;
for(i=0;i<len;i++)
{
TX1_write2buff(*dat);
dat++;
}
}
unsigned char Float2Char(float value, unsigned char *array)
{
u16 IntegerPart;
float DecimalPart;
u8 i = 0;
u8 j = 0;
char temp;
if(value >= 1)
{
IntegerPart = (u16)value;
DecimalPart = value - IntegerPart;
}
else
{
IntegerPart = 0;
DecimalPart = value - IntegerPart;
}
if(IntegerPart==0)
{
array[0]='0';
array[1]='.';
i=1;
}
else
{
while(IntegerPart>0)
{
array[i]=IntegerPart%10+'0';
IntegerPart/=10;
i++;
}
i--;
for(j=0;j<i;j++)
{
temp=array[j];
array[j]=array[i-j];
array[i-j]=temp;
}
i++;
array[i] = '.';
}
i++;
array[i++] = (u32)(DecimalPart * 10)%10 + '0';
array[i++] = (u32)(DecimalPart * 100)%10 + '0';
array[i++] = (u32)(DecimalPart * 1000)%10 + '0';
array[i++] = (u32)(DecimalPart * 10000)%10 + '0';
array[i++] = (u32)(DecimalPart * 100000)%10 + '0';
array[i++] = (u32)(DecimalPart * 1000000)%10 + '0';
array[i] = '\0';
return i;
}
Len_Num=Float2Char(adj_value,R_buf);
Usart_Send(R_buf,Len_Num);使用函数