What if you need to shift a 5 bit number in, through and out of a byte using bit0 to bit4 and not affect bit5 - bit7 because, for example, bits 5-7 are running the column select (via a 3 to 8) for a matix LED and the lower 5 bits are connected to the colum.
If you had two 8 bit wide registers next to each other like the following. The 5 bit value in byte 2 is shifted left throughout byte 1 and out.
byte1 byte2 XXX00000 xxx11111 start state XXX00001 xxx11110 XXX00011 xxx11100 XXX00111 xxx11000 XXX01111 xxx10000 XXX11111 xxx00000 XXX11110 xxx00000 XXX11100 xxx00000 XXX11000 xxx00000 XXX10000 xxx00000 XXX00000 xxx00000 end state
X = can not be changed.
x = not used
Dmitry Kiryashov [zews at AHA.RU] says:
1. You only need to shift single one register. rlf byte1,W ;get new bit from carry xorwf byte1,W ;get difference andlw B'00011111' ;0's will mask unchanged bits xorwf byte1,F ;update only required bits 2. You need to shift in such way through many registers. rlf byte1,W ;get new bit from carry andlw B'00111111' ;mask msb's but last addlw B'11100000' ;copy last to carry xorwf byte1,W andlw B'00011111' ;see explanation of xorwf byte1,F ;this in example above ;then ; rlf byte2,W andlw B'00111111' addlw B'11100000' ; ;and so on as many bytes as you need ;)
|file: /Techref/microchip/math/bit/rotpart.htm, 2KB, , updated: 2003/4/21 07:34, local time: 2018/3/18 13:55,
|©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/techref/microchip/math/bit/rotpart.htm"> PIC Microcontoller Bit Math Method Rotate some bits without affecting others</A>
|Did you find what you needed?|
PICList 2018 contributors:
o List host: MIT, Site host massmind.org, Top posters @20180318 RussellMc, Isaac M. Bavaresco, Sean Breheny, Neil, Van Horn, David, David C Brown, alan.b.pearce, Bob Blick, John Gardner, Brent Brown,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!