shiftin with \bits - What order do they come?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2014
    Posts
    17

    Default shiftin with \bits - What order do they come?

    I need to shiftin 16 bits of data from an A/D. I think the command should be:
    shiftin datapin, clkpin, mode, [data\16]

    I need the data to be read MSB first. Some code examples show using MSBPRE to select MSB first. However, according to the manual when "\bits" is used the bits are always the low order bits, which I take to mean as LSB first.

    Am I understanding this correctly? Or can I select either MSB or LSB first and the number of bits to be read?

    If the bits are read in in reverse is there an easy way to reverse them back to MSB first?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,515


    Did you find this post helpful? Yes | No

    Default Re: shiftin with \bits - What order do they come?

    the way I interpret that is
    if \bits=8 and you are shiftin-ing that into a word var then the shiftin data is always placed in the low order byte (but msb first or last as requested)

    but that's just my interpretation , I have been known to be wrong

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: shiftin with \bits - What order do they come?

    I’m mixed up between significant bits & bytes here!

    “The bits shifted in are always the low order bits” reads to me like if you shifted in 4 bits,
    they will be populated from bit0 to bit3 of the variable you read in to, and the difference
    between lowest or highest bit first refers to the order of those 4 bits.
    ie. %00001011 as opposed to %00001101.

    I wouldn’t bet my life on it either, but I’m sure whatever mess you make can be cleaned up after the read.
    REV will reverse the order of a specified number of the lowest bits in a value, so there’s an easy way to
    fix the above two numbers.
    If you want to swap bytes in a word, you can alias the byte values which is a lot more typing than code space.
    Code:
    16bitval var word
    16bitvalswapped var word
    L16bitval var 16bitval.byte0
    H16bitval var 16bitval.byte1
    Ls16bitval var 16bitvalswapped.byte0
    Hs16bitval var 16bitvalswapped.byte1
    
    Ls16bitval = H16bitval ‘ swap bytes
    Hs16bitval = L16bitval
    Last edited by Art; - 3rd April 2015 at 05:48.

Similar Threads

  1. Replies: 2
    Last Post: - 23rd April 2013, 17:34
  2. ShiftIn to array of bits using EXT modifier?
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th March 2011, 15:30
  3. DT_INTS-14 /interrupts enable bits / flag bits
    By bogdan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th May 2009, 19:42
  4. Need clever way to convert 10 bits to 8 bits
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd September 2005, 16:13

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts