See remars between code
On Mon, Jun 26, 2000 at 11:17:16AM +0100, Russell Farnhill wrote:
{Quote hidden}> Hi all,
>
> I have just started learning asm and playing around with a 16f84. I've
> already read
> a couple of tutorials from the net and now have a question. How do I create
> a function
> that uses a bit orientated command and pass its arguments via a register. I
> have
> included a small piece of code to try and illustrate.
>
> #include "p16f84.inc"
> #DEFINE PAGE0 bcf STATUS,5
> #DEFINE PAGE1 bsf STATUS,5
>
> RBpin equ 0x0C ; Port B pin number
>
>
> org 4
> goto start
>
> start
> clrf PORTB ; clear portb
> PAGE1 ; select bank 1
> clrf PORTB ; portb all output's
> PAGE0 ; select bank 0
>
> loop movlw 0 ; bit 0 portb
> movwf RBpin ; move bit select into register
> call foobar ; test function
> goto loop
>
> foobar
>
> bsf PORTB,RBpin
What you are doing here is effectively a
bsf PORTB,0x0C
So it indeed can't work.
{Quote hidden}> return
>
> END
>
> When I compile this I get the error "Argument out of range. Least
> significant bits used".
> I guess this is because bsf expects a single bit arg but I pass it a byte. I
> tried loading
> W with my bit number and then read W from within my function which worked
> fine, but if I
> need to pass 2 args I can't use W as one arg overwrites the other.
>
> Any suggestions ?
What I would do is something like :
RBpin EQU 0x0C
;bit to set is in RBpin,
; eg. b'00001000'
foobar
COMF RBpin,w ; set b'11110111' in w , complement of RBpin
ANDWF PORTB,w ; make sure bit to set is 0, store in w
XORWF RBpin,w ; make that bit '1' now, store in w
MOVWF PORTB ; set ouput port
return
I hope I got this correct.
There may be a faster (smaller) solution, but can't think of any.
Hans