Any way to use built-in conversion functions?
Jexts
Posts: 2
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.
Thanks.
Comments
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
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
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
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
char = x DIG idx + "0" ' convert to ascii chars
what is the "x" for?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com