piclist 1999\10\16\121952a >
Thread: BTFSS help
www.piclist.com/techref/index.htm?key=btfss+help
flavicon
face BY : Quentin email (remove spam text)



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

<3808A0F9.CC844D12@icon.co.za> 7bit

See also: www.piclist.com/techref/index.htm?key=btfss+help
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) BTFSS help

month overview.

new search...