Searching \ for 'Setting bits with the bit number store in variable' 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=setting+bits+with
Search entire site for: 'Setting bits with the bit number store in variable'.

Truncated match.
PICList Thread
'Setting bits with the bit number store in variable'
1999\11\10@233537 by Mathew Cohen

flavicon
face
Hi,

Is it possible to set a bit of a variable when the number of the bit I want
set is contained in another variable??? The solution can be in assembler or
PicBasic.

I am currently doing this with a large case statement ( To large, there has
to be a better way)

Thanks in advance


mathew

1999\11\11@015735 by russellh

picon face
Mathew Cohen wrote:
>
> Hi,
>
> Is it possible to set a bit of a variable when the number of the bit I want
> set is contained in another variable??? The solution can be in assembler or
> PicBasic.
>
<snip>


       movf    VARIABLE1,W     ; VARIABLE1 contains the bit number
       call    BITNUMBER
       iorwf   VARIABLE2,F     ; Set bit in VARIABLE2

BITNUMBER:

       addwf   PCL
       retlw   0x01            ; Bit zero
       retlw   0x02
       retlw   0x04
       retlw   0x08
       retlw   0x10
       retlw   0x20
       retlw   0x04
       retlw   0x08            ; Bit eight

1999\11\11@032755 by Michael Rigby-Jones

flavicon
face
part 0 4450 bytes
<P><FONT SIZE=2 FACE="Arial">BITNUMBER:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addwf&nbsp;&nbsp; PCL</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x01&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Bit zero</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x02</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x04</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x08</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x10</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x20</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x04</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x08&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Bit eight</FONT>
</P>
</UL>
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Couple of typos in the lookup table, should be:</FONT>
</P>
<UL>
<P><FONT SIZE=2 FACE="Arial">BITNUMBER:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addwf&nbsp;&nbsp; PCL</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x01&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Bit zero</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x02</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x04</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x08</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x10</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x20</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">40</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp; 0x</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">80</FONT><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Bit</FONT> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">seven</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Regards</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Mike Rigby-Jones</FONT>
</P>
<BR>
</UL>
</BODY>
</HTML>
</x-html>

1999\11\11@111912 by Tracy Smith

picon face
Sorry to be blunt Matthew,

But we just discussed this a week ago:

http://www.infosite.com/%7Ejkeyzer/piclist/1999/Nov/0018.html

You oughta check the archives before asking a FAQ. But
to be fair to you, you probably didn't know this was a
FAQ. (But a 1000 other people did :). Maybe Paul ought
to consolidate all of his pic list posts and call it a
FAQ!

.lo

--- Mathew Cohen <spam_OUTmathewTakeThisOuTspamEVERYTHINGIT.NET> wrote:
{Quote hidden}

=====

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

1999\11\11@123420 by Harold M Hallikainen

picon face
On Thu, 11 Nov 1999 15:25:37 +1100 Mathew Cohen <.....mathewKILLspamspam@spam@EVERYTHINGIT.NET>
writes:
>Hi,
>
>Is it possible to set a bit of a variable when the number of the bit I
>want
>set is contained in another variable??? The solution can be in
>assembler or
>PicBasic.
>
>I am currently doing this with a large case statement ( To large,
>there has
>to be a better way)
>

       Since the number of the bit to be set is hard coded into the
instruction, you can't put a variable for the bit number in a bsf or bcf.
       A couple ways to deal with it are use of a loop with a rotate and
use of a table with the appropriate bits set.  Note that in Basic (or
other langauges), you can make an array (say BitSet[]) with the
approriate byte values (1, 2, 4, 8, 16, 32, 64, 128).  Then, in your
code, just reference BitSet[n] where n is the bit you want to set.


Harold


Harold Hallikainen
haroldspamKILLspamhallikainen.com
Hallikainen & Friends, Inc.
See the FCC Rules at http://hallikainen.com/FccRules and comments filed
in LPFM proceeding at http://hallikainen.com/lpfm

___________________________________________________________________
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: dl.http://www.juno.com/dynoget/tagj.

1999\11\11@175849 by paulb

flavicon
face
Tracy Smith wrote:

> Maybe Paul ought to consolidate all of his pic list posts and call it
> a FAQ!

 I thought of that *long* ago!  Time... Time... Time... <Sigh!>
--
 Cheers,
       Paul B.

1999\11\13@233310 by russellh

picon face
> Michael Rigby-Jones wrote:
>


Oops.
>              retlw   0x40
>              retlw   0x80            ; Bit seven
>
>      Regards
>
>      Mike Rigby-Jones


       Russell Hedges

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