PDA

View Full Version : Loading a BIT array, losing my mind!



PlantBob
- 19th January 2011, 12:26
PIC18F2450

HC VAR BIT[16]

This code will load the HC bits correctly:

HC[0]=1
HC[1]=1
HC[2]=1
HC[3]=0
HC[4]=0
HC[5]=0
HC[6]=0
HC[7]=0
HC[8]=1
HC[9]=1
HC[10]=0
HC[11]=0
HC[12]=0
HC[13]=0
HC[14]=0
HC[15]=0

This code does nothing!
HC = %1111111111111111

HC will still have the bit pattern loaded in the first code.

I have 512 different 16 bit patterns I need to use. Using the first code requires 8192 lines of code. There has got to be a better way! I have tried every VAR type and none of them seem to load data into the HC array. Hoe can I accomplish this? Going crazy.

HenrikOlsson
- 19th January 2011, 12:55
Hi,
You can't create an array of bits and then treat it as a word (as far as I know), you can however do the opposite - if you can have an array of words instead?


BitPatterns VAR WORD[512]
i VAR BYTE

BitPatterns[0] = %1010101010101010
BitPatterns[1] = %0101010101010101
BitPatterns[2] = 0

For i = 0 to 23
BitPatterns.0[i] = 1
NEXT

For i = 0 to 22 STEP 2
BitPatterns.0[i] = 1
BitPatterns.0[i+1] = 0
NEXTPlease see Melanies excellent write up. (http://www.picbasic.co.uk/forum/showthread.php?t=544)

EDIT: I'm not sure you can actually declare an array of 512 words, look that up in the manual as it differs between different PIC series.

/Henrik.

PlantBob
- 19th January 2011, 13:13
Any other ideas's? can't use an array that large

PlantBob
- 19th January 2011, 13:26
Thanks for the suggestion, I couldn't set the array to 512 words but your code sample inspired me to do it a bit different, its working correctly now. Thanks again.

Bob

cncmachineguy
- 19th January 2011, 13:26
How do you want to use the array? That will help determine what way will work for you. There are different ways of playing with data.

EDIT: crossed posted