求教:诺基亚5110液晶如何显示变量?
我想在诺基亚5110上显示个浮点型变量,要怎么进行转换显示呢,弄了老半天都不行,请大虾们求教……或者有这方面资料的希望共享下,谢谢了·····
最笨的办法就是找个数组。
然后定长定点 用求余求模 计算每一位的数字。
变长变小数点就需要另外计算位数。。
我也是新手只知道这些了 楼主慢慢来,不要急 首先你做出一个能显示字符串的函数,然后将浮点数转换为字符串显示即可!
sprintf()? vsprintf()? qinkaiabc 发表于 2013-8-18 23:54 static/image/common/back.gif
楼主慢慢来,不要急
太好了,万分感谢! 我去研究了。 techbaby 发表于 2013-8-18 23:58 static/image/common/back.gif
首先你做出一个能显示字符串的函数,然后将浮点数转换为字符串显示即可!
sprintf()? vsprintf()? ...
对了,在这里我顺便想问下显示字符串函数调用的是下面这个:
void write_english_string(uchar X,uchar Y,uchar *s)
{
LCD_set_XY(X,Y);
while(*s)
{
LCD_write_char(*s);
s++;
}
}
对变量 sudu我想保留两位数小数
于是我定义 uint sudu0;float sudu; uchar v;
sudu=sudu0/100;
v=(char)sudu;
write_english_string(25,1,&v); 为什么这样不能显示呢? glacier1 发表于 2013-8-18 23:52 static/image/common/back.gif
最笨的办法就是找个数组。
然后定长定点 用求余求模 计算每一位的数字。
恩,同样感谢,刚才有在别人的例程看到这样的求法 char a={'0','1','2','3','4','5','6','7','8','9'};
void LCD_write_english_int(unsigned char X,unsigned char Y,char s)
{
LCD_set_XY(X,Y);
LCD_write_char(s);
}
LCD_write_english_int(0,3,a); 同求、、、楼主弄好了没?求教、、、 qqwangte 发表于 2013-8-19 23:32 static/image/common/back.gif
同求、、、楼主弄好了没?求教、、、
恩,已经调好了,就是用数组的方法。
首先设定一个数组:
uchar tempstr={0x30,0x30,0x30,0x30,0x30,0x30,0x30} ; //初始化 为0;
然后对你所求的变量进行分解
例如我所求的变量为V
tempstr=v/100+0x30;
tempstr=v%100/10+0x30;
tempstr=v%10+0x30;
显示时则调用:
LCD_write_char(tempstr);
write_english_string(32,1,".");
LCD_write_char(tempstr);
LCD_write_char(tempstr);
write_english_string(52,1,"m/s");
以下为相关的调用函数
void LCD_write_char(uchar c) //写单个字符
{
uchar line;
c=c-32;
for(line=0;line<6;line++)
LCD_write_byte(font6x8,1);
}
void write_english_string(uchar X,uchar Y,uchar *s) //写 字符串
{
uchar i;
LCD_set_XY(X,Y);
for(i=0;i<strlen(s);i++)
{
LCD_write_char(s);
}
}
根据楼上的代码我也成功显示了,上面的代码只能显示三位。如果不知道位数的话该怎么写代码?我用Arduino的库函数 lcd.print(t)t是个变量,假如t=99511那么就输出99511,如果t=79.16那么就输出79.16,这种代码怎么写的?还可以这样输出 lcd.print("t")就输出个t。。。
而且前面的0没法消掉啊
void LCD_write_count(unsigned long int count)
{
unsigned char tempstr={0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30} ;
//将count送入缓冲区
tempstr=count/10000000+0x30;
tempstr=count%10000000/1000000+0x30;
tempstr=count%10000000%1000000/100000+0x30;
tempstr=count%10000000%1000000%100000/10000+0x30;
tempstr=count%10000000%1000000%100000%10000/1000+0x30;
tempstr=count%10000000%1000000%100000%10000%1000/100+0x30;
tempstr=count%10000000%1000000%100000%10000%1000%100/10+0x30;
tempstr=count%10000000%1000000%100000%10000%1000%100%10+0x30;
//判断count显示位数
if(count>10000000)
{
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
}
else if((10000000>count)&&(count>=1000000))
{
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
}
else if((1000000>count)&&(count>=100000))
{
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
}
else if((100000>count)&&(count>=10000))
{
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
}
else if((10000>count)&&(count>=1000))
{
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
}
else if((1000>count)&&(count>=100))
{
LCD_write_char(tempstr);
LCD_write_char(tempstr);
LCD_write_char(tempstr);
}
else if((100>count)&&(count>=10))
{
LCD_write_char(tempstr);
LCD_write_char(tempstr);
}
else
{
LCD_write_char(tempstr);
}
}
这是我写的,亲测可用~~~求交流指点啊,我是新手啊 浮点数扩大N倍变成整数,然后再求模显示。
页:
[1]