String & WRITE


Closed Thread
Results 1 to 17 of 17

Thread: String & WRITE

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: String & WRITE

    Whether you wish to refer to a value in its decimal, hexadecimal, or binary format, when storing to the EEPROM, you are simply storing that value. When you READ it back, you may need to format it in its hexadecimal format for sending information serially, or displaying to an LCD. It looks like you are receiving these digits as ASCii, which allows for letters A-F. My approach would be to first convert the ASCii characters into Nibbles, then group them together into Hex. Finally you can store the Value in your EEPROM.

    To convert an ASCii character to a Hex nibble, subtract $30 from the numeric value of that nibble. Characters 0 >> 9 will be their 0 >> 9 raw value. Capital letters start at $41. Example, actual ASCii value of $41 = "A". You could use IF New_Data > $39 THEN : GOSUB DecodeLetters, ELSE : GOSUB DecodeNumbers. Using the shift and mask code listed previously, group your high nibble and low nibble together to create a new and complete byte value. Repeat for each 2-character grouping. When READing from the EEPROM, use the HEX modifier to send "Value" serially (ASCii representation). The key is that your ASCii value is $30 + Numbers (0 >> 9) and $37 + Letters (A >> F); conversely, ASCii - $30 = 0 >> 9 value while ASCii - $37 = A >> F values.
    Last edited by mpgmike; - 30th December 2017 at 19:12.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: String & WRITE

    When you use the HEX modifier with SEROUT, DEBUG, LCDOUT, HSEROUT, ARRAYWRITE and so on it converts FROM a numeric value TO an ASCII string representing the numeric value as hexadecimal. In other words a value of 127 becomes a "7" and a "F".

    Likewise, when you use the HEX modifier with SERIN, DEBUGIN, HSERING, ARRAYREAD etc it converts FROM an ASCII string (or single character) representing a numeric value as hexadecimal TO the actual numeric value. In other words the "7" and the "F" becomes 127.

    mpgmike does a good job of explaining how you convert ASCII to the numeric value that the "text" represents but what I'm trying to say is that you don't have to do that "manually" because the HEX- (and DEC and BIN) modifiers works both ways and does the job for you when used with a command that supports them (which DEBUGIN does).

    It would be interesting to see if any benefits (size- or speedwise) can be gained from doing the conversion "manually" instead of letting PBP handle it for you using the built in modifiers.

    Happy new year by the way!

    /Henrik.

  3. #3
    Join Date
    Dec 2017
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: String & WRITE

    Hello everyone,

    I am glad that my "initiative" to re-open this topic has got such an echo.
    Will give a try to presented methods and will reverd with results ASAP.

    Meanwhile have a joyful and prosperous New Year !

Similar Threads

  1. WRITE: One more PBP 2.60 Surprise ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 26th August 2009, 09:10
  2. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 04:39
  5. Storing Strings using the Write command
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2005, 11:31

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