Searching \ for '[PIC]: Variables' 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/microchip/devices.htm?key=pic
Search entire site for: 'Variables'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Variables'
2002\09\08@204605 by Dave Gomez

flavicon
face
Hi,     it¹s the newbie again, I got a potentially silly question, but here
goes.

   I have a working program to read a temperature sensor, but I would like
to add more.  The issue is, I was thinking to save coding, and redundancy by
using a variable to describe what portb bit I¹m working with, so I could
reuse the subroutines but setting a variable to the current bit to work
with.  An example of this would be to make something like DSBIT a variable,
and then swap the value of the bit to work with.  Is this possible?

       BSF    TRISB,DSBIT    ;make RAx an input
                                        ;where DSBIT can be variable

Thanks,
Dave Gomez

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2002\09\08@205821 by A.J. Tufgar

flavicon
face
Dave,
    Your probably better off doing this by, OR'ing the tris register
rather then by setting a bit.

For instance:

MOVLW b'00000001'
IORWF TRISB, F

This will keep your tris settings the same for the rest of the bits.
But rather than load a literal into w like I did, your program could
work with a temporary register and simply use the movf command to place
it in w instead.  Make sure your bank bits are correct!!

You can also use ANDWF to set a tris bit back to 0.

Hope this helps,
Aaron

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\09\08@222617 by Clayton Mellina

picon face
       Yes it is possible.  Use the "equ" directive like this:

DSBIT   equ     "bit number goes here"

There are many other directives that you can use with MPASM and it can get
complicated.
For more information download the MPASM User's Guide from the Microchip
website.
Good luck!

{Original Message removed}

2002\09\08@234343 by Bob Barr

flavicon
face
On Sun, 8 Sep 2002 17:45:10 -0700, Dave Gomez wrote:

>Hi,
>    it¹s the newbie again, I got a potentially silly question, but here
>goes.
>
>    I have a working program to read a temperature sensor, but I would like
>to add more.  The issue is, I was thinking to save coding, and redundancy by
>using a variable to describe what portb bit I¹m working with, so I could
>reuse the subroutines but setting a variable to the current bit to work
>with.  An example of this would be to make something like DSBIT a variable,
>and then swap the value of the bit to work with.  Is this possible?
>
>        BSF    TRISB,DSBIT    ;make RAx an input
>                                         ;where DSBIT can be variable
>

Nope. The BSF and BCF instructions require that the bit number be
known at assembly time. The bit number is hard-coded into the opcode.

You can, though, use logical instructions (IORWF to set bits, ANDWF to
clear them) with your variable as a mask in W.
To do the equivalent of "BCF TRISB, 0", you would use "ANDWF TRISB, F"
with 0xFE in W. By changing the mask in W, you can modify any bit (or
bits) in the register that you'd like.


Regards, Bob

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2002\09\08@234353 by Tony Nixon

flavicon
picon face
No you can't do that.

The bit number is actually part of the [BSF, BCF etc.] instruction and
is created at compile time.

Clayton Mellina wrote:
{Quote hidden}

> {Original Message removed}

2002\09\09@001552 by Tony Nixon

flavicon
picon face
Bob Barr wrote:
>
> On Sun, 8 Sep 2002 17:45:10 -0700, Dave Gomez wrote:
>
> >
> >        BSF    TRISB,DSBIT    ;make RAx an input
> >                                         ;where DSBIT can be variable
> >
>
> Nope. The BSF and BCF instructions require that the bit number be
> known at assembly time. The bit number is hard-coded into the opcode.

You can actually do it with F series chips by rewriting the OpCode
before calling the subroutine. Although I wouldn't recommend it due to
ROM re-write limits.


--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
.....salesKILLspamspam.....bubblesoftonline.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\09@001711 by Dave Gomez

flavicon
face
Bob (and AJ),
   thanks for the workaround, sounds like IORWF and ANDWF are the way to
go.  Based on those inputs, I can use a file register to swap through my
"constants", and then use the IORWF/ANDWF.

   I'm going to play now, to see if I can get my evil creation to work as
intended.

dave

On 9/8/02 8:28 PM, "Bob Barr" <EraseMEbbarrspam_OUTspamTakeThisOuTCALIFORNIA.COM> wrote:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\09@020356 by Bob Barr

flavicon
face
On Mon, 9 Sep 2002 14:00:17 +1000, Tony Nixon wrote:

>Bob Barr wrote:
>>
>> On Sun, 8 Sep 2002 17:45:10 -0700, Dave Gomez wrote:
>>
>> >
>> >        BSF    TRISB,DSBIT    ;make RAx an input
>> >                                         ;where DSBIT can be variable
>> >
>>
>> Nope. The BSF and BCF instructions require that the bit number be
>> known at assembly time. The bit number is hard-coded into the opcode.
>
>You can actually do it with F series chips by rewriting the OpCode
>before calling the subroutine. Although I wouldn't recommend it due to
>ROM re-write limits.
>

Good point. I hadn't considered that possibility. As you say, it's not
that it's a particularly practical approach, but I guess it is
"possible" nonetheless. :=)


Regards, Bob

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\09@074207 by Olin Lathrop

face picon face
>>
       BSF    TRISB,DSBIT    ;make RAx an input
                                        ;where DSBIT can be variable
<<

The bit number in a BSF instruction must be a constant.  Again, you would
get a more detailed answer if you used plain text encoding.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\09@081536 by Russell McMahon

face
flavicon
face
> The bit number in a BSF instruction must be a constant.  Again, you would
> get a more detailed answer if you used plain text encoding.

I see received the original message as plain vanilla text.
Perhaps the phantom internet change-the-message-format enroute gremlin is at
work somewhere ? :-)

Or mayhaps the "plain text" encoding & decoding disagree and we can blame
Bill Gates.
The original headers say -

       Content-Type: text/plain; charset="ISO-8859-1"
       Content-Transfer-Encoding:  quoted-printable



                       RM

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\09@083227 by Olin Lathrop

face picon face
> I see received the original message as plain vanilla text.
> Perhaps the phantom internet change-the-message-format enroute gremlin is
at
> work somewhere ? :-)
>
> Or mayhaps the "plain text" encoding & decoding disagree and we can blame
> Bill Gates.
> The original headers say -
>
>         Content-Type: text/plain; charset="ISO-8859-1"
>         Content-Transfer-Encoding:  quoted-printable

Exactly.  Don't use quoted-printable, base64, etc.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\09@083850 by Clayton Mellina

picon face
       Sorry, I thought he meant changing it before compiling to allow different
versions at compile time like conditional assembly.

       "reuse the subroutines but setting a variable to the current bit"

I understood this as meaning he wants to write the code and then set a
variable that represents the bit that is uses to read the temperature
sensor, allowing easier relocating of the subroutine.
Good luck!

{Original Message removed}

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