A little help with shifting out Arrays?


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Re: A little help with shifting out Arrays?

    I'll maybe try both ways and break out my logic analyzer. I get confused with the MSB/LSB stuff though. I guess the analyzer captures on the screen the first bit it sees on the left hand side of the screen and goes from there. So we'll see. I just have to think about what numbers to use to get a result I can fit my little brain around. high voltage modulators and vacuum tubes at work to microcontrollers and digital circuits at home. Maybe I should take up wood working as a hobby instead!

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: A little help with shifting out Arrays?

    Henrik,
    What "low order bits" means in this case is that "\X" will always shift out the x lowest bits. So myByte\4 or myWord\4 or myLong\4 would all just output the 4 lowest bits. Now that the correct bits have been determined, it will shift them out based on the mode. So you can think of "\X" as "Shift out the lowest X bits of the variable"

    This is why I'm curious about the actual output of the the shift statement used, which could be understood as, "Shift out the lowest 24 bits in the byte called myArray". As you can see, it doesn't make a lot of sense, but it's going to try to do something, and I am wondering what that something is.

  3. #3
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: A little help with shifting out Arrays?

    myArray VAR BYTE[3]

    myArray[0] = 1
    myArray[1] = 127
    myArray[2] = 255

    SHIFTOUT PORTB.0, PORTB.1, 1, [myArray\24]

    Prediction:
    The above code will shift out the following:
    00000000 00000000 00000001

    With myArray[0] = 127:
    00000000 00000000 01111111

    With myArray[0] = 255:
    00000000 00000000 11111111

    The values in myArray[1] and myArray[2] have no effect on the outcome.

  4. #4
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Re: A little help with shifting out Arrays?

    Sorry for not getting back to this. I've had my logic analyzer tied up for something else and haven't been able to get back to that project let alone this one due to some things beyond my control. I will however report back when I do get to it. I hate starting a question and not getting to the answer.

    Best Regards,

    Ryan

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: A little help with shifting out Arrays?

    I haven't had a chance to test it either. But my prediction is based on looking at the asm code produced. Although I noticed that I compiled it using PBPLong.

    Using the non-long PBP, the results will be a little different, but likely still have 0000000000 00000001 as part of the result, since the internal temporary variable PBP uses is a 2-byte word, and it clears the top byte before entering the shift-out routine, then shifts out 24 bytes.

    Bottom line, to do what you want, either of the following will work:
    - Use 3 seperate BTYE variables
    - 1 BYTE and 1 WORD variable
    - 1 LONG variable

    There may be some other, more creative way to work out the problem, but these are striaght foward and simple. The code may not look as 'tight', but it will work the way you expect/desire.

    SB
    Last edited by SteveB; - 24th September 2012 at 16:36. Reason: typo

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: A little help with shifting out Arrays?

    Hi guys,
    I just did some tests here. Here's the testcode:
    Code:
    Leader VAR BYTE
    myArray VAR BYTE[3]
    Trailer VAR byte
    
    Leader = 170
    Trailer = 85
    
    Test1:
      myArray[0] = 1
      myArray[1] = 127
      myArray[2] = 255
      PortB.5 = 0
      SHIFTOUT PortB.6, PortB.7, 1, [myArray\24]
      PortB.5 = 1
    
    PauseUs 10
    
    Test2:
      myArray[0] = 255
      myArray[1] = 127
      myArray[2] = 1
      PortB.5 = 0
      SHIFTOUT PortB.6, PortB.7, 1, [myArray\24]
      PortB.5 = 1
    
    Pauseus 10
    
    Test3:
      myArray[0] = 1
      myArray[1] = 127
      myArray[2] = 255
    
      PortB.5 = 0
      SHIFTOUT PortB.6, PortB.7, 1, [myArray[0], myArray[1], myArray[2]]
      PortB.5 = 1
    
    Pause 100
    END
    The idea with the Leader and Trailer bytes was to see if the memory is alocated in the order it declared and if the shiftout would "fall into" those - turns out that's not the case in this example. Here are the captured results:
    Name:  Test_123JPG.JPG
Views: 1602
Size:  114.3 KB
    I was a bit surprised that both test 1 and test 2 gave the same results but it did.

    /Henrik.

  7. #7
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: A little help with shifting out Arrays?

    Quote Originally Posted by HenrikOlsson View Post
    I was a bit surprised that both test 1 and test 2 gave the same results but it did.
    That IS a bit suprising.

    But, it difinately shows that shifting out the array in the original post won't work, but doing it as seperate bytes of the array will work. So that is a 4th method that will work.

    Thanks Henrik!
    Last edited by SteveB; - 24th September 2012 at 21:39. Reason: typo

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