On Tue, 20 Feb 2001, Roman Black wrote: > Drew Vassallo wrote: > > > > (don't mind the "." in front of each line... my email client seems not to > > recognize tabs or spaces in front of text) > > > > Hmm, how about this. 6 cycles regardless of which bit changed. 7 cycles if > > neither changed 0->1. > > > > . movf PORTB, w > > . andlw 0x30 ; mask out 4,5 > > . xorwf last_input, f > > . btfss last_input, 5 > > . btfss last_input, 4 > > . goto error_path > > ;; Either 4 or 5 changed 0->1 > > . movf PORTB, w > > . movwf last_input > > . > > . etc... > > error_path > > ;; Otherwise, neither changed > > ; do error stuff here > > ; > > > Hi Andrew (and thanks everyone else re this challenge!). > > But now I'm getting confused. Doesn't the xorwf > produce a 1 for every bit that has changed, and a 0 > for every unchanged bit?? > > So this is just a test for change?? How does it > just detect a 0-1 change but not a 1-0 change? > > I already had a fast routine to detect any change: > > subwf last_input,w > skpz > > so did I miss something? :o) > > I forgot to mention before too that after it detects > a 0-1 going input I need to know which input it was > to get to that routine asap. :o) Another way to approach this problem is with state machines. As I see it you have these conditions which are of interest: bit5 bit4 SA: low low SB: low high SC: high low SD: high high Then the low to high transitions may be checked slightly faster: while in state SA: movf PORTB,W andlw MASK skpnz ... However, this assumes your in a tight polling loop. If you're really multitasking, then you have the overhead of determining which state to switch to. Just a thought. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu