please dont rip this site

PIC Microcontoller Bit Math Method

0/3335

Testing bits in W

Dmitry Kiryashov says:

You can't apply btfss/btfsc operations to [the W register]. You need to put W value to some temp location first and finally check temp with btfss/btfsc commands.

HINTS:

  1.  ANDLW   0x80 ; will test bit .7 in W, other bits are cleared ;-)
     ANDLW   0x40 ; test bit .6
    ;...
    

    result of operation in _Z flag (=0 means bit=1 otherwise bit=0 result to _Z=1)

    ANDLW is destructive command. You cannot restore W if you didn't save it before.

  2.  ADDLW   0x88 ; will test bits .7 and .3
    

    results of operation in _C and _DC flags. To restore initial W just ADDLW -0x88 ;-)

  3. You can also apply XORLW value command to check identity W to some value. It is useful command (sometimes) 'cause you can do comparison for alot of values and restore W after that to initial value.
    XORLW   A_CONST
    SKPNZ
    GOTO    A_CONST_MATCH
    
    XORLW   B_CONST^A_CONST ;compare with B_CONST
    SKPNZ
    GOTO    B_CONST_MATCH
    
    XORLW   C_CONST^B_CONST ;compare with C_CONST
    ;....
    
    XORLW   LAST_CONST ;last used const value -> restore initial W
    ;.....
    

David A Cary of Motorguide Pinpoint Says: " Hint #3 is explained in more detail (with macros that make it easier to write compact, correct code). "


file: /techref/microchip/math/bit/testbitsw.htm, 1KB, , updated: 2004/12/6 12:57, local time: 2008/5/16 23:53,
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/bit/testbitsw.htm"> PIC Microcontoller Bit Math Method Testing bits in W</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 @20080516 Apptech, Xiaofan Chen, Jinx, David VanHorn, Bob Axtell, Alan B. Pearce, William \Chops\ Westfield, bean, Cedric Chang, Gerhard Fiedler,
* 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, Larry Williams, David VanHorn, Bryan Whitehouse, Timothy Weber, David Challis. Peter Todd. on-going support is MOST appreciated!
* Contributors: Neil Narwani, David Cary, Elemer AM Nyiry, Philip J Taylor, Gus Calabrese of Omegadogs.com, Gautama Venegas, Patrick B. Murphy, William Chops Westfield, Peter Todd, Leslie Ellis
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .