please dont rip this site

PIC Microcontoller Basic Math Inc/Dec Methods

Also:

From http://www.myke.com/basic.htm: Incrementing/Decrementing "w"

Here are a couple of snippets that will allow you to increment and decrement the "w" register without affecting any file registers if you don't have "addlw"/"sublw" instructions (ie in the case of the low-end processor).

"Reg" can be any register that does not change during the execution of the three instructions. For the low-end parts, any file register can be used because there is no danger of them being updated by an interrupt handler.

To Increment:

 xorlw 0x0FF              ;  Get 1s Complement of Number
  addwf Reg, w             ;  w = Reg + (w^0x0FF)
  subwf Reg, w             ;  w = Reg + ((Reg + (w^0x0FF))^0x0FF) + 1
                           ;  w = w + 1

To decrement, the instructions are re-arranged:

 subwf Reg, w             ;  w = Reg + (2^0x0FF) + 1
  xorlw 0x0FF              ;  Get 1s Complement of Result
  addwf Reg, w             ;  w = w - 1

Archive:

Questions:


file: /techref/microchip/math/incdec/index.htm, 2KB, , updated: 2008/3/5 11:14, local time: 2008/7/20 14:20,
TOP NEW HELP FIND: 
38.103.63.16:LOG IN
©2008 PLEASE DON'T RIP! DO: LINK / DIGG! / MAKE!

 ©2008 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?
Please DO link to this page! Digg it!
<A HREF="http://www.piclist.com/techref/microchip/math/incdec/index.htm"> PIC Microcontoller Basic Math Inc/Dec Methods</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be reviewed) Just type in the box and press the Post button. (HTML welcomed!): A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Did you find what you needed?

  PICList 2008 contributors:
o List host: MIT, Site host massmind.org, Top posters @20080720 Apptech, Jinx, Xiaofan Chen, olin piclist, Alan B. Pearce, David VanHorn, William \Chops\ Westfield, Tamas Rudnai, Cedric Chang, bean,
* 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: Shultz Electronics, Timothy Weber, on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .