Get a 62.5% more program space easily


Closed Thread
Results 1 to 6 of 6
  1. #1
    serandre's Avatar
    serandre Guest

    Default Get a 62.5% more program space easily

    If you use too much strings (A-Z), you can easy get a 62.5% more space, since only 5/8 of the byte is used for the ASCII chars, this let us with a 3/8 wasted space of a byte that serves nothing.

    So a string like this:
    "HELLO WORLD LETS WASTE SOME BITS"

    that takes 32 bytes (256 bits) could be coded as a 5 bit per ASCII character and ocupies only (160 bits), or 20 bytes !!!!!!

    The downside is only that if you need to change the string, you will need to code it again, and once coded it's not possible to read it.

    But considering some pics like 12f675 that only have a 1k of memory, having this type of code can save your project.

    An example could be some type of REMOTE CONTROL decoder, that uses LOOOOTTTTTs of ASCII chars to show on a LCD the command descriptions, etc.... This takes a loot of memory.

    To code the strings just subtract from each char (-65), so a "A" (ASCII 65) char will be coded as 0, B will be 1, etc...

    Example:
    HELLO --> ASCII 72, 69, 76, 76, 79 will be
    HELLO --> CODED 7, 4, 4, 14
    BINARY SEQUENCE --> 00111 00010 00010 01110
    BYTE SEQUENCE --> $38, $84 $E0

    See, the HELLO would take 5 bytes, after coded it took 2 1/2 bytes, and yeat there's a space in the last byte to more 1 char !!!

    Hope this idea could be usefull to someone, I'm using it with my remote control project, if not using this type of code it would be impossible to me use a Pic12f675.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    interesting idea if you only need plain text in Upper Case. Good job! Now how do you save this to your codespace?

    Did you already look here for a thread called Embedded String in your code space?
    See the short story there http://www.pbpgroup.com/modules/wfse...p?articleid=10

    Easier does it?
    Last edited by mister_e; - 6th April 2006 at 23:15.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    serandre's Avatar
    serandre Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    interesting idea if you only need plain text in Upper Case. Good job! Now how do you save this to your codespace?

    Did you already look here for a thread called Embedded String in your code space?
    See the short story there http://www.pbpgroup.com/modules/wfse...p?articleid=10

    Easier does it?
    In fact it's possible to use any character using a 5bits coding:

    Since A-Z is only 26 letters, the 5 bits coding has a remaining 5 position to be used as controls like bellow:

    I prefer to use the default as a lower case chars. (abcdef...)
    So A-Z are coded as a=1, b=2, c=3, d=4...till z=26

    As controls I use:
    0 - End of string
    27 - Space char
    28 - Begin/End mark for a upper case string
    29 - Begin/End mark for numbers 0-9
    30 - Begin/End mark for symbols +-,.!$%^ (max 26 symbols each one is a char A-Z)
    31 - Reserved, I have in nothing in mind in the moment :-)

    So I code the string this way:

    Source:
    "/t/hese /word/ is in upper case this year is [bjjf]"

    the ouput:
    "This WORD is in upper case this year is 2006"

    I am doing this ... errr... by hand :-) transforming the string directly to bits, it's a hell of work i know, I need just to create a program to translate the strings (Source above) to the bits and coded as i want.

    Well, this idea I took from the HTML format, so even with as little as 5 bits I can get any char in a compact size :-)
    Last edited by serandre; - 7th April 2006 at 02:36.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    with the previous link, it will take the same code space (+/- few bytes) and you'll never have to translate your strings. Make things really much easy when you need to modify or add any strings.

    Another idea is to save your string (or part of) in the internal EEPROM. Using your method or a variant of will permit to store 256 character in the internal EEPROM. I don't know how your string eat space but it could work too.
    Last edited by mister_e; - 7th April 2006 at 06:07.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Retrieving text - any example

    Hello Seandre,

    Any example on how you retrieve the code please?
    Roger

  6. #6
    Join Date
    Jan 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Better still, why not code your words as TOKENS??

    Store all the words you are likely to use in a table in the EEPROM in the PIC, then reference them using numbers;

    Example;

    PRESS, ANY, BUTTON, DOWN, THE

    PRESS THE DOWN BUTTON becomes 1,5,4,3 you can delineate the words with a number say 27 as you will only ever use characters 1-26 anyhow, when the exctract routine sees a "27" it knows that is the end of the word.

    Hope this helps.

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  2. Replies: 1
    Last Post: - 23rd May 2009, 09:22
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30

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