Stupid array question


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    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
    __________________

  2. #2
    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.

  3. #3
    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?

  4. #4
    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
    __________________

  5. #5
    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

  6. #6
    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!

  7. #7
    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.

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