- typedef unsigned char uint8;
- typedef unsigned int uint16;
- void main()
- {
- float value = 3.142;
-
- SendByte(((uint8)value % 100)/10 + 48); //输出十位
- SendByte(((uint8)value) % 10 + 48); //输出个位
- SendByte(0x2E); //输出小数点
- SendByte(((uint16)(value*10)) % 10 + 48); //输出十分位
- SendByte(((uint16)(value*100)) % 10 + 48); //输出百分位
- SendByte(((uint16)(value*1000)) % 10 + 48); //输出千分位
- }
- void SendByte(uint8 c) //以51单片机为例。不同接收设备或通信方式可自定义
- {
- SBUF = c; //存入发送缓冲,移位寄存器将自动发送
- while(!TI); //等待数据发送完成
- TI = 0;
- }
|