Shop OBEX P1 Docs P2 Docs Learn Events
Any way to use built-in conversion functions? — Parallax Forums

Any way to use built-in conversion functions?

JextsJexts Posts: 2
edited 2005-11-08 17:46 in BASIC Stamp
I am using a Parallel LCD (with a T6963C controller) and need to display numbers. The functions I really need are already connected to the DEBUG/SEROUT commands (DEC, DIG, SDEC, etc.), but I can't use them outside of the functions (IE. I can't do a strout = [noparse][[/noparse] DEC char DIG 5 ], but I could do a DEBUG [noparse][[/noparse] DEC char DIG 5 ] ) Is there a way to call these functions some how, or do I have to recreate the wheel??

Thanks.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-11-08 05:38
    Jexts -

    Unfortunately you don't seem to state exactly what it is you're trying to achieve, but, by way of example, DEC 5 is valid within a SEROUT or DEBUG statement. As a bit of additional information, if this is the problem, DEBUG and SEROUT 16 provide the same output, as shown below:

    Equivalent Commands:

    Debug NUMBR, "NUMBER =", DEC 3
    SEROUT 16, baudmode, [noparse][[/noparse]"NUM =", DEC 3]

    Lastly, built-in functions (DIG being one of them) are valid anywhere in the program. I'm just not sure ho you want to apply that?

    Regards,

    Bruce Bates
  • JextsJexts Posts: 2
    edited 2005-11-08 05:57
    Bruce, THanks for the reply.


    What I really need is a way to convert a value stored in a Word VAR into a string that I can then send to a Parallel LCD. So.... The code that I really need is something like:

    v1 = 43
    chars = DEC v1
    GOSUB LCDputString

    This code does not pass the syntax checker. I get an "Expected a constant, variable, uniary operator, or '('" error at the "DEC" part of the line..... so I have not found that the built-in functions are valid anywhere as you say they are.....would be great if they were, but doesn't seem to work for me. This is for a BS2 using PBasic 2.5. So not sure what I'm doing wrong...

    Cheers,
    John
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-11-08 07:00
    John -

    You would seem to imply that only strings can be displayed on a parallel LCD. Let me assure you, that is not the case. You can display anything you choose to. OTOH, there are times when you may want to convert from string format to numeric format.

    If you want to convert a string value to a numeric value or visa versa, adding and/or subtracting $30 (ASCII zero as I remember) will do that for you. Using alphameric data in a math statement is perfectly acceptable, since all data is seen as binary.

    Here is an incomplete subroutine which uses that technique for an "N" width string:

    /code
    FOR index = N TO 0··················· · 'Establish field width
    ··· char = ASCII DIG index + "0"···'Extract one digit and convert it
    ··· GOSUB LCDwrite····················· 'Pump out one character
    · NEXT···································· ··· 'Continue until done
    code/

    I hope I've better understood your problem.

    Regards,

    Bruce Bates
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-08 17:17
    If you have a BS2p, pe or px, you could use the modifiers like DEC with the LCDOUT commands. However with the earlier Stamps your best bet is the DIG operator. Here is another example, similar to Bruce's, for converting a word into digits to display.

    v1 VAR word
    idx VAR nib
    v1 = 12345
    FOR idx=4 to 0 ' 5 digits, most signif. first
    char = v1 DIG idx + "0" ' convert to ascii chars
    GOSUB LCDwrite
    NEXT

    I would take a little more code to suppress leading zeros, Depending on how you want the display to look.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 11/8/2005 5:45:46 PM GMT
  • NewzedNewzed Posts: 2,503
    edited 2005-11-08 17:23
    Tracy, in the line

    char = x DIG idx + "0" ' convert to ascii chars

    what is the "x" for?

    Sid
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-08 17:46
    Oops. a typo. It was supposed to be v1 as the word variable. I edited it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.