Searching \ for '[PIC]:Indirect Addressing Help' 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: 'Indirect Addressing Help'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Indirect Addressing Help'
2001\03\28@110634 by Shawn Yates

flavicon
face
Hello all,

       I have a problem that I thought Indirect Addressing would solve, but
I don't think it will.  Please read this over and throw any ideas you may
have my way.

       I have three pins (say RB0, RB1 and RB2) that all receive the exact
same format of serial data at different times.  I want to use one section of
code to receive data on any one pin at a time.  Since I have to use BTFSx
instructions to sample the pin, how can I make the code change which pin its
reading?  I can already determine which pin I need to be reading at any
given time, but I just don't see how to transfer that information in a
usable way.  I have had it working up till now by copying the code three
times and changing the literal in the BTFSx instruction, but now I am
starting to run low on code space and want to shrink the amount of code.

       If there is some other way to read the pins (not usint BTFSx), then
I am open to that.  The data stream is very slow compared to the processor
clock so I have lots of cycles to do things if need be.

       Any ideas?

TIA,

Shawn

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


2001\03\28@135352 by Olin Lathrop

face picon face
>         I have three pins (say RB0, RB1 and RB2) that all receive the
exact
> same format of serial data at different times.  I want to use one section
of
> code to receive data on any one pin at a time.  Since I have to use BTFSx
> instructions to sample the pin, how can I make the code change which pin
its
> reading?  I can already determine which pin I need to be reading at any
> given time, but I just don't see how to transfer that information in a
> usable way.  I have had it working up till now by copying the code three
> times and changing the literal in the BTFSx instruction, but now I am
> starting to run low on code space and want to shrink the amount of code.

There are so many ways to do this, you will probably get many different
suggestions.

One way would be to have a subroutine that does all the processing for a
bit.  You pass it a mask for the port B bit it is supposed to work on.  The
subroutine ANDs the mask and the port B value to determine whether the bit
is 1 or 0.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, spam_OUTolinTakeThisOuTspamembedinc.com, 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


2001\03\28@140205 by Dan Michaels

flavicon
face
Shawn Yates wrote:

>
>        I have three pins (say RB0, RB1 and RB2) that all receive the exact
>same format of serial data at different times.  I want to use one section of
>code to receive data on any one pin at a time.  Since I have to use BTFSx
>instructions to sample the pin, how can I make the code change which pin its
>reading?
.....
>        If there is some other way to read the pins (not usint BTFSx), then
>I am open to that.  The data stream is very slow compared to the processor
>clock so I have lots of cycles to do things if need be.
>


Hi Shawn, there is "always" another way. In this case you can use
"masking". Declare a variable to hold the mask, and then check the
mask against the data:

                       ; mask values corresponds to specific port pins.
MASK0 = 00h             ; (0000'0001) mask for bit 0.
MASK1 = 01h             ; (0000'0010)  "    "   "  1.
MASK2 = 04h             ; (0000'0100)  "    "   "  2.
...
maskhold  = 20h         ; variable declaration.

       movlw   MASKx           ; load mask variable
       movwf   maskhold
       call    portpin_test
       .....

portpin_test
       movf    PORTB,W         ; read all 8 port pins.
       andwf   maskhold,W      ; mask out pin of interest.
       btfss   STATUS,Z        ; test whether relevant pin is set/clr.
       ...
       return


hope this helps,
- dan michaels
http://www.oricomtech.com
=====================

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


2001\03\28@140927 by Shawn Yates

flavicon
face
Got it.

So I have one routine to receive, it just reads the whole port and tests the
Z flag after the AND with the mask.  I like it.

Thanks a lot!!

Shawn

{Original Message removed}

2001\03\28@150552 by Dan Michaels

flavicon
face
oops, slight misque ---

>
>                        ; mask values corresponds to specific port pins.
>MASK0 = 00h             ; (0000'0001) mask for bit 0.
>MASK1 = 01h             ; (0000'0010)  "    "   "  1.
>MASK2 = 04h             ; (0000'0100)  "    "   "  2.
>...

MASK0 = 01h             ; (0000'0001) mask for bit 0.
MASK1 = 02h             ; (0000'0010)  "    "   "  1.
MASK2 = 04h             ; (0000'0100)  "    "   "  2.

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


2001\03\28@185117 by Bob Ammerman

picon face
Sure, instead of using BTF instructions use logical instructions. Here is an
example:

Given:    BMASK is a register containing the bitmask for the particular port
pin you are working on.

Instead of:


  btfsc    PORTB,x

use:

   movf    PORTB,W
   andwf  BMASK,W
   skpz

Instead of:

   btfss    PORTB,x

use:

   movf    PORTB,W
   andwf  BMASK,W
   skpnz

Instead of:

   bsf    PORTB,x

use:

   movf    BMASK,W
   iorwf    PORTB,F

instead of:

   bcf    PORTB,x

use:

   comf    BMASK,W
   andwf  PORTB,F

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

{Original Message removed}

2001\03\29@091340 by Shawn Yates

flavicon
face
Bob,

       Thanks for the detail.  I hadn't thought of it before, but using
your code I can control multiple output at the same time by having more than
one bit set in the mask.  Very usefull.

Shawn

{Original Message removed}

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