PDA

View Full Version : 2 decimal display on LCD



pt3rg
- 4th January 2004, 17:55
The following program:

ADCIN 0, PRE
PRE = (PRE */500)>>2
PRE = ((((PRE * 10/5) + 95)/9)

How do i display the result of PRE on a LCD, correct to 2 decimal values?

Assuming
1st case : PRE = 800
After the formula, PRE = 97.36111111
How to display "97.36" on LCD?

2nd case : PRE = 900
After the formula, PRE = 108.2118
How to display "108.22" on LCD?

Thank you.

Melanie
- 5th January 2004, 15:13
The secret to doing things like this is easily to scale your math. If you need two decimal places in the range 0-99.99 then just scale so your math produces results between 0-9999 (ie 100 times bigger than you need) and take the last two digits as your decimal places.

Whatever you do must however fit inside a word variable, so the biggest number you can play with is 65535 - therefore with this method to two decimal places, the biggest number you can have is 655.35

Melanie

pt3rg
- 5th January 2004, 18:47
Thanks, i've already figured out the code.

btw, how do i deal with numbers that are bigger than 65535?

Just curious though...

pt3rg
- 7th January 2004, 13:49
Just another question:

The 16877 uses the voltage supply as its reference voltage by default. Meaning that by default,

VREF- = 0V
VREF+ = 5V

How do i change the reference voltages? Is there a way where i can do it directly by just programming the PIC? Or do i need an external connection?

For example,change to

VREF- = 2.5
VREF+ = 4V

THanks.

mat janssen
- 7th January 2004, 15:28
If you look in the data sheet of the 877 then you see that
ADCON1 register can be set to a mode for Vref+ and Vref- and some other analog or digital inputs
page 112 of the data sheet
And if you put in you programm ADCON1 = %1enz
than you can programm you pins as you like.
succes