Putting values into an array


Closed Thread
Results 1 to 5 of 5
  1. #1
    Vince's Avatar
    Vince Guest

    Default Putting values into an array

    Hi!

    I'm having trouble manually placing values into an array. I'm using a 16F628 and Pic Basic Pro. Here is what I'm trying to do:

    CLAR VAR BYTE[32]

    I want to put this:

    0,1,0,1,1,1,1,0,1,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,0, 0,0,1,0,0,0,0,0

    Into the CLAR array.

    Right now, I'm trying:
    CLAR = 0,1,0,1,1,1,1,0,1,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,0, 0,0,1,0,0,0,0,0

    But it won't work. I've tried to search through this forum, but I couldn't find any solutions to this. I thought about making a FOR loop and putting each individual value in each location of the array.

    Thanks for your help!!!

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Vince,

    There's probably a dozen different ways to do this. Here's 1 of them.
    Ignore this... See second post below
    Code:
    For x = 0 to 31
       Lookup x,[0,1,0,1,1,1,1,0,1,1,1,1,1,0,0,1 ,1,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0], CLAR[x] 
    Next x
    Also, the original example has 1 too many numbers for a 32 byte array.

    HTH,
    Darrel Taylor
    Last edited by Darrel Taylor; - 2nd December 2003 at 05:38.

  3. #3


    Did you find this post helpful? Yes | No

    Lightbulb Make it a bit array

    Hello Vince,

    If all you are loading is 1's and 0's, why don't you make it a bit array?

    Use the method that Darrel suggested, but declare "CLAR" as a bit type array.

    For example...

    CLAR VAR BIT[32]

    I hope that Darrel's suggestion can be implemented using a bit variable. I haven't used the "Lookup" command yet, so I'm not sure. However, If you can then the "CLAR" array will take up 8 times less memory than if you declare it as a byte array.

    Good luck.

    picnaut
    ---> picnaut

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Vince

    Well, after trying to compile my previous example, I found that IT DOESN'T WORK!

    Not to worry, only one minor problem. The lookup statement doesn't seem to like having an array variable as the output.
    Using a Temp variable then copying it to the array seems to work fine. So now it should look like this.

    Code:
    CLAR VAR BYTE[32]
    x    VAR Byte
    Temp VAR Byte
    
    For x = 0 to 31
       Lookup x,[0,1,0,1,1,1,1,0,1,1,1,1,1,0,0,1 ,1,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0], Temp
       CLAR(x) = Temp
    Next x
    Also,
    picnaut has a good point about the bit arrays, and yes, the revised version will work with them. (I checked before saying that)

    HTH,
      Darrel Taylor

  5. #5
    Vince's Avatar
    Vince Guest


    Did you find this post helpful? Yes | No

    Talking

    Thank you guys so much for the help!!! ^_^ I will implement this code and see how it works. Thanks again!!!

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. Array values changing
    By MyBuddy in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th October 2009, 23:13
  4. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 08: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 : 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