PDA

View Full Version : shiftin with \bits - What order do they come?



tbarania
- 2nd April 2015, 04:04
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?

richard
- 2nd April 2015, 05:23
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

Art
- 3rd April 2015, 04:39
I’m mixed up between significant bits & bytes here! :D

“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.



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