Searching \ for 'BTFSS help' 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=btfss+help
Search entire site for: 'BTFSS help'.

Truncated match.
PICList Thread
'BTFSS help'
1999\10\16@073014 by Somasundaram

flavicon
picon face
Hi,

I am a PIC newbie. I am working on 16f877. I use MPLAB 4.12 for Windows.

I have a value stored in the FileRegister 0x27 < General Purpose Register
>. That value is always between 0 and 7 (both inclusive). This value will
be dynamically varying during program execution. I need to use this value
in the instruction  BTFSS. How do I use it as required? Are there any other
methods that can be used to skip instructions based on a bit, with the bit
position dynamically varying during program execution?

Regards,
Somasundaram.

1999\10\16@081038 by Quentin

flavicon
face
I don't understand your question. What is it you want to test in the
register? Do you want to test the position of the bit and then do
instructions based on its position in the register?
Or do you want to do instuctions based on the value in the register?

You ask if there are other instructions based on a bit. Depends what you
want to do.
Other ways of testing for bits set is the MOVLW K (constant) and SUBWF
0x027,W routine
Then you test Status for Z, C or DC (BTFSS STATUS,Z) as one example.
There are many more.

Better if you explain to us what you need to do. Maybe with some short
code examples.

Quentin

Somasundaram wrote:
{Quote hidden}

1999\10\16@084159 by Dag Bakken

flavicon
face
Q> I don't understand your question. What is it you want to test in the
Q> register? Do you want to test the position of the bit and then do
Q> instructions based on its position in the register?
Q> Or do you want to do instuctions based on the value in the register?

Could it be that Somasundaram wants to dynamically change the bit
thats being tested, like this?:

BTFSS 0x27,V        ; 'V' is a variable

-DS

>> I have a value stored in the FileRegister 0x27 < General Purpose Register
>> >. That value is always between 0 and 7 (both inclusive). This value will
>> be dynamically varying during program execution. I need to use this value
>> in the instruction  BTFSS. How do I use it as required? Are there any other
>> methods that can be used to skip instructions based on a bit, with the bit
>> position dynamically varying during program execution?

1999\10\16@090751 by Somasundaram

flavicon
picon face
Sorry, I didn't put it clear.

test_for_bit equ 0x27
value_to_test equ 0x26

Say value 5 is stored in the file register 0x27
I would like to test the <test_for_bit> bit of <value_to_test>.

BTFSS value_to_test,[value stored in test_for_bit] -> Test the bit5 in the
value stored at 0x26

But the value stored in 0x27 will keep changing with program  execution.
Say, after sometime( may be while in a loop), 0x27 holds the value 3, then
the same statement must test the  bit3 of the value stored at 0x26.

Something like: I would like to count the number of 1's in the value ( at
0x26) using btfss instruction.

- Somasundaram.

At 02:09 PM 10/16/99 +0200, you wrote:
{Quote hidden}

1999\10\16@100044 by paulb

flavicon
face
Somasundaram wrote:

> Sorry, I didn't put it clear.

 *I* knew what you were getting at!

> Say value 5 is stored in the file register 0x27
> I would like to test the <test_for_bit> bit of <value_to_test>.

 This is a FAQ.  The PIC does not provide for this (and I don't recall
any other processor doing so either).  If that's *all* you need and you
want to do it fast (bad luck - it isn't!), then the suggested method is
to use a table either of the masks (DB 1,2,4,8,16,32,64,128) which you
access via a ADDWF,PCL call as a subroutine, or you use an "action
table" accessed in the same fashion, but with the index multiplied by
two or four and separate test procedures in each entry.  Use macros!

> Something like: I would like to count the number of 1's in the value
> (at 0x26) using btfss instruction.

 Ah!  That's a separate FAQ.

 I was thinking of the parity calculation that usually goes like:

       SWAPF   value,W
       XORWF   value,W
       MOVWF   temp
       RRF     temp,W
       RRF     temp,W
       XORWF   temp,F
       RRF     temp,W
       XORWF   temp,F

 and now you test bit 0 of temp for the parity.  If however you want
the overall sum of the bits, that is slightly different.  I'm sure there
is a *terribly* clever way to do that too, but I think I better go to
bed now before I send any more private messages such as the one I
thought I sent to Russell McMahon, to the list!
--
 Cheers,
       Paul B.

1999\10\16@121952 by Quentin

flavicon
face
Somasundaram wrote:
>
> Sorry, I didn't put it clear.
>
> test_for_bit equ 0x27
> value_to_test equ 0x26
>
> Say value 5 is stored in the file register 0x27
> I would like to test the <test_for_bit> bit of <value_to_test>.
>
> BTFSS value_to_test,[value stored in test_for_bit] -> Test the bit5 in the
> value stored at 0x26
Try this:
       MOVF    TEST_FOR_BIT,W
       MOVWF   TEMP1
       MOVF    VALUE_TO_TEST,W
       MOVWF   TEMP2

       ;ABOVE ONLY NEEDED IF YOU WANT TO RETAIN ORIGINAL VALUES

       MOVF    TEMP1,F
       BTFSC   STATUS,Z
       GOTO    TEST2   ;IF TEMP1 =0, CHECK ONLY LSB

TEST    BCF     STATUS,C
       RRF     TEMP2,F
       DECFSZ  TEMP1,F
       GOTO    TEST
TEST2   BTFSS   TEMP2,0
       GOTO    IF_0
       GOTO    IF_1


> Something like: I would like to count the number of 1's in the value ( at
> 0x26) using btfss instruction.

I take it this is part of your first question so change above to:
       MOVF    TEST_FOR_BIT,W
       MOVWF   TEMP1
       MOVF    VALUE_TO_TEST,W
       MOVWF   TEMP2
       CLRF    TEMP3

       ;ABOVE ONLY NEEDED IF YOU WANT TO RETAIN ORIGINAL VALUES

       INCF    TEMP1,F ;EXTRA COUNT TO CHECK LSB

TEST
       BTFSC   TEMP2,0
       INCF    TEMP3,F ;CONTAINS NUMBER OF "1" BITS
       BCF     STATUS,C
       RRF     TEMP2,F
       DECFSZ  TEMP1,F
       GOTO    TEST
       GOTO    NEXT.....

This clear for you? I did not take any "short cuts" here so that you can
see what can be done.

Quentin

1999\10\16@172801 by Byron A Jeff

face picon face
>
> Sorry, I didn't put it clear.
>
> test_for_bit equ 0x27
> value_to_test equ 0x26
>
> Say value 5 is stored in the file register 0x27
> I would like to test the <test_for_bit> bit of <value_to_test>.
>
> BTFSS value_to_test,[value stored in test_for_bit] -> Test the bit5 in the
> value stored at 0x26

There's no instruction that can do that. As posted before there's a couple of
ways of solving the problem.

1. Shift the bit to bit 0 then test bit 0.
2. Use a jump table to convert the bit number into a bit mask then apply
the mask to the original value.
3. Use a jump table with two instruction each that does the appropriate
bit test then a jump to the end. I use this technique in my NPCI interpreter.

>
> But the value stored in 0x27 will keep changing with program  execution.
> Say, after sometime( may be while in a loop), 0x27 holds the value 3, then
> the same statement must test the  bit3 of the value stored at 0x26.
>
> Something like: I would like to count the number of 1's in the value ( at
> 0x26) using btfss instruction.

Now that's a different problem. The fastest way to do this is to have a 256
byte jump table that takes the number and returns the number of bits. Probably
even better would be to half the table an test, then zero, the high bit of
the value under test. Then the table till only be 128 bytes long.

The shortest way is to use technique 1 listed above. Instead of using a
counter to variably test the bits of value_to_test, keep the same loop and
shift the value_to_test (vtt) 1 bit to the right/left each time through the
loop, testing the single bit at the end each time. So if the vtt is

10110101

You test bit 0, see that it's a one an increment the number of ones (noo)
count. Then you shift one bit to the right getting

01011010

Test bit 0 again. Now the bit to test is fixed, which the PIC does no problem.
Now since it's 0, the noo stays put. Repeat until the vtt is 0 (or exactly
8 counts if you like). When done the noo has the number of ones.

Hope this helps,

BAJ

1999\10\17@025147 by Agnes en Henk Tobbe

flavicon
face
I presume that you sort of parse the possible value in your general purpose
register and have various actions taken on various values? Is that right?
in that case you could do two things
1.  create a lookup or branche off table of the 8 possible actions.
2.  load the value in the genral purpose register in W and test its value
with xorlw
       movfw GenPurpReg, W  ; suppose this value is 5
       xorlw    5                      ;  if the value is 5 then the result
is 0
       skpnz                           ;   test the zero flag (MPLAB
assembler short for bftsc STATUS, Z)
       goto  ......                     ; do something
       start the next tet sequence......
Henk Tobbe VK2GWK / PA0ADC


{Quote hidden}

1999\10\17@072343 by Nikolai Golovchenko

flavicon
face
Hi, Somasundaram

-----Original Message-----
From: Somasundaram <spam_OUTmeisomsTakeThisOuTspamMD4.VSNL.NET.IN>
To: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU <PICLISTspamKILLspamMITVMA.MIT.EDU>
Date: Saturday, October 16, 1999 2:30 PM
Subject: BTFSS help


>Hi,
>
>I am a PIC newbie. I am working on 16f877. I use MPLAB 4.12 for Windows.
>
>I have a value stored in the FileRegister 0x27 < General Purpose Register>.
>That value is always between 0 and 7 (both inclusive). This value will
>be dynamically varying during program execution. I need to use this value
>in the instruction  BTFSS. How do I use it as required? Are there any other


BTFSS is required to have a constant bit position. But you can try
reprogramming the instruction at run-time (takes some time :)

>methods that can be used to skip instructions based on a bit, with the bit
>position dynamically varying during program execution?
>


There are no one-instruction way to check a bit with a variable position.
Try these methods:

Method 1:
       Rotate the register you are checking several times, till the bit in
question will be copied to carry bit in STATUS. Then simply check carry.

Method 2:
       Make a look-up table with 8 entries. Each entry will contain mask X
depending on a bit position N, which is also address to the table. (X = 2 ^
N) When you need to check a specific bit, find the corresponding mask, AND
the mask with the register you are checking. Then check zero bit. z = 1 if
bit N = 0, z = 0 if bit N = 1.

Method 3:
       Keep additional variable that contains dynamically changing mask.
Then apply the mask when needed.

I hope it helps.

1999\10\18@055753 by Dr. Imre Bartfai

flavicon
face
Hi,

directly not. Indirectly, see the following snippet

MaskVal EQU     0x27    ; the value you have given
i       EQU     0x28    ; or whatever
Data    EQU     0x29    ; the register to be BTFSS-ed
Mask    EQU     0x2A    ; or whatever
W       EQU     0       ; for the sake of readibility
F       EQU     1       ; same

;............

       movlw   1       ; initiate mask
       movwf   Mask    ; same
       movf    MaskVal,W
       bz      done    ; mask already done
       movwf   i       ; set up loop
       clrc
loop    rlf     Mask,F  ; shift mask into position
       decfsz  i       ; loop administration
       b       loop    ; same
done    movf    Mask,W  ; fetch mask value
       andwf   Data,W
       skpnz           ; this is that skip you wanted

Some mnemonics below may appear strange for you (e. g. clrc) but they're
supported by MPASM.

I hope this helps. But check double before using!

Regards,
Imre



On Mon, 16 Oct 2000, Somasundaram wrote:

{Quote hidden}

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