4x3 keypad and an LCD.. need help.


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    If you must have floating points there is a routine over at the MeLabs site.

    The easy way for what you are doing is to drop the decimal point.
    x = 2 * 1.5

    would be
    x = 2 * 15 / 10

    Then if you are wanting to display a 3.0
    Code:
    LCDOUT, $FE;1,DEC x,".",DEC2 x//100
    65535 is the largest value for a WORD size variable. So 125000 over flows, comes back around starting at zero and the result is 59464.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Dec 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    i tried the codes but the lcd displaying 3.03.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    OOPPS, I was not thinking straight

    What we are doing.
    Take the number with one decimal place and multiply by 10 before the PIC sees it.
    1.5 is now 15
    1.6 is now 16
    ...
    Code:
    x = 2 * 16
    lcdout $FE,1,DEC x / 10,".",DEC x//10
    In the above the "x / 10" will return 3.
    x//10 will return the remainder 2.

    Look in the Pic Basic manual under Math Operators for more fun/confusing stuff
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Dec 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    thanks! that info really helps me..
    But i still got another problem. if the equation goes like this x = 26 // 21.. the answer should be 238095238, the decimal part cannot read by the program and the answer is wrong because the limit is 65535 right? how to get the right answer like display 238 only? thanks again..

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    In this case the decimal needs moved three places to the right.
    26/21=1.238095...
    1000*26/21=1238.095...
    x = (1000*26/21)//1000
    x=238

    You could have
    Code:
    y=26
    x = (1000*y/21)//1000
    The above will only work if "y" is an integer 22 through 41.
    When reading a sensor the range of values are fixed so with a little imagination a constant like in the above case 1000 will work. When another application comes along with a different set of values a different constant and equation will be required.

    What is your application besides a keypad?
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit
    You could have

    Code:
    y=26
    x = (1000*y/21)//1000
    The above will only work if "y" is an integer 22 through 41.
    I'm not sure why any value 0 - 65 will not satisfy your equation. The only requirement to keep it "legal" is to keep 1000*y under 65535. Also if you can afford to loose one digit after the decimal point (0.00x) then the range for y will be 0 – 650.
    I guess knowing more about the application will help make the best decision.

    Regards,

    Nick

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Nicmus View Post
    I'm not sure why any value 0 - 65 will not satisfy your equation. The only requirement to keep it "legal" is to keep 1000*y under 65535. Also if you can afford to loose one digit after the decimal point (0.00x) then the range for y will be 0 – 650.
    I guess knowing more about the application will help make the best decision.

    Regards,

    Nick
    I should have said 2 - 41 .
    Beyond these values you run into the leading zero problem with the equation I gave.
    Some values above 41 will work, some will return 0.0xx. The 0 tenths is the problem.
    Thanks for catching that.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

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