> -----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.