Searching \ for '[PIC]: Not use the address but what is inside that' 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: 'Not use the address but what is inside that'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Not use the address but what is inside that'
2001\01\04@130607 by imenez Yamasaki

flavicon
face
   Hi all:

   What I want to do exactly is to have to variables, one with the port I
want to use (let4s call it "port") and another one with the bit I want to
read (let4s call it "bit") then use the instruccion btfss.

   Something like this:

   porta --> port
   3 -->    bit

   btfss    port, bit

   What should mean btfss porta, 3

   Is it possible?

   As far as I know, when you use btfss what is read is the address of
port, not what this address contains.

   I guess I can use somenthin like this:

   port    equ    h'0005'        ;port = porta

   and when I want portb, I should use (port + 1) the same for "bit", but,
is there any other way?

   Any help will be apreciate,

   Thanks in advance,

   Gonzalo

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@132939 by M. Adam Davis

flavicon
face
There is an inderirection register that you can use to set the port, upon
which you can perform port accesses.  As far as specifying the bit to
access, there are methods contained in the faq.  There isn't an easy way
to do it, but it is possible.

First read the information in the data sheet about the indirection
register (register 0 on most parts, INDC if I remember correctly)

-Adam

"What?  I couldn't very well say 'INDC, IIRC'..."

Gonzalo Jimenez Yamasaki wrote:
{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@135018 by Drew Vassallo

picon face
>     What I want to do exactly is to have to variables, one with the port I
>want to use (let4s call it "port") and another one with the bit I want to
>read (let4s call it "bit") then use the instruccion btfss.
>
>     Something like this:
>
>     porta --> port
>     3 -->    bit
>
>     btfss    port, bit
>
>     What should mean btfss porta, 3
>
>     Is it possible?

I don't believe you can use a file (e.g. "bit") as a variable in this
instance.  It would return the location of the register, not the contents.
You would have to set "bit EQU 0x03" to make it work in this case.  Even so,
you couldn't change it by incrementing the register.  You'd have to use "bit
+ 1" next time around and have already defined "bit + 1 EQU 0x04" or
whatever bit you want to test.

You'd be better off just saving the contents of the port to a temporary
register and checking the bits by shifting them into carry:

 movf  PORTB, 0
 movwf  port_contents
 movf  bit_to_test, 0  ; check whatever bit # you want
 movwf  count
 sublw  0x07      ; must be <= 7
 btfss  STATUS, C
 goto  skip_check
 incf  count      ; bit 0 needs one rrf
 clrc
Loop
 rrf  port_contents
 decfsz  count
 goto  Loop
 btfss  STATUS, C    ; check the desired bit
 goto  bit_was_clear
 goto  bit_was_set
skip_check
....


Hope this is what you need.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@144010 by Drew Vassallo

picon face
Hmm, it appears that the spaces were stripped from my message, leaving the
loops unlabeled.  Oh well, here's the same thing with markers to validate
the spaces:

{Quote hidden}

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@153438 by Olin Lathrop

face picon face
>     What I want to do exactly is to have to variables, one with the port I
> want to use (let4s call it "port") and another one with the bit I want to
> read (let4s call it "bit") then use the instruccion btfss.
>
>     Something like this:
>
>     porta --> port
>     3 -->    bit
>
>     btfss    port, bit
>
>     What should mean btfss porta, 3
>
>     Is it possible?

If "bit" and "port" are assembler variables, then yes.  No matter how you
may try to disguise it, the register and bit referenced by a BTFSS
instruction are hard coded into the instruction, and therefore must be known
at assembly time.

If you need to dynamically select a register at runtime, use an FSR.  There
are more options for dynamically selecting a bit, most of which require bit
shifting or mask selecting.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, spam_OUTolinTakeThisOuTspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@154917 by Petra Weeks

flavicon
picon face
Hi Gonzalo

I think it may help if you could tell us what determines which "bit" of
PORTA you are testing.

Petra

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@162742 by imenez Yamasaki

flavicon
face
   Well I4ve found FSR and INDF, but that can solve half my problem... with
this I can select porta, portb or portc easily, but what about bits, how can
I choose between them?

   Petra: I should use any port, and any bit... my idea is to make a
subrutine to read a bit using sofware filter...

   Regards,

   Gonzalo

----- Mensaje original -----
De: "Olin Lathrop" <.....olin_piclistKILLspamspam@spam@EMBEDINC.COM>
Para: <PICLISTspamKILLspamMITVMA.MIT.EDU>
Enviado: Jueves 4 de Enero de 2001 2:31 PM
Asunto: Re: [PIC]: Not use the address but what is inside that address


| >     What I want to do exactly is to have to variables, one with the port
I
| > want to use (let4s call it "port") and another one with the bit I want
to
| > read (let4s call it "bit") then use the instruccion btfss.
| >
| >     Something like this:
| >
| >     porta --> port
| >     3 -->    bit
| >
| >     btfss    port, bit
| >
| >     What should mean btfss porta, 3
| >
| >     Is it possible?
|
| If "bit" and "port" are assembler variables, then yes.  No matter how you
| may try to disguise it, the register and bit referenced by a BTFSS
| instruction are hard coded into the instruction, and therefore must be
known
| at assembly time.
|
| If you need to dynamically select a register at runtime, use an FSR.
There
| are more options for dynamically selecting a bit, most of which require
bit
| shifting or mask selecting.
|
|
| *****************************************************************
| Olin Lathrop, embedded systems consultant in Devens Massachusetts
| (978) 772-3129, .....olinKILLspamspam.....embedinc.com, http://www.embedinc.com
|
| --
| http://www.piclist.com hint: The PICList is archived three different
| ways.  See http://www.piclist.com/#archives for details.
|
|
|

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@163820 by M. Adam Davis

flavicon
face
As noted in my previous message you could use the routine from the
piclist.com faq:
http://www.piclist.com/techref/microchip/math/bit/mask.htm

; Convert 3-bit number (0-7) in INDEX to a 8-bit mask (00000001 ...
; 10000000) in BitP.
       movfw   INDEX
       andlw   b'00000011'     ;Start with half of the mask.
       movwf   BitP
       incf    BitP, W         ;The 4-bit converter
       btfsc   BitP, 1
       iorwf   BitP, F
       incf    BitP, F
       btfsc   INDEX, 2        ;Is it high 4 bits?
       swapf   BitP, F

So you make your number into a mask, then you can apply that mask to the
number from the port.  Your value (set or clear) will show up in the
status register, zero bit.

-Adam

Gonzalo Jimenez Yamasaki wrote:
{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@170131 by imenez Yamasaki

flavicon
face
   Perfect!!! thanks a lot!!!

   Gonzalo


----- Mensaje original -----
De: "M. Adam Davis" <KILLspamadavisKILLspamspamUBASICS.COM>
Para: <RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU>
Enviado: Jueves 4 de Enero de 2001 4:39 PM
Asunto: Re: [PIC]: Not use the address but what is inside that address


| As noted in my previous message you could use the routine from the
| piclist.com faq:
| www.piclist.com/techref/microchip/math/bit/mask.htm
|
| ; Convert 3-bit number (0-7) in INDEX to a 8-bit mask (00000001 ...
| ; 10000000) in BitP.
|         movfw   INDEX
|         andlw   b'00000011'     ;Start with half of the mask.
|         movwf   BitP
|         incf    BitP, W         ;The 4-bit converter
|         btfsc   BitP, 1
|         iorwf   BitP, F
|         incf    BitP, F
|         btfsc   INDEX, 2        ;Is it high 4 bits?
|         swapf   BitP, F
|
| So you make your number into a mask, then you can apply that mask to the
| number from the port.  Your value (set or clear) will show up in the
| status register, zero bit.
|
| -Adam
|

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@180126 by Bob Ammerman

picon face
You need to map from a bit number to a bitmask, then use logical
instructions:

To turn on bit "BitNum" of port "PortNum":

   movf       PortNum,W
   movwf    FSR

   movf       BitNum,W
   call         BitToMask
   iorwf       INDF,F

To turn off bit "BitNum" of port "PortNum":

   movf       PortNum,W
   movwf    FSR

   movf       BitNum,W
   call          BitToMask
   xorlw       0xFF
   andwf      INDF,F


BitToMask:
   addwf    pcl
   retlw    1
   retlw    2
   retlw    4
   retlw    8
   retlw    16
   retlw    32
   retlw    64
   retlw    128

{Original Message removed}

2001\01\04@180336 by Olin Lathrop

face picon face
>     Well I4ve found FSR and INDF, but that can solve half my problem...
with
> this I can select porta, portb or portc easily, but what about bits, how
can
> I choose between them?

You need to spend some time learning the instruction set and how to use it.
There are lots of ways of "selecting" a bit.  One way is to rotate the byte
until the desired bit ends up in C.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, spamBeGoneolinspamBeGonespamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@224341 by Drew Vassallo

picon face
>You need to spend some time learning the instruction set and how to use it.
>There are lots of ways of "selecting" a bit.  One way is to rotate the byte
>until the desired bit ends up in C.

Didn't I just send a routine that does this?

If it wasn't posted, let me know.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@224543 by Drew Vassallo

picon face
The original problem was:

> >     Petra: I should use any port, and any bit... my idea is to make a
> > subrutine to read a bit using sofware filter...

How is the routine below solving this problem?  It looks useful for DEFINING
a bit to output, not reading a bit in.

{Quote hidden}

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@232048 by Bob Ammerman

picon face
----- Original Message -----
From: Drew Vassallo <TakeThisOuTsnurpleEraseMEspamspam_OUTHOTMAIL.COM>
To: <RemoveMEPICLISTspamTakeThisOuTMITVMA.MIT.EDU>
Sent: Thursday, January 04, 2001 10:45 PM
Subject: Re: [PIC]: Not use the address but what is inside that address


> The original problem was:
>
> > >     Petra: I should use any port, and any bit... my idea is to make a
> > > subrutine to read a bit using sofware filter...
>
> How is the routine below solving this problem?  It looks useful for
DEFINING
> a bit to output, not reading a bit in.

Oops, sorry -- lost track of the original request. Here is the code to check
a bit:

; To test bit "BitNum" or port "PortNum"

   movf    PortNum,W
   movwf FSR
   movf    BitNum,W
   call       BitToMask
   andwf  INDF,W

; At this point Z is set if PortNum,BitNum was clear
;  Z is clear if PortNum,BitNum was set

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)


{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\05@111241 by imenez Yamasaki

flavicon
face
| >You need to spend some time learning the instruction set and how to use
it.
| >There are lots of ways of "selecting" a bit.  One way is to rotate the
byte
| >until the desired bit ends up in C.
|
| Didn't I just send a routine that does this?

   Yes, you did...

   Thanks,

   Gonzalo

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservEraseMEspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2001\01\05@150611 by Olin Lathrop

face picon face
> >You need to spend some time learning the instruction set and how to use
it.
> >There are lots of ways of "selecting" a bit.  One way is to rotate the
byte
> >until the desired bit ends up in C.
>
> Didn't I just send a routine that does this?
>
> If it wasn't posted, let me know.

You may very well have sent such a routine before you read my reply.  With
the various mail servers between me and the PIC list and probably on your
end as well, messages can appear out of order for up to 12 hours or more.  I
reply to messages as I read them (and I suspect many others do to), so a
different reply can even be further down in the IN box.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, EraseMEolinspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservEraseMEspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


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