Stupid array question


Closed Thread
Results 1 to 14 of 14
  1. #1
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest

    Post Stupid array question

    I'm working on an LED matrix project that involves displaying data on an 8 x 80 LED matrix (multiplexed of course). I was planning on storing the data to be displayed in hex form in my PIC18F252s EEPROM, which I would then be able to look at using .Bit0 or .Bit1 to see if an LED needs to be on (for example, $AA in binary is 10101010, which would mean that every other LED is on). The only problem with this plan is that the EEPROM on the 18F252 is only 256 bytes, leaving room for less than 125 rows of LEDs, which just isn't enough.

    If anyone knows a good way to somehow compress data, that might be usefull, but I was thinking about storing the display data in arrays, that way I could easily switch between different messages.

    So, the real question now:
    Is there any way to store a bunch of data in an array on one line?

    In java you can do this:
    Int[] test = {5, 6, 7};

    Can you do anything like that in PBP? It would make coding much easier, as opposed to going like this:
    message[0] = $AA
    message[1] = $2C
    message[2] = $4D

    and so on...

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RUBiksCUbe
    .... switch between different messages.
    ....
    Will the "different messages" come from an external source or there will be a fixed pattern inside the program and once the PIC is programmed then that fixed pattern will never be changed?



    --------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    As Sayzer is hinting, if your data does not change after you do the initial programming, you could use the LOOKUP or LOOKUP2 command. (or just the READCODE command referenced below if you preloaded your data)

    If your data is going to change, you could use WRITECODE and READCODE. Also see: http://www.picbasic.co.uk/forum/showthread.php?t=137 for reference
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Default

    The READCODE command actually looks perfect for me. Thanks for pointing that out.

    The PIC will switch between different messages when external buttons are pushed.

  5. #5
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Angry

    Well, it was too good to be true. Whenever I compile with this in my project:

    Code:
    Asm
    CODE 1400
    DB 0
    DB 220
    DB 476
    DB 384
    DB 384
    DB 476
    DB 220
    DB 0
    DB 999
    Endasm
    I get some nice errors:

    Found directive in column 1. (CODE)
    Directive only allowed when creating an object file
    Found directive in column 1. (DB)
    Argument out of range. Least significant bits used.

    There are 15 errors total, but they're all just copies of those 4.

    Am I missing something?

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    You need to indent your program like that below. However, I believe DB is used for bytes only and you must use packing to place the word (i.e., DB 476 will not do what you want)? Others with more 16 bit processor Assembly experience might be able to offer a (better) solution in ASM.

    You might want to consider using PBP's WRITECODE instead of the ASM for the initial write. Look here http://www.picbasic.co.uk/forum/show...ight=writecode and also search “WRITECODE” on this forum for examples of how to write to the 18F family, which is not as straight forward as one might think.

    Code:
    Asm
         CODE 1400
         DB 0
         DB 220
         DB 476
         DB 384
         DB 384
         DB 476
         DB 220
         DB 0
         DB 999
    Endasm
    Good Luck

    edit: or consider LOOKUP2 tables
    Last edited by paul borgmeier; - 3rd September 2006 at 08:29. Reason: added option?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier
    ..........or consider LOOKUP2 tables

    I also was going to suggest LOOKUP table but arrays can not be used with Lookup tables!
    Say there are 90 messages.


    Code:
    'This code is just a part of the idea to start from somewhere.
    
    
    Message     var byte[90]
    MessageTemp var byte
    Loop        var byte
    
    
    for loop = 0 to 89
        lookup loop,[$AA,$2C,$4D,.....................], MessageTemp
        message[loop]=messageTEMP
    
    next loop

    This way,

    Quote Originally Posted by RUBiksCUbe
    ........

    Can you do anything like that in PBP? It would make coding much easier, as opposed to going like this:
    message[0] = $AA
    message[1] = $2C
    message[2] = $4D

    and so on...


    can be achieved.


    ------------------------------------



    -------
    Last edited by sayzer; - 3rd September 2006 at 13:22.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Talking

    I never knew about LOOKUP, but the lookup and loop should work perfectly. The intenting fixed the "DB"s but the "CODE" line still causes a problem, so I'm going to abandon READCODE and just stick with LOOKUP.

    Thanks!

  9. #9
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    There have been a number of solutions to this type of problem. If the messages you plan on displaying won't be changed once the pic is programmed, These may work:

    STRINGS - How to store and retrieve strings in Code Space by Darrel Taylor.

    Here is a thread which deals with the storage of strings as well.


    One other possibility is use an external EEPROM. Limit all the messages to X number of characters (say 255). Then, depending on the message, go to the designated starting address for that message (0 for message A, 256 for message B, ...) Also store a "stop" character to know where the message ends. This would allow something like (This is an example, not a completed program):

    Code:
    MessageString VAR BYTE[256]
    StartAddress  VAR WORD
    cnt           VAR BYTE
    StopChar      CON 3
    
    MessageNumber = 1
    StartAddress = MessageNumber * 256
    cnt = 0
    ReadMessage:
         I2CREAD DataPin,ClockPin,Control, (StartAddress+cnt) ,[MessageString(cnt)]
         IF MessageString(cnt) <> StopChar THEN ReadMessage
    HTH,
    Steve

    EDIT: Added varible declaration for StartAddress
    Last edited by SteveB; - 3rd September 2006 at 23:04.

  10. #10
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Default

    I'll definetly switch to an EEPROM for storage once I get the rest of the circuit working. I thought about using an EEPROM but I wasn't sure how to interface with one. Thanks for the code.

  11. #11
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default About the EEPROM...

    Some of the nice things about using the external EEPROM:
    - I2C or SPI Interface. (both of which have built in PBP software base routines. Or roll your own hardware interface since most, in not all, 18Fs have this.)
    - Up to 1024Kbit (with I2C). More than enough for your intended use.
    - You can change messages and store new messages. A little more work to program this, but more than likely worth it for your applications. (EDIT: You could do this with ERASECODE/WRITECODE as well)

    Best of luck,
    Steve
    Last edited by SteveB; - 4th September 2006 at 00:21.

  12. #12
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default And on second thought...

    As my previous reply ratteled around in my head some more (Hard to do while chasing around my little ones on a Sunday afternoon), the method I mentioned relating to the EEPROM could be implemented with READCODE and WRITECODE as well. Definately have a look the link to Darrel Taylor's stuff. You could use the techniques he has come up with to set your initial messages, then later use the ERASECODE/WRITECODE if you want/need to change things (EDIT: But you have to write in 64 byte blocks, which should not be such a limiting factor in your case. See the Datasheet!). If you have lots of extra code space available, why not use it and avoid adding another component to the project.

    Steve
    Last edited by SteveB; - 4th September 2006 at 00:24.

  13. #13
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    RUBiksCUbe,

    I think you now are like a kid in a candy shop and you are allowed to get only one candy but there are hundreds of different candies around you.

    You can not decide which one to get???

    You came down to two choices; Lookup or EEPROM?





    ------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  14. #14
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Default

    Lookup or EEPROM
    ....hmmm....

    Well, I already wrote a java applet that exports designes straight to the form of Lookup tables (based off of the one used here: http://www.sparkfun.com/commerce/pre...20LED%20Client)

    So for now I'll stick with Lookup, but eventually I'll run out of code space and migrate over to an EEPROM. I'm planning on having a lot of messages available to be cycled through. I guess I could just adapt my applet to export just the hex characters without the Lookup code around it for EEPROM use.

    So until I run out of space, I'll stick with Lookup

Similar Threads

  1. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  2. Array Question....please help
    By jmoskalski in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st October 2009, 01:29
  3. Stupid question about LCDOUT
    By Glenn in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 7th October 2008, 21:37
  4. Stupid question
    By Meriachee in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 20th July 2007, 05:47
  5. How to saparate variable to array and GLCD Question
    By pramarn in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 4th October 2006, 03:42

Members who have read this thread : 0

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