Searching \ for 'Direct, Indirect when referencing BTFSC FILE, BIT' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=direct+indirect
Search entire site for: 'Direct, Indirect when referencing BTFSC FILE, BIT'.

Truncated match.
PICList Thread
'Direct, Indirect when referencing BTFSC FILE, BIT'
1999\10\31@194745 by John Considine

flavicon
face
I am trying to have a variable be decremented and that result be used as
the BTFSC test bit

For example

movlw    H'07'
movwf    TestBit
decf        TestBit, 1
btfsc       PORTB, TestBit

Is this possible,  I tried using indirect referencing like

movlw    TestBit
movwf    FSR
btfsc       PORTB, INDF

but that will not work. Any suggestions.
Thanks

1999\10\31@201502 by Tony Nixon

flavicon
picon face
John Considine wrote:
>
> I am trying to have a variable be decremented and that result be used as
> the BTFSC test bit
>
> For example
>
> movlw    H'07'
> movwf    TestBit
> decf        TestBit, 1
> btfsc       PORTB, TestBit
>
> Is this possible,  I tried using indirect referencing like
>
> movlw    TestBit
> movwf    FSR
> btfsc       PORTB, INDF
>
> but that will not work. Any suggestions.
> Thanks

You cannot use BTFSC like that. (?)

You may need to try something like...

       movlw b'10000000'
       movwf TestBit

       - - - -

       bcf status,carry        ; shift bit one position to right
       rrf TestBit
       btfsc status,carry      ; if carry = 1 then reset bit 7 = 1
       rrf TextBit

       - - - -

       movf PORTB,w            ; do bit comparison on port
       andwf TestBit,w
       btfsc status,Z
       goto BitIsOne

--
Best regards

Tony

http://www.picnpoke.com
Email spam_OUTsalesTakeThisOuTspampicnpoke.com

1999\10\31@213701 by Dennis Plunkett

flavicon
face
At 12:13 1/11/99 +1100, you wrote:
{Quote hidden}

I realy can't see what is going on here,
If you are decementing to see what the results is you can have either a 1
or a 0, no matter what.
Or is it that you are trying to use this as a mask for testing of each
potential bit location.
Ah yes the latter
If the latter is true, then there is the problem in that the compiler +
opcodes expect this to be a litteral value, hence the method used by Tony.

E.G BTFSC myval, 0-7, where the 0 to 7 are fixed.

If this is the case then perhaps you could waste a bit of space
and use a table type function

                                       ;Test byte is the location to be compare
d with the counter
                                       ;value. This makes the code resuable for
testing of bit
                                       ;compares for any direct RAM location
               movf    PORTB
               movwf   test_byte,w     ;do this bit on pre entry

               counter         ;the current bit location to look at
                                       ;the counter is 0-7 and indicates the bi
t that we want to look
                                       ;at. Note that this vale must be preload
ed and maintained by
                                       ;the calling code

                                       ;function body


;***********
bit compare:
;***********
;                                       Perequsites
;                                       ===========
;                                       Counter must be set with the bit to test
;                                       w must contain the table offset
;                                       test_byte must be the byte to test to
;                                       LOCAL variable  :- test_byte -> effectiv
e only, not to be preserved

               movlw   3               ;so that we get to the correct location
in the table
               addw    counter
               add     pcl,w           ;point to the location to jump to
TABLE
               nop
               nop
               nop
               btfsc   test_byte,0
               goto    return_true
               goto    return_false
               btfsc   portb,1
               ...

return_true
               do stuff

return_false
               do other stuff

I know that there is stuff missing in the table but you can get the general
idea. Tonys stuff also works, but
resides on the assumption that the value (As you requested) is dectmented
by one each time, where the table value lets you attack any bit at any time.

On further thinking Tonys way on bit test will work at all times, so ignore
the rubbish I just came up with

Dennis

1999\10\31@222932 by paulb

flavicon
face
John Considine wrote:

> I am trying to have a variable be decremented and that result be used
> as the BTFSC test bit

 This is a VFAQ.  There is no bit pointer function on the PIC or AFAIK
*any* microcontroller.

 Tony's reply noted; but I suspect you don't really need, possibly
even want, to read PORTB each time.  Would this not do?:

   movlw   8
   movwf   TestBit         ; count from 8
   movf    PORTB,W
   movwf   shiftr          ; copy of PORTB
nexbit:
   btfsc   shiftr,7        ; test MSB
   goto    bitset          ; the bit denoted by TestBit is set
   rlf     shiftr          ; roll the bits
   decfsz  TestBit,F       ; look at next bit
   goto    nexbit
noneset:                    ; fall through if none set.

bitset:                     ; the bit denoted by TestBit is set

 If you use 0 and 1 rather than W and F for the "destination" you are
really *asking* for trouble!
--
 Cheers,
       Paul B.


'Direct, Indirect when referencing BTFSC FILE, BIT'
1999\11\01@075448 by Byron A Jeff
face picon face
>
> I am trying to have a variable be decremented and that result be used as
> the BTFSC test bit
>
> For example
>
> movlw    H'07'
> movwf    TestBit
> decf        TestBit, 1
> btfsc       PORTB, TestBit
>
> Is this possible,

Nope.

> I tried using indirect referencing like
>
> movlw    TestBit
> movwf    FSR
> btfsc       PORTB, INDF
>
> but that will not work. Any suggestions.

There was a discussion of this a while ago on the list. The bit number
for a btfsc instruction is fixed. Two possible ways of handling it.

1. Use a jump table to translate the bit number into a bit mask. Then use
the mask to test the required bit (using and)  then btfsc off the zero flag.

2. Build a jump table with 8 btfsc's and their associated no jumps in it.

But you cannot perform the task they way you like unfortunately.

BAJ

1999\11\01@105630 by Tracy Smith

picon face
--- John Considine <jconsispamKILLspamMAGICNET.NET> wrote:
> I am trying to have a variable be decremented and
> that result be used as
> the BTFSC test bit
>
> For example
>
> movlw    H'07'
> movwf    TestBit
> decf        TestBit, 1
> btfsc       PORTB, TestBit

Here are a couple of ideas for getting 1<<TestBit

10 cycles:

2^n:
   clrw
   btfsc    TestBit,2
    movlw   b'11111100'
   addwf    TestBit,f

   incf     TestBit,w
   btfsc    TestBit,1
    iorwf   TestBit,f

   incf     TestBit,f

   skpnc
    swapf   TestBit,f

.........
another way (7 cycles [including the call])

two_to_n:
   andlw    7
   addwf    pcl,f
   retlw    1
   retlw    2
   retlw    4
   retlw    8
   retlw    0x10
   retlw    0x20
   retlw    0x40
   retlw    0x80


............
or probably more to the point

   movf     portb,w
   movwf    portb_shadow

   btfss    TestBit,2
    swapf   portb_swadow,f


   btfss    TestBit,0
    rlf     portb_shadow,f

   movlw    b'10000000'
   btfss    TestBit,1
    movlw   b'00100000'

   andwf    portb_shadow,f

   skpnz
    goto    _the_bit_is_set

.lo

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...