Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Displaying float value with more than 4 decimal points on LCD

Status
Not open for further replies.
hello,

this kind of conversion will not work in every cases
example in post #16 will work only for value > 0 and < 99.9999
bad if 0.3244 => gives 00.3244 and bad for 199.1234 => gives 99.1234

example in post #20 is the same case , not cover all values..
and you must add 0x30 or '0' to the digit value to get an ascii
Code:
Lcd_chr(4,3,0+digit);
  must be
  Lcd_chr(4,3,'0'+digit);

i suppose your Lcd_chr as parameters as ( line number, caractere position, caractere)
and when you use Lcd_chr_cp('.'); you write on the current cursor position ?
Do you have automatic increment of cursor inside your LCD init ?

so a lot of pending probem !

my last opinion about this thread.. use the code in post #7
allready tested in many application..
Check if you have automatic increment of cursor after writing a car on the LCD.
To write the ascii result of float
Put the cursor at the begining of a line
after just use Lcd_chr_cp(car);, no need to put again line number and X position.


Code:
unsigned char CRam1[32];
float F1;
int k;

.. see float conversion in post #7 ....

F1=0.3244;

....

fltToa(F1,CRam1,4);  // 4 decimales
k=strlen(CRam1;

// put here LCD function to put the cursor position at line 4,0
...... 
for (i=0;i<k;i++)
{
 Lcd_chr_cp(CRam1[i]);
}
 

Ok thanks. These functions are built in MiroC pro. I guess they have auto increment function. I'll try again the code in post #7.
 

I tried your code but the fprintf is not available in MikroC

- - - Updated - - -

I tried zsolt1's method it seems to be easy to understand. Its working fine. So thought of using his method. Thank you very much zsolt1.

Code:
void Energydisplay(double V){

  unsigned char a,b,c,d,d1,d2,d3,d4;
  double n;
  
   a=V/1000;
   b=(V-(1000*a))/100;
   c=(V-(1000*a)-(100*b))/10;
   d=V-(1000*a)-(100*b)-(10*c);
   n=(V-(1000*a)-(100*b)-(10*c)-d)*10000;
   d1=n/1000;
   d2=(n-(d1*1000))/100;
   d3=(n-(d1*1000)-(d2*100))/10;
   d4=n-(d1*1000)-(d2*100)-(d3*10);
   
   Lcd_Chr(4,5,a+48);
   Lcd_Chr(4,6,b+48);
   Lcd_Chr(4,7,c+48);
   Lcd_Chr(4,8,d+48);
   Lcd_Chr_CP('.');
   Lcd_Chr(4,10,d1+48);
   Lcd_Chr(4,11,d2+48);
   Lcd_Chr(4,12,d3+48);
   Lcd_Chr(4,13,d4+48);
   }
 
Last edited:

One problem, it displays some garbage data when v=0000.000, how do I solve it?

- - - Updated - - -

I solved it in the following way. This is my new code:
Code:
void Energydisplay(double V){

  unsigned char a,b,c,d,d1,d2,d3,d4;
  double n;
   if(v==0000.00){
   Lcd_Chr(4,5,48);
   Lcd_Chr(4,6,48);
   Lcd_Chr(4,7,48);
   Lcd_Chr(4,8,48);
   Lcd_Chr_CP('.');
   Lcd_Chr(4,10,48);
   Lcd_Chr(4,11,48);
   Lcd_Chr(4,12,48);
   }
   else{
   a=V/1000;
   b=(V-(1000*a))/100;
   c=(V-(1000*a)-(100*b))/10;
   d=V-(1000*a)-(100*b)-(10*c);
   
   n=(V-(1000*a)-(100*b)-(10*c)-d)*10000;
   d1=n/1000;
   d2=(n-(d1*1000))/100;
   d3=(n-(d1*1000)-(d2*100))/10;

   Lcd_Chr(4,5,a+48);
   Lcd_Chr(4,6,b+48);
   Lcd_Chr(4,7,c+48);
   Lcd_Chr(4,8,d+48);
   Lcd_Chr_CP('.');
   Lcd_Chr(4,10,d1+48);
   Lcd_Chr(4,11,d2+48);
   Lcd_Chr(4,12,d3+48);
  }
   }
Any ideas that I can make it simple?
 

One problem, it displays some garbage data when v=0000.000, how do I solve it?

- - - Updated - - -

I solved it in the following way. This is my new code:
Code:
void Energydisplay(double V){

  unsigned char a,b,c,d,d1,d2,d3,d4;
  double n;
   if(v==0000.00){
   Lcd_Chr(4,5,48);
   Lcd_Chr(4,6,48);
   Lcd_Chr(4,7,48);
   Lcd_Chr(4,8,48);
   Lcd_Chr_CP('.');
   Lcd_Chr(4,10,48);
   Lcd_Chr(4,11,48);
   Lcd_Chr(4,12,48);
   }
   else{
   a=V/1000;
   b=(V-(1000*a))/100;
   c=(V-(1000*a)-(100*b))/10;
   d=V-(1000*a)-(100*b)-(10*c);
   
   n=(V-(1000*a)-(100*b)-(10*c)-d)*10000;
   d1=n/1000;
   d2=(n-(d1*1000))/100;
   d3=(n-(d1*1000)-(d2*100))/10;

   Lcd_Chr(4,5,a+48);
   Lcd_Chr(4,6,b+48);
   Lcd_Chr(4,7,c+48);
   Lcd_Chr(4,8,d+48);
   Lcd_Chr_CP('.');
   Lcd_Chr(4,10,d1+48);
   Lcd_Chr(4,11,d2+48);
   Lcd_Chr(4,12,d3+48);
  }
   }
Any ideas that I can make it simple?

you don't need anymore d4?
Ps: it is a good practice to declare variables initializing them at the same time by 0 like
unsigned char a=0,b=0,c=0,d=0,d1=0,d2=0,d3=0,d4=0; this way you can be shore that everything starts from 0 ....
48 decimal is the character '0' in ascii, so when you send to the display the value (48+y)dec, if y\[\in\][0 .......9], you can display the caracters from 48 to 57 from the table , any other value for y wil display something else (check ascii table on the net)
 
Last edited:

Big Float value using mikroC.

https://www.mikroe.com/forum/viewtopic.php?f=13&t=32369

I converted it to display Integers.

100702d1389142988-bigfont.png


100703d1389145622-bigfont2.png
 

Attachments

  • bigFont.png
    bigFont.png
    40.3 KB · Views: 89
  • bigFont2.png
    bigFont2.png
    9.3 KB · Views: 85
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top