搜索
bottom↓
回复: 14

求教:诺基亚5110液晶如何显示变量?

[复制链接]

出0入0汤圆

发表于 2013-8-18 23:50:12 | 显示全部楼层 |阅读模式
       我想在诺基亚5110上显示个浮点型变量,要怎么进行转换显示呢,弄了老半天都不行,请大虾们求教……
       或者有这方面资料的希望共享下,谢谢了·····

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

发表于 2013-8-18 23:52:17 | 显示全部楼层
最笨的办法就是  找个数组。
然后  定长定点       用求余求模      计算每一位的数字。

变长变小数点就需要另外计算位数。。

我也是新手只知道这些了

出0入0汤圆

发表于 2013-8-18 23:54:19 | 显示全部楼层
楼主慢慢来,不要急

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出20入70汤圆

发表于 2013-8-18 23:58:13 | 显示全部楼层
首先你做出一个能显示字符串的函数,然后将浮点数转换为字符串显示即可!

sprintf()?   vsprintf()?

出0入0汤圆

 楼主| 发表于 2013-8-19 00:00:35 | 显示全部楼层
qinkaiabc 发表于 2013-8-18 23:54
楼主慢慢来,不要急

太好了,万分感谢! 我去研究了。

出0入0汤圆

 楼主| 发表于 2013-8-19 00:11:09 | 显示全部楼层
techbaby 发表于 2013-8-18 23:58
首先你做出一个能显示字符串的函数,然后将浮点数转换为字符串显示即可!

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);   为什么这样不能显示呢?

出0入0汤圆

 楼主| 发表于 2013-8-19 00:13:13 | 显示全部楼层
glacier1 发表于 2013-8-18 23:52
最笨的办法就是  找个数组。
然后  定长定点       用求余求模      计算每一位的数字。

恩,同样感谢,刚才有在别人的例程看到这样的求法

出0入0汤圆

发表于 2013-8-19 09:36:05 | 显示全部楼层
char a[10]={'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[i]);

出0入0汤圆

发表于 2013-8-19 23:32:02 | 显示全部楼层
同求、、、楼主弄好了没?求教、、、

出0入0汤圆

 楼主| 发表于 2013-8-21 20:02:21 | 显示全部楼层
qqwangte 发表于 2013-8-19 23:32
同求、、、楼主弄好了没?求教、、、

恩,已经调好了,就是用数组的方法。
首先设定一个数组:
uchar tempstr[7]={0x30,0x30,0x30,0x30,0x30,0x30,0x30} ;    //初始化 为0;
然后对你所求的变量进行分解
例如我所求的变量为V
        tempstr[0]=v/100+0x30;
        tempstr[1]=v%100/10+0x30;
        tempstr[2]=v%10+0x30;

显示时则调用:

         LCD_write_char(tempstr[0]);
         write_english_string(32,1,".");
        LCD_write_char(tempstr[1]);
        LCD_write_char(tempstr[2]);
        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[c][line],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);
        }
}

出0入0汤圆

发表于 2014-8-21 22:14:32 | 显示全部楼层
根据楼上的代码我也成功显示了,上面的代码只能显示三位。如果不知道位数的话该怎么写代码?  我用Arduino的库函数 lcd.print(t)  t是个变量,假如t=99511那么就输出99511,如果t=79.16那么就输出79.16,这种代码怎么写的?还可以这样输出 lcd.print("t")就输出个t。。。

出0入0汤圆

发表于 2014-8-21 22:28:41 | 显示全部楼层
而且前面的0没法消掉啊

出0入0汤圆

发表于 2014-8-22 15:50:51 | 显示全部楼层
void LCD_write_count(unsigned long int count)
{
                unsigned char tempstr[9]={0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30} ;
        //将count送入缓冲区
              tempstr[0]=count/10000000+0x30;
              tempstr[1]=count%10000000/1000000+0x30;
              tempstr[2]=count%10000000%1000000/100000+0x30;
              tempstr[3]=count%10000000%1000000%100000/10000+0x30;
              tempstr[4]=count%10000000%1000000%100000%10000/1000+0x30;
              tempstr[5]=count%10000000%1000000%100000%10000%1000/100+0x30;
              tempstr[6]=count%10000000%1000000%100000%10000%1000%100/10+0x30;
              tempstr[7]=count%10000000%1000000%100000%10000%1000%100%10+0x30;
   //判断count显示位数
         if(count>10000000)
                     {

                             LCD_write_char(tempstr[0]);
                             LCD_write_char(tempstr[1]);
                             LCD_write_char(tempstr[2]);
                             LCD_write_char(tempstr[3]);
                             LCD_write_char(tempstr[4]);
                             LCD_write_char(tempstr[5]);
                             LCD_write_char(tempstr[6]);
                             LCD_write_char(tempstr[7]);
                     }

                     else if((10000000>count)&&(count>=1000000))
                     {

                              LCD_write_char(tempstr[1]);
                              LCD_write_char(tempstr[2]);
                              LCD_write_char(tempstr[3]);
                              LCD_write_char(tempstr[4]);
                              LCD_write_char(tempstr[5]);
                              LCD_write_char(tempstr[6]);
                              LCD_write_char(tempstr[7]);

                     }
                     else if((1000000>count)&&(count>=100000))
                     {
                             LCD_write_char(tempstr[2]);
                             LCD_write_char(tempstr[3]);
                             LCD_write_char(tempstr[4]);
                             LCD_write_char(tempstr[5]);
                             LCD_write_char(tempstr[6]);
                             LCD_write_char(tempstr[7]);

                     }
                     else if((100000>count)&&(count>=10000))
                     {

                             LCD_write_char(tempstr[3]);
                         LCD_write_char(tempstr[4]);
                         LCD_write_char(tempstr[5]);
                         LCD_write_char(tempstr[6]);
                         LCD_write_char(tempstr[7]);
                     }
                     else if((10000>count)&&(count>=1000))
                     {

                             LCD_write_char(tempstr[4]);
                             LCD_write_char(tempstr[5]);
                             LCD_write_char(tempstr[6]);
                             LCD_write_char(tempstr[7]);
                     }
                     else if((1000>count)&&(count>=100))
                     {

                              LCD_write_char(tempstr[5]);
                              LCD_write_char(tempstr[6]);
                              LCD_write_char(tempstr[7]);
                     }
                     else if((100>count)&&(count>=10))
                     {

                              LCD_write_char(tempstr[6]);
                              LCD_write_char(tempstr[7]);
                     }
                     else
                     {

                             LCD_write_char(tempstr[7]);
                     }
}

出0入0汤圆

发表于 2014-8-22 15:51:38 | 显示全部楼层
这是我写的,亲测可用~~~求交流指点啊,我是新手啊

出0入0汤圆

发表于 2014-8-24 17:27:48 | 显示全部楼层
浮点数扩大N倍变成整数,然后再求模显示。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-26 01:04

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表