please dont rip this site

PIC Microcontroller Bit Math Method

Detecting bit changes

by Scott Dattalo

Here's a version that saves the changes and then checks if wither input went high (but doesn't check high to lows):

    movf   PORTB,w         ;get current state
    xorwf  last_in,w       ;compare to previous
    xorwf  last_in,f       ;save changes
    andwf  last_in,w       ;did either go high?

    andlw  (1<<4)||(1<<5)  ;only want bits 4 and 5
    skpnz
     goto  nolowtohighs

; either bit4 or bit5 went from 0 to 1
...

nolowtohighs

Here's one that does a check and then saves the changes (and will allow you to test high to lows if you want)

    movf   PORTB,w         ;get current state
    movwf  temp
    xorwf  last_in,w       ;compare to previous
    andwf  temp,w          ;did either go high?

    andlw  (1<<4)||(1<<5)  ;only want bits 4 and 5

    skpnz
     goto  save changes

; low to high change - do whatever

    btfsc  temp,4
     do whatever for bit 4 going high
    btfsc  temp,5
     do whatever for bit 5 going high

save_changes:
    movf   temp,w
    xorwf  last_in,w
    xorwf  last_in,f

Also:

See also:

Andrew D. Vassallo says:

Bob Ammerman says:
 ; compare register "last_inputs" to
  current PORTB reading ;
 ; direct computation of ~last_inputs & new_value
    comf last_inputs,W
    andwf PORTB,W
    andlw (1<<4)|(1<<5)
    skpz
     goto got_a_0_to_1 

file: /Techref/microchip/math/bit/detchng.htm, 2KB, , updated: 2016/4/11 09:21, local time: 2017/10/23 03:24, owner: JMN-EFP-786,
TOP NEW HELP FIND: 
54.81.131.189:LOG IN

 ©2017 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! / MAKE! / 

<A HREF="http://www.piclist.com/techref/microchip/math/bit/detchng.htm"> PIC Microcontroller Bit Math Method - Detecting bit changes</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. 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: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2017 contributors:
o List host: MIT, Site host massmind.org, Top posters @20171023 RussellMc, Van Horn, David, James Cameron, Sean Breheny, IVP, alan.b.pearce, Neil, David C Brown, Bob Blick, Denny Esterline,
* 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!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .