1602 lcd程序已调试好,能显示出任意字符串
rs=1;
for (i = 0; Message != 0; i++)
LCDWrite(Message);
但不能够把计算出来的值显示出来,这里找到的程序也没有提及
现在情况是pic读取adc的值并把它真实值计算出来,并存入变量double x
假设存入x为12.345
如何把12.345显示出来到lcd出来?
用picc编译
#include <stdio.h>
double x=12.345;
char Buffer[10];
sprintf (Buffer, "%f", x);
for (i=0;Buffer!=0;i++)
LCDWrite(Buffer, 1);
picc看似无法编译double和%f,从watch window上面看变量数值,x的不是值12.345..
这个问题要如何解决??
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
unsigned char sprint(unsigned char *buffer, float x)
{
unsigned char i = 0, j = 0;
if(x < 0.0)
{
buffer[j++] = '-';
//x = -x;
//x *= -1.0;
x = fabs(x);//三者取一种
}
if(x > 1.0)
{
while(x > 10.0)
{
x /= 10.0;
i += 1;
}
do
{
buffer[j++] = '0' + (unsigned char)floor(x);
x -= floor(x);
x *= 10.0;
}while(i--);
buffer[j++] = '.';
if(j > ( ('-'==buffer[0]) ? WEISHU+1 : WEISHU))
{
buffer[j++] = '0';
buffer[j++] = ' ';
}
else
{
while(j < ( ('-'==buffer[0]) ? WEISHU+2 : WEISHU+1))
{
buffer[j++] = '0' + (unsigned char)floor(x);
x -= floor(x);
x *= 10.0;
}
buffer[j++] = ' ';
}
}
else
{
buffer[j++] = '.';
do
{
buffer[j++] = '0';
x *= 10.0;
}while(x < 1.0);
for(i=0;i<WEISHU;++i)
{
buffer[j++] = '0' + (unsigned char)floor(x);
x -= floor(x);
x *= 10.0;
}
buffer[j++] = ' ';
}
return j;
}
一周热门 更多>