Dear Sam Woolf, sam woolf on 2001-05-07 09:51:05 AM wrote: > I have a subroutine called ECHO that listens for and times highs and lows on > one pin of the 16F84.. > The original code uses BTFSS PORTA, PIN > I want to be able to set which pin to listen to from outside the subroutine. > I've tried to do a mask thing, but it doesn't work: > basically I replaced BTFSS PORTA, PIN > with: > PIN0 EQU B'00000001' > PIN1 EQU B'00000010' > ; > MOVF PIN0,W > XORWF PORTA > BTFSS STATUS,Z > > This doesn't seem to be working? Any idea why not? Is there anything else >I can try? >sam Since this code needs to focus on just that one pin, you need to use AND to mask off all the other pins. Also, try using "movlw" to move (compile-time) ``literal'' constants to w; try using "movfw" to move (run-time) variables to w. ; Warning: untested code ... movlw PIN0 movwf current_pin ... wait_for_lo: call increment_hi_time_counter movfw PORTA andwf current_pin,w skpz goto wait_for_lo ... wait_for_hi: call increment_lo_time_counter movfw PORTA andwf current_pin,w skpnz goto wait_for_lo ... Isn't there a timer/counter on your PIC ? Perhaps the software would be simpler (and the timing more accurate) if you used that timer/counter on the PIC, and added external mux hardware to switch the appropriate signal to the PIC's timer pin. Sounds like you're working on a little robot with sonar sensors. I'd enjoy looking at a web page with the source code and a couple of small photos. (There's lots of "free" sites out there The 100 Best Free Web Space Providers Reviewed http://100best-free-web-space.com/Top100.htm or you could talk James Newton into letting you put them on piclist.com). -- David Cary -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads