2 decimal display on LCD


Closed Thread
Results 1 to 5 of 5
  1. #1
    pt3rg's Avatar
    pt3rg Guest

    Post 2 decimal display on LCD

    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.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    pt3rg's Avatar
    pt3rg Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks, i've already figured out the code.

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

    Just curious though...

  4. #4
    pt3rg's Avatar
    pt3rg Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by mat janssen; - 7th January 2004 at 14:38.

Similar Threads

  1. Replies: 14
    Last Post: - 26th September 2007, 05:41
  2. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  3. LCD Display not working - PIC heating...
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 24th September 2006, 07:35
  4. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22
  5. A/D display result on LCD
    By winsthon in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 10th January 2004, 10:09

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts