Loading a BIT array, losing my mind!


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2008
    Posts
    43

    Default Loading a BIT array, losing my mind!

    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.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default

    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?
    Code:
    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
    NEXT
    Please see Melanies excellent write up.

    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.
    Last edited by HenrikOlsson; - 19th January 2011 at 12:57.

  3. #3
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Any other ideas's? can't use an array that large

  4. #4
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    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
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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