how to print a decimal value in lcd

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
rags
Posts: 29
Joined: Thu Dec 22, 2011 5:33 pm
Has thanked: 1 time

how to print a decimal value in lcd

Post by rags »

hello sir,

what function should i use to print a decimal value
for eg a=7
b=2
c=a/b and in lcd when i use print number(c) command i want the lcd display to show 3.5 but float is not supported pls help


regards
ragesh

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: how to print a decimal value in lcd

Post by medelec35 »

Hi ragesh,
I have moved topic so we can keep Tips section for posting tips, and not starting topic with a question question.

As for the Decimal point, take a look here:
http://www.matrixmultimedia.com/mmforum ... 326#p20298
There are two replies that should be able to help you.

With your example, I would 1st multiply a by 10 so you have got 70/2

Reason for that is with pic maths if not using float it will disreguard any remainders since bytes and intergers are whole numbers only.
so 7/2 = 3
not 3.5

Martin
Martin

rags
Posts: 29
Joined: Thu Dec 22, 2011 5:33 pm
Has thanked: 1 time

Re: how to print a decimal value in lcd

Post by rags »

hello sir,
as i am using flowcode for AVR can u please guide to a topic that deals my question with AVR
thank you!!

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: how to print a decimal value in lcd

Post by medelec35 »

You will be able to use import function from File/ Import to import pic versions of Flowcode.

Or do you mean you want this thread moved to Flowcode V4?

What version of AVR do you have (Help, About Flowcode menu)?

If the version is too early then you will not be able to import successfully.
Martin

rags
Posts: 29
Joined: Thu Dec 22, 2011 5:33 pm
Has thanked: 1 time

Re: how to print a decimal value in lcd

Post by rags »

sir,

i use flowcode v4..i have imported it..but i want to display a mathematical calculation in decimals not an ADC value..
say 7/2..i want 3.5 to be displayed in my LCD display

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: how to print a decimal value in lcd

Post by medelec35 »

Instead of adc, your using your own variables.
That flowchart was to show you a method of how it can be done, then you just create your own flowchart once you have learned the principles.

For that method you need to learn how Left$ and Right$ work.

Then as stated in my previous post
medelec35 wrote:
With your example, I would 1st multiply a by 10 so you have got 70/2

Reason for that is with pic maths if not using float it will disreguard any remainders since bytes and intergers are whole numbers only.
so 7/2 = 3
not 3.5


So 70/2=35
Convert to string then use Left$ and Right$ to separate the two digits.

Alternatively you can use the Mod function to separate the digits.
e.g

Code: Select all

Digit_0 = Voltage MOD 10
Digit_1 = Voltage / 10 MOD 10 
If your still stuck then I can post a flowchart to demonstrate both methods.
See if you can have a go first and post a flowchart, as that is a good learning method.

Martin
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: how to print a decimal value in lcd

Post by medelec35 »

Hi rags,
I have altered flowchart from link I had posted, to display the result with a decimal point.
It may not be perfect, but it should do what you’re after.
a div b v1.fcf
(8.5 KiB) Downloaded 457 times
Martin
Attachments
a div b v1.png
(75.89 KiB) Downloaded 4189 times
Martin

rags
Posts: 29
Joined: Thu Dec 22, 2011 5:33 pm
Has thanked: 1 time

Re: how to print a decimal value in lcd

Post by rags »

hello sir ,
thanks for your response , thanks a lot!

i tried and have come up with a better and very easy solution.
what i did was..
a=7
b=2
c=7/2

all variables are FLOAT,
initialze string variable str. then use string manuplation[ str=floattostring(c)] ; now in lcd print string--> str and the its accuracy is upto six decimals!
thank you,

reagrds
ragesh

rags
Posts: 29
Joined: Thu Dec 22, 2011 5:33 pm
Has thanked: 1 time

Re: how to print a decimal value in lcd

Post by rags »

sorry small typing mistake in previous post

it is c=a/b

and its NOT
c=7/2

rags
Posts: 29
Joined: Thu Dec 22, 2011 5:33 pm
Has thanked: 1 time

Re: how to print a decimal value in lcd

Post by rags »

i have attched a sample file.
i have used at,ega32 MCU
Attachments
print_adecimal.fcf_avr
(5.5 KiB) Downloaded 453 times

Post Reply