;=============================================================================== ; Macro to rotate a register a variable number of positions to the right. ; The number of positions to rotate must be in another register. ; ; Input: ; value: Register with the value to be rotated. ; vacc: Access method (ACCESS or BANKED) for the value. ; positions: Register with the number of positions to rotate. ; pacc: Access method (ACCESS or BANKED) for the positions. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register. ; ; Side effects: ; Flags Z and N may be affected. ; ; Notes: ; - If both registers use access method BANKED, both must reside in the ; same bank. ; - The code is isochronous (runs always in the same number of cycles). rrvar macro value,vacc,positions,pacc btfsc positions, 2, pacc swapf value, F, vacc btfsc positions, 1, pacc rrncf value, F, vacc btfsc positions, 1, pacc rrncf value, F, vacc btfsc positions, 0, pacc rrncf value, F, vacc endm ;=============================================================================== ; Macro to rotate a register a variable number of positions to the left. ; The number of positions to rotate must be in another register. ; ; Input: ; value: Register with the value to be rotated. ; vacc: Access method (ACCESS or BANKED) for the value. ; positions: Register with the number of positions to rotate. ; pacc: Access method (ACCESS or BANKED) for the positions. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register. ; ; Side effects: ; Flags Z and N may be affected. ; ; Notes: ; - If both registers use access method BANKED, both must reside in the ; same bank. ; - The code is isochronous (runs always in the same number of cycles). rlvar macro value,vacc,positions,pacc btfsc positions, 2, pacc swapf value, F, vacc btfsc positions, 1, pacc rlncf value, F, vacc btfsc positions, 1, pacc rlncf value, F, vacc btfsc positions, 0, pacc rlncf value, F, vacc endm ;=============================================================================== ; Macro to rotate a register a fixed number of positions to the right. ; The number of positions to rotate must be a numeric constant. ; ; Input: ; value: Register with the value to be rotated. ; vacc: Access method (ACCESS or BANKED) for the value. ; positions: Constant with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register. ; ; Side effects: ; Flags Z and N may be affected. ; ; Notes: ; - The code generated may range from one to four instructions. rrcon macro value,vacc,positions if positions & b'00000100' swapf value, F, vacc endif if positions & b'00000010' rrncf value, F, vacc rrncf value, F, vacc endif if positions & b'00000001' rrncf value, F, vacc endif endm ;=============================================================================== ; Macro to rotate a register a fixed number of positions to the left. ; The number of positions to rotate must be a numeric constant. ; ; Input: ; value: Register with the value to be rotated. ; vacc: Access method (ACCESS or BANKED) for the value. ; positions: Constant with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register. ; ; Side effects: ; Flags Z and N may be affected. ; ; Notes: ; - The code generated may range from one to four instructions. rlcon macro value,vacc,positions if positions & b'00000100' swapf value, F, vacc endif if positions & b'00000010' rlncf value, F, vacc rlncf value, F, vacc endif if positions & b'00000001' rlncf value, F, vacc endif endm ;===============================================================================
;=============================================================================== ; Macro to rotate a register a variable number of positions to the right. ; The number of positions to rotate must be in another register. ; ; Input: ; value: Register with the value to be rotated. ; positions: Register with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register, WREG. ; ; Side effects: ; Flag C is affected. ; ; Notes: ; - Both registers must reside in the same bank. ; - The code is isochronous (runs always in the same number of cycles). rrvar macro value,positions btfsc positions, 2 swapf value, F rrf value, W btfsc positions, 1 rrf value, F btfsc positions, 1 rrf value, F btfsc positions, 0 rrf value, F endm ;=============================================================================== ; Macro to rotate a register a variable number of positions to the left. ; The number of positions to rotate must be in another register. ; ; Input: ; value: Register with the value to be rotated. ; positions: Register with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register, WREG. ; ; Side effects: ; Flag C is affected. ; ; Notes: ; - Both registers must reside in the same bank. ; - The code is isochronous (runs always in the same number of cycles). rlvar macro value,positions btfsc positions, 2 swapf value, F rlf value, W btfsc positions, 1 rlf value, F btfsc positions, 1 rlf value, F btfsc positions, 0 rlf value, F endm ;=============================================================================== ; Macro to rotate a register a fixed number of positions to the right. ; The number of positions to rotate must be a numeric constant. ; ; Input: ; value: Register with the value to be rotated. ; positions: Constant with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register, "WREG". ; ; Side effects: ; Flag C is affected. ; ; Notes: ; - The code generated may range from one to five instructions. rrcon macro value,positions if positions & b'00000100' swapf value, F endif if positions & b'00000011' != 0 rrf value, W endif if positions & b'00000010' rrf value, F rrf value, F endif if positions & b'00000001' rrf value, F endif endm ;=============================================================================== ; Macro to rotate a register a fixed number of positions to the left. ; The number of positions to rotate must be a numeric constant. ; ; Input: ; value: Register with the value to be rotated. ; positions: Constant with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register, WREG. ; ; Side effects: ; Flag C is affected. ; ; Notes: ; - The code generated may range from one to five instructions. rlcon macro value,positions if positions & b'00000100' swapf value, F endif if positions & b'00000011' != 0 rlf value, W endif if positions & b'00000010' rlf value, F rlf value, F endif if positions & b'00000001' rlf value, F endif endm ;===============================================================================
See also:
| file: /Techref/microchip/math/bit/variablerotate.htm, 8KB, , updated: 2012/1/24 13:36, local time: 2012/5/24 02:31,
owner: IMB-yahoo-J86,
38.107.179.234:LOG IN |
| ©2012 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/variablerotate.htm"> Rotate a byte a variable number of positions</A> |
| Did you find what you needed? |
|
PIC 16 series Microcontroller Instruction Set Reference. And his Hobby Electronics web site at http://hobby_elec.piclist.com. |
Robotics nuts!Check out http://users.frii.com/dlc/robotics/projects/botproj.htm from Dennis Clark. This guy ROCKS! He has made (and sells but also releases code, docs, etc...) for a number of cool little robotic modules including whiskers, IR proximity detect and remote control, Sonar proximity detect, PWM, Servo, compass. Most of these use the little PIC 12C508 controller which costs basically nothing and is soooo tiny.The 4 servos, 2400 baud serial servo controller is a wonder of magic and he sells the programmed chip for $8. Wow! |
.