array in constant?


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2007
    Posts
    12

    Default array in constant?

    hi every one. i am fresh here. i got a problem with coding about arrays.

    what i wanted to do is to create an array which have a series of constants that i won't be changing during runtime.

    i believe there is a code which is like " a var byte[10] " is possible but this required the pic's ram and the ram is pretty limited. so, can i create the array as in constant or as code which i can den use later on?

    futher more, how to put in data in array mode? which some thing like " a[] = {1 2 3 4 5 6 7} "

    thank you

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    LOOKUP a,[1,2,3,4,5,6,7],b.

    a & b would be byte variables. a = the index pointer. b = the byte variable
    the constant value from the table is placed in.

    a = 1
    LOOKUP a,[1,2,3,4,5,6,7],b

    b now = 2.

    This creates a constant array in ROM similar to const char a[]={1,2,3,4,5,6,7};
    in C where b=a[1].
    Last edited by Bruce; - 2nd August 2007 at 14:11.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Aug 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    this means that i can put
    LOOKUP A,[.......],B

    but how can i refer to the A later on?

    eg. lookup a,[ 1 2 3 ],b

    den how can i do like x= a[1] + a[2] ?
    Last edited by SpiritHunter; - 2nd August 2007 at 12:52.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you need x= a[1] + a[2] then you'll need to create a standard array of
    RAM variables.

    Or do something like this;
    Code:
    Main:
         a = 1
         GOSUB GetConst
         X = b
         a = 2
         GOSUB GetConst
         X = X + b ' now X = a[1]+a[2]
         GOTO Main
    
    GetConst:
         LOOKUP a,[1,2,3,4,5,6,7],b
         RETURN
    Last edited by Bruce; - 2nd August 2007 at 14:29.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Aug 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    thanks alot bruce, i think i understand already. will try out 2moro.

  6. #6
    Join Date
    Aug 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    wow.. thanks.... o ya... 1 more question... how many constant can i write in a single bracket? and... is there a problem if i write like this?

    LOOKUP a,[1,2,3,4,5,6,7
    ,b

  7. #7
    Join Date
    Aug 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    wow.. thanks.... o ya... 1 more question... how many constant can i write in a single bracket? and... is there a problem if i write like this?

    LOOKUP a,[1,2,3,4,5,6,7
    ,8,9,10],b

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by SpiritHunter View Post
    how many constant can i write in a single bracket? and... is there a problem if i write like this?

    LOOKUP a,[1,2,3,4,5,6,7
    ,8,9,10],b
    Hi, SH

    Will 255 for a 16F series and 256 for a 18F series be enough ??? ( LOL !!!)

    ...

    Note this type of array takes a lot of room ( like with assembler ... 1 prog line per value + 1 ) and you might think at it when choosing your PIC ...

    PbP doesn't deal so well with room for this function ... and lots of room is lost with big lookup tables !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Aug 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, SH

    Will 255 for a 16F series and 256 for a 18F series be enough ??? ( LOL !!!)

    ...

    Note this type of array takes a lot of room ( like with assembler ... 1 prog line per value + 1 ) and you might think at it when choosing your PIC ...

    PbP doesn't deal so well with room for this function ... and lots of room is lost with big lookup tables !!!

    Alain
    ? 255 only? i am thinking of at less 500... as i need to bit map all the char in ascii which is at less need 101x5

    ya.. i know it takes alot of memory. and i have chosen 16F877A to do the job. i hope 8k is enough for the constants, I2C and a serial communication... if not enough, then i am in big troble.. haha...

    so... 16F877A can only allocate 255 in 1 lookup table? if so, den i need to separate the bit map codings.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Those are PbP limits !!! ... for LOOKUP ...

    you can also use an external pre-programmed EEPROM or use some READCODE ( see manual for the limits )... if your code space allows it ....

    note ... DATAs for READCODE can be loaded as an "include" file ... generated by your computer ! ( with "word", or much better "Excel" ...)

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Aug 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    thanks Acetronics, i can deal with the more then 255 problem.

    now another problem is that

    how can i write

    lookup a,[1,2,3,4,5,6,...........,255],b

    in multiple line? and adding comment in the end of each line?

    eg:
    lookup a,[1,2,3,4,5,6,7,8,9,10, ; line 1
    11,12,13,14,15, ; line 2
    .................... ],b

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    lookup a,[1,2,3,4,5,6,_       'never tried comments on each line
              7,8,9,10,....,255],b ' but the normal way should work
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Aug 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    just add _ behind each line. got it... thanks

  14. #14
    Join Date
    Aug 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    thanks guys, not that the compiling part is finish, it's time to put it in the 16f877a and test it.
    the coding alone is around 6kb already. haha...

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  3. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  4. RS232 receive an array (packet)
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th February 2008, 05:02
  5. Reading Array values into variables
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 21st March 2005, 10: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