Searching \ for 'Bit test commands and ports' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/ios.htm?key=port
Search entire site for: 'Bit test commands and ports'.

Truncated match.
PICList Thread
'Bit test commands and ports'
1998\12\29@182054 by Geoff Thornton

flavicon
face
Hi Piclisters,
               I have a device that I wish to connect to one of the I/O ports o
f a PIC
that can be read and written to. What I wish to know is if the PIC bit test
instuctions (BTFSS and BTFSC) are read-modify-write instructions, that is if
I perfom a bit test on the port whilst it is in input mode does the PIC read
the port and then place the value read into the ports data latch, so that if
I then change the port into an output will it then output the value read by
the bit test command. For example the port has B'11110000' on it when
configured as an input,carry out a bit test,change the port to output, will
it output B'11110000'? or will it output the value last written to it when
it was configured configured as an output?


Regards Geoff :)
==================
spam_OUTgeoffTakeThisOuTspamtechie.com

1998\12\29@183955 by Dmitry Kiryashov

flavicon
face
Geoff Thornton wrote:
>
> Hi Piclisters,
> I have a device that I wish to connect to one of the I/O ports of a PIC
> that can be read and written to. What I wish to know is if the PIC bit test
> instuctions (BTFSS and BTFSC) are read-modify-write instructions, that is if
> I perfom a bit test on the port whilst it is in input mode does the PIC read

Hello Geoff. Don't worry about that. BTFSx is read only commands.
Probably you wrongly thinking BSF or BCF command ... Make you sure
that required i/o pins in input mode and all'll be ok.

WBR Dmitry.

1998\12\30@181144 by Geoff Thornton

flavicon
face
Dmitry,
       Thanks. But that is not really what I'm after you see, I want the port t
o
set the output to what was read after the last read of the port when it was
an input and I was hoping the bit test commands would do this, can you
please advise.


> Hello Geoff. Don't worry about that. BTFSx is read only commands.
> Probably you wrongly thinking BSF or BCF command ... Make you sure
> that required i/o pins in input mode and all'll be ok.
>
> WBR Dmitry.
>

1998\12\30@194458 by James Cameron

flavicon
face
Geoff Thornton wrote:
> [...] not really what I'm after you see, I want the port to set the
> output to what was read after the last read of the port when it was
> an input and I was hoping the bit test commands would do this, can you
> please advise.

You hope vainly.  Bit test instructions (BTFSC, BTFSS) do not change
port bits.  They change PC only, if at all.  Use BCF, BSF, MOVF, et. al.
instead.

--
James Cameron                                      (.....cameronKILLspamspam@spam@stl.dec.com)

OpenVMS, Linux, Firewalls, Software Engineering, CGI, HTTP, X, C, FORTH,
COBOL, BASIC, DCL, csh, bash, ksh, sh, Electronics, Microcontrollers,
Disability Engineering, Netrek, Bicycles, Pedant, Farming, Home Control,
Remote Area Power, Greek Scholar, Tenor Vocalist, Church Sound, Husband.

"Specialisation is for insects." -- Robert Heinlein.

1998\12\30@204419 by Mike Keitz

picon face
On Thu, 31 Dec 1998 09:10:29 +1000 Geoff Thornton <geoffspamKILLspamTECHIE.COM>
writes:
>Dmitry,
>        Thanks. But that is not really what I'm after you see, I want
>the port to
>set the output to what was read after the last read of the port when
>it was
>an input and I was hoping the bit test commands would do this, can you
>please advise.

The bit test commands don't change the port's output latch.  Only
instructions with a destination of "f" (including bsf and bcf) do.

The easiest way to do what you are talking about would be
       movf    PORTB,f
This reads all the pins of the port and sets the output latch to the
value read.  Changing the port pins from input to output or vice versa by
writng the TRIS register doesn't change the output latch.  So the pins
that are newly made outputs will immediately output the level set by the
output latch.  I'm fairly sure that nothing changes the output latch
value other than software writes to the port register or turning the
power off.

___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]

1998\12\31@003030 by Geoff Thornton

flavicon
face
Thanks James and Mike,
       It looks like I will have to do a MOVF port,W followed by a BTFSS or BTF
SC
to achieve what I'm after, thanks for the help, and thank you too Dmitry.

> Geoff Thornton wrote:
> > [...] not really what I'm after you see,
>
> You hope vainly.


Regards Geoff :)
==================
.....geoffKILLspamspam.....techie.com

1998\12\31@063254 by steve

flavicon
face
> This reads all the pins of the port and sets the output latch to the
> value read.
<snip>
>  I'm fairly sure that nothing changes the output latch
> value other than software writes to the port register or turning the
> power off.

Your second statement is correct if the word "all" is noticed in the
first statement. Doing a BSF on one bit can change the output latch
value on another bit because _all_ bits of the byte are read and
rewritten, even though the instruction is specific for a single bit.

Steve.


======================================================
Steve Baldwin                Electronic Product Design
TLA Microsystems Ltd         Microcontroller Specialists
PO Box 15-680, New Lynn      http://www.tla.co.nz
Auckland, New Zealand        ph  +64 9 820-2221
email: EraseMEstevebspam_OUTspamTakeThisOuTtla.co.nz      fax +64 9 820-1929
======================================================


'Bit test commands and ports'
1999\01\03@230842 by James Cameron
flavicon
face
Geoff Thornton wrote:
> It looks like I will have to do a MOVF port,W followed by a BTFSS or
> BTFSC to achieve what I'm after, thanks for the help, and thank you too
> Dmitry.

Actually, based on what you have said before, I think what you will end
up with is something like this ...

       MOVF    port,W
       MOVWF   port
       MOVWF   file
       BTFSS   file,bit

Derivation follows ...

You said you wanted to cause the port output latches to adopt their
input states, and also to test a bit.  Using "MOVF port,F" will do the
first step, and "BTFSS" the second step, so the initial version would
be;

       MOVF    port,F
       BTFSS   port,bit

But the problem with this is that the port is read twice, once in each
instruction, and so it is possible for the state of bits to change
between each instruction.  This may not be a problem for you in your
application.  However, to avoid the double read you'd need to buffer it
in W or a file register.

       MOVF    port,W
       MOVWF   port
       BTFSS   W,bit           ; (sic)

But you can't test a bit in W.  The BTFSS works only with a port or file
register addresses.  So you must test a bit in either of those.  But you
can't test twice, so you must use a file register as a buffer.

       MOVF    port,W          ; read the port bits into W
       MOVWF   port            ; copy them back to the port
       MOVWF   file            ; save in a temporary file register
       BTFSS   file,bit        ; test the bit

And when I look at code like that I wonder if I could simplify my
external circuitry so that I don't have to code like that!

--
James Cameron                                      (cameronspamspam_OUTstl.dec.com)

OpenVMS, Linux, Firewalls, Software Engineering, CGI, HTTP, X, C, FORTH,
COBOL, BASIC, DCL, csh, bash, ksh, sh, Electronics, Microcontrollers,
Disability Engineering, Netrek, Bicycles, Pedant, Farming, Home Control,
Remote Area Power, Greek Scholar, Tenor Vocalist, Church Sound, Husband.

"Specialisation is for insects." -- Robert Heinlein.

1999\01\04@001729 by Geoff Thornton

flavicon
face
James,
       thanks very much for the additional information and stated my problem an
d
the answer I need as well, thanks for the extra information on the possible
problem I hadn't even considered, I will be adopting the code segment you
outlayed.

> {Original Message removed}

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