In need of accessing more than 255 bits in a byte/word array.
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2017
    Posts
    39

    Post In need of accessing more than 255 bits in a byte/word array.

    Hello all.

    I'm sure this question has been asked a million times before but has anyone found a way to access more than 255 bits in a byte/word array with a variable bit index?

    Any and all answers are appreciated.
    Last edited by csantex; - 16th January 2019 at 02:37. Reason: Display error, typos

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    1,686

    Default Re: In need of accessing more than 255 bits in a byte/word array.

    value
    bit = array[abc/8]&(1<<(abc//8))
    to set
    array[abc/8]= array[abc/8] |(1<<(abc//8))
    to clear
    array[abc/8]= array[abc/8] & ~(1<<(abc//8))
    This is more entertaining than Free to Air TV

  3. #3
    Join Date
    Jun 2017
    Posts
    39

    Post Re: In need of accessing more than 255 bits in a byte/word array.

    Thanks Richard. I already use a similar approach to set and clear the bits within my array but it's not as elegant as yours.

    Code:
        BrdCountLp0 = Address/16       ; I divide by 16 to select the array variable I want.
        BitCountLp0 = Address//16      ; Now I get the remainder of the division above and it becomes my bit number.                                                       
        lookup2 BitCountLp0, [$01,$02,$04,$08,$10,$20,$40,$80,$100,$200,$400,$800,$1000,$2000,$4000,$8000], TempBits
    .
    .
    .
    .
    
        TempBits0 = ~TempBits0                                            
        OutputLp0[BrdCountLp0] = OutputLp0[BrdCountLp0] & TempBits ; AND these two to clear the bit.
    
        or
    
        OutputLp0[BrdCountLp0] = OutputLp0[BrdCountLp0] | TempBits ; OR these two to set the bit.
    The heart of this post is to see if I could read the status of all the bits in my array, in a loop. My max array is 32 words, so 512 bits. I could split my array in two 16 word arrays but that just complicates things.
    I will see how I can make your value expression work for me in a loop.

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,231

    Default Re: In need of accessing more than 255 bits in a byte/word array.

    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    1,686

    Default Re: In need of accessing more than 255 bits in a byte/word array.

    another way is to stick with a byte array any use an asm call to the L?CALL ARRAYBIT ,macro after setting fsr to appropriate offset
    and calculated byte index for testing bit set or not,. bit offsets of any size in any sized array can be accomodated



    Code:
      movlw   high (_leds) ;Store the High byte of leds to FSRH [set fsr to (bit/256)*256 offset 
        movwf   FSR0H
        movlw   low (_leds)  
        movwf   FSR0L        ;Store Low byte of leds in FSRL   
        decf   _x,W  [this is the index   [bit//256
        bcf STATUS,C         ;must clear carry before arraybit call
        L?CALL ARRAYBIT      ;inc fsr to correct byte and test bit
        bz NL
    This is more entertaining than Free to Air TV

  6. #6
    Join Date
    Jun 2017
    Posts
    39

    Post Re: In need of accessing more than 255 bits in a byte/word array.

    Thanks for the link sayzer! I have read it before a long time ago and it was very helpful at the time. As it turns out, the method stated by melanie does not coincide with what the manual states. I tried it in a for loop and I could only read 255 bits out of 512. These bits are used as flags and when one is set, I turn on an output for a specified period of time using interrupts. In the interrupt, I would check the flags and if they were set, I would then clear my output and the flags until they get set again. It would.be best to use a loop, although not specifically needing to be a for loop. I will try Richard's example and see if it will work. If you have any other suggestions, I'm all "ears". Thanks again for your input.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,686

    Default Re: In need of accessing more than 255 bits in a byte/word array.

    I tried it in a for loop and I could only read 255 bits out of 512.
    the arraybit macros are byte sized
    This is more entertaining than Free to Air TV

Similar Threads

  1. Accessing bits of an array element
    By Art in forum PBP Wish List
    Replies: 5
    Last Post: - 14th June 2014, 12:11
  2. Accessing bytes within a word array
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th September 2011, 08:50
  3. Accessing several bits together in a byte or word...
    By rossfree in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th May 2007, 18:07
  4. Word array behaving like byte array.... wierd
    By forgie in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd August 2005, 15:43

Members who have read this thread : 21

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