PDA

View Full Version : Putting values into an array



Vince
- 2nd December 2003, 03:25
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!!!

Darrel Taylor
- 2nd December 2003, 03:55
Hi Vince,

There's probably a dozen different ways to do this. Here's 1 of them.
Ignore this... See second post below

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

picnaut
- 2nd December 2003, 05:12
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

Darrel Taylor
- 2nd December 2003, 06:36
Vince

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

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.


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

Vince
- 2nd December 2003, 08:22
Thank you guys so much for the help!!! ^_^ I will implement this code and see how it works. Thanks again!!!