Avoiding of 255 IF-THEN in the code, possible?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Avoiding of 255 IF-THEN in the code, possible?

    Hello.
    As some of you know, I already have developed a "Library", which allows to use low-end MCUs with ST7920 graphical LCDs.
    The issue is the memory for the character data. The fastest way is to use on-chip EEPROM. Most low-end PICs have only 128/256 bytes of EEPROM, which, considering letter size of 8x8 pixels, allows storage of either 16 or 32 chars, which is not enough.

    I tried to use external I2C EEPROM, and it works fine, however, reading speed is slow, due to software I2C, and I was not able to use hardware I2C or SPI on low-end PICs.

    I had idea of using parallel EEPROM, but such chips are rare now.

    The only solution remains is to use code memory for character data storage. I've implemented it in some way, but code turns out to be too big. Currently I'm doing it in this way:

    There's a 8 byte array, in which, data for each letter is written, according to ASCII code of the text, stored in another array. The code looks approximately like this:

    Code:
    FOR X=0 TO 16 'LENGTH OF THE TEXT BUFFER
    Z=TEXTLINE[X] 'READ DATA INTO VARIABLE
    
    IF Z=65 THEN 
    ARRAYWRITE FONTLINE, [12,23,34,45,56,78,33,44] 'WRITE FONT BITMAP DATA INTO FONT ARRAY FOR LETTER "A'
    ENDIF
    
    IF Z=66 THEN 
    ARRAYWRITE FONTLINE, [42,23,34,55,56,78,93,44] 'WRITE FONT BITMAP DATA INTO FONT ARRAY FOR LETTER "B'
    ENDIF

    This method indeed works, but I need to have individual IF-THEN-ENDIF lines of code for all characters, which makes code too long in lines and too big in size.

    So is there any other, more compact way for storing these font data lines into main memory?

  2. #2
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Avoiding of 255 IF-THEN in the code, possible?

    This method consumes average 82 bytes per character, so for full, 255 character set, it will require 20K of program memory - too much....

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Avoiding of 255 IF-THEN in the code, possible?

    Yes, ARRAWRITE quite wasteful and not "worth it" for simple things like static data.
    Code:
    Select Case Z
      Case "A"
        FONTLINE[0] = 12
        FONTLINE[1] = 23
        FONTLINE[2] = 34
        FONTLINE[3] = 45
        FONTLINE[4] = 56
        FONTLINE[5] = 78
        FONTLINE[6] = 33
        FONTLINE[7] = 44
    
      Case "B"
        FONTLINE[0] = 42
        FONTLINE[1] = 23
        FONTLINE[2] = 34
        FONTLINE[3] = 55
        FONTLINE[4] = 56
        FONTLINE[5] = 78
        FONTLINE[6] = 93
        FONTLINE[7] = 44
    END SELECT
    There are other ways that are more efficient.
    The FLASH memory of PIC16 devices are 14bits wide. If your characters are 7 pixels wide you can store 2 "lines" in each memory location. See, for example Richards code here:
    http://www.picbasic.co.uk/forum/showthread.php?t=24171

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Avoiding of 255 IF-THEN in the code, possible?

    Thanks!
    Will try that "case" version and check, what amount of memory it will consume.
    regarding the MAX7219 example, there's some ASM code doing "unpack".
    Is it portable? I mean, can be used with other PIC hardware?

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Avoiding of 255 IF-THEN in the code, possible?

    I did some quick tests yesterday and the arraywrite method consumes about double the space compared to loading the array "manually" - no where near 82 bytes though so I don't know what's going on there.

    SELECT CASE uses slightly more space than multiple IF/THEN but it's cleaner and the execution time is always the same.

    Since the memory width of PIC18 is 8 bits the method of packing two 7-bit wide "character lines" into one word isn't suitable for that series.

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Avoiding of 255 IF-THEN in the code, possible?

    Of by the way, I "took apart" the code I've provided, and out of 82 bytes, ARRAYWRITE uses only 19, remaining is used by IF-THEN

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Avoiding of 255 IF-THEN in the code, possible?

    That sounds very very strange to me. I can't imagine that a single IF/THEN clause would "eat" 63 bytes.

  8. #8
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Avoiding of 255 IF-THEN in the code, possible?

    I'm using PIC16F886.

Similar Threads

  1. Read EEprom the 18f4620 after 255 ??
    By vicce67 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd June 2011, 09:22
  2. Line Following, Obstacle Avoiding , and Victim Finding
    By cryptex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th June 2011, 16:34
  3. Replies: 4
    Last Post: - 14th June 2011, 22:03
  4. Avoiding getting stuck in a loop
    By AndrewC in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st July 2008, 11:41
  5. Need to count higher than 255
    By Steve Matson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd February 2008, 08:05

Members who have read this thread : 2

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