Shop OBEX P1 Docs P2 Docs Learn Events
Newbie Question Re. ASCII — Parallax Forums

Newbie Question Re. ASCII

ArchiverArchiver Posts: 46,084
edited 2001-11-02 03:38 in General Discussion
Hi! I am new to this list and had a quick question regarding ASCII.
I am working on a project (using the Basic Stamp II) that does a
simple math problem, then writes the answer to the EEPROM using the
WRITE command. The EEPROM contents later are sent to a 4-bit
parallel LCD display. My question is how to convert the decimal
number from the math problem into ASCII for the LCD display. I know
this sounds like a simple problem, but I'm not very experienced with
the Basic Stamp.
Thanks,
Jacob

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-11-01 05:29
    --- In basicstamps@y..., sejpower@j... wrote:
    > Hi! I am new to this list and had a quick question regarding
    ASCII.
    > I am working on a project (using the Basic Stamp II) that does a
    > simple math problem, then writes the answer to the EEPROM using the
    > WRITE command. The EEPROM contents later are sent to a 4-bit
    > parallel LCD display. My question is how to convert the decimal
    > number from the math problem into ASCII for the LCD display. I
    know
    > this sounds like a simple problem, but I'm not very experienced
    with
    > the Basic Stamp.
    > Thanks,
    > Jacob

    Hi Jacob,

    One simple, but not the most efficient, way would be to load the
    decimal number, bit by bit, into an array, and the parse the array,
    one bit at a time with the ASC qualifier, i.e. x=ASC(decimalnumber,1)
    and so on. (But come to think of it, that would be one way to do it
    in VB, so not sure if that will help you.)

    Jim
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-01 06:38
    >Hi! I am new to this list and had a quick question regarding ASCII.
    >I am working on a project (using the Basic Stamp II) that does a
    >simple math problem, then writes the answer to the EEPROM using the
    >WRITE command. The EEPROM contents later are sent to a 4-bit
    >parallel LCD display. My question is how to convert the decimal
    >number from the math problem into ASCII for the LCD display. I know
    >this sounds like a simple problem, but I'm not very experienced with
    >the Basic Stamp.
    >Thanks,
    >Jacob

    Hi Jacob,
    Something like this

    read location, mybyte
    for j=2 to 0
    char=mybyte dig j + 48 ' get jth digit, add 48 for ascii
    gosub char2lcd ' put it on the lcd, not shown
    next

    That prints the leading zeros, for example, 005, 013, 154, always
    three digits. The following substitutes spaces for leading zeros, so
    the above would be 5, 13 or 154, right justified:

    nonzeroflag var bit
    mybyte var byte
    location data 154
    j var nib

    read location, mybyte
    digflag=0 ' flag turns to 1 at first significant digit.
    for j=2 to 0
    char=mybyte dig j ' char is jth decimal digit
    digflag = char max 1 | digflag
    char=(digflag-1)*16+ char+48 ' convert to ascii
    ' and convert leading zeros to spaces
    gosub char2lcd ' put it on the lcd, not shown
    next

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-02 03:38
    You shouldnt have to convert to ascii try using the dec2 modifier in
    front of your variable
    ie(serout pin,baud,[noparse][[/noparse]254,120,dec2 variable]
    If your using an lcd with a backpak installed you will need to initialize
    the display,which is 254, and a start position followed by your variable.


    On Thu, 01 Nov 2001 02:32:25 -0000 sejpower@j... writes:
    > Hi! I am new to this list and had a quick question regarding ASCII.
    >
    > I am working on a project (using the Basic Stamp II) that does a
    > simple math problem, then writes the answer to the EEPROM using the
    > WRITE command. The EEPROM contents later are sent to a 4-bit
    > parallel LCD display. My question is how to convert the decimal
    > number from the math problem into ASCII for the LCD display. I know
    >
    > this sounds like a simple problem, but I'm not very experienced with
    >
    > the Basic Stamp.
    > Thanks,
    > Jacob
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
Sign In or Register to comment.