PDA

View Full Version : Copying Array to Array



vamtbrider
- 23rd April 2010, 16:03
I am having trouble copying from one array to another.

if I do this it works:



array1 VAR BYTE [30]
CopyMe VAR BYTE[30]

For I = 0 to 29
array1[I] = CopyMe[I]
Next I

If I try this it does not work:


Arraywrite Array1, [CopyMe\30]

OR

Arraywrite Array1, [CopyMe]





I have even tried


ARRAYWRITE Array1, 30, [CopyMe]

And


ARRAYWRITE Array1, [STR CopyMe\30]

But these result in compile errors or in the later example, code not functioning correctly.

What am I missing with the Arraywrite command?

ARRAYWRITE ArrayVar, length, label, [data]

???

Thanks

Ioannis
- 23rd April 2010, 21:34
Which version of PBP do you own?

Ioannis

vamtbrider
- 23rd April 2010, 23:03
running version 2.6

Bruce
- 23rd April 2010, 23:49
Works fine here!


String1 Var Byte(26)
String2 Var Byte(26)
Index Var Byte

PAUSE 5000
Hserout ["Testing",13,10]

Main:
Clear ' Clear RAM before entry

' Load String1 with data
ARRAYWRITE String1,["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]

' Show what's in String1
Hserout [13,10,"String1 = "]
For Index = 0 TO 25
Hserout [String1(Index)]
Next Index

' Copy String1 to String2
ARRAYWRITE String2, [STR String1\26]

' Show what's in String2
Hserout [13,10,"String2 = "]
For Index = 0 TO 25
Hserout [String2(Index)]
Next Index
Pause 500
Goto Main
Returns;


Testing
String1 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
String2 = ABCDEFGHIJKLMNOPQRSTUVWXYZ

vamtbrider
- 24th April 2010, 01:12
Thanks for the response Bruce. I will try your example when I get to my bench later tonight.

For some reason I am having a hard time getting my head around how PBP handles arrays and formatting (DEC, STR, HEX, etc.)

Here is what I am attempting:
From VB using USB I pass 64 bytes of data that contain numbers in the range of 0-255
I assume this shows up in the PIC USBRXBuffer (var from DT and Mistere demos) in hex form of 0x00 through 0xFF.

For example,
PC side:

Bufferout(2) = 150
Bufferout(3) = 200
Bufferout(4) = 8
.
.
.
Bufferout(63) = 233

On the PIC side the USBRXBuffer needs to be copied into another array, USBDataIn. I then use the data in USBDataIn to make program decisions and store some of the data in EEPROM.

If I use
ARRAYWRITE USBDataIn, [USBRXBuffer] I get random data in the USBDataIn array. By random I mean I can not make the data look anything like the data sent from the PC. This would make sense since I never specified a length for the Arraywrite command.

If I use the for...next loop method then the data in USBDataIn matches what came from the PC.

If I try to do the
ARRAYWRITE USBDataIN, [STR USBRXBuffer\24] the processor runs off into la la land. It looks like that method should work, so I guess I need to fire up the debugger and see where the code is getting lost.

So what would happen if you filled your array this way:


For I = 0 to 25
String1(I) = I * 10
Next I


So instead of having "ABCDE..." it now has (0,10, 20, 30...250)

Does the
' Copy String1 to String2
ARRAYWRITE String2, [STR String1\26]

produce an output of 0,10,20,30,40...250?