thankyou Michael, that works. Now a related question: 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 ----- Original Message ----- From: "Michael Rigby-Jones" To: Sent: Friday, May 04, 2001 2:00 PM Subject: Re: [PIC]:a newbie mpasm question > > -----Original Message----- > > From: sam woolf [SMTP:samw@COGS.SUSX.AC.UK] > > Sent: Friday, May 04, 2001 1:36 PM > > To: PICLIST@MITVMA.MIT.EDU > > Subject: [PIC]:a newbie mpasm question > > > > Hi everyone. Sorry if this is a silly question. > > > > I have a subroutine called PULSE that oscilates one of the pins on the > > 16F84. It does this by using BCF and BSF to set and clear that pins bit on > > porta.. so basically there are some loops and instructions like > > BCF PORTA,1 > > > > My question is: how can I modify my subroutine so that I can set which pin > > to oscillate. I want to be able to do something like: > > > > movlw 1; load w with number of pin on porta to pulse > > call ping; oscillate pin 1 > > movlw 2;now load in new pin number > > call ping ; oscillate pin 2. > > > > How can I do this? Are instructions like BCF porta,w valid? I've tried > > this and it doesn't seem to work. > > Any suggestions much appreciated. > > sam. > > > That instruction is not valid, the bit must be set at compile time. > One way of doing this is to use a lookup table to convert your bit number to > a mask > > e.g. > > GetMask: > addwf PCL,f > retlw B'00000001' > retlw B'00000010' > retlw B'00000100' > retlw B'00001000' > retlw B'00010000' > retlw B'00100000' > retlw B'01000000' > retlw B'10000000' > > > Then use the returned bit mask to toggle the port: > > movlw 1 ; select pin to toggle > call GetMask ; retrieve the appropriate mask > xorwf PORTA,f ; toggle the pin > > Everytime you XOR the port with the mask, the select bit will toggle. > > Hope this helps. > > Mike > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > > -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads