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

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Subroutines'
2003\02\01@085535 by Bob Ammerman

picon face
You need to use bit masks and indirect access:

MAINLOOP:
   movlw    ROL                  ; address of ROL
   movwf    FSR                  ; prepare for indirect access
   movlw    1 << ROLP        ; get mask for roll pin
   call        get_pulse

   movlw    PIT                    ; address of PIT
   movwf    FSR                  ; prepare for indirect access
   movlw    1 << PITP          ; get mask for pitch pin
   call         get_pulse

   etc...

   goto     MAINLOOP

get_pulse:
   clrf         INDF                 ; zero output value
   movwf    MASK               ; remember mask value

gp_2:                                    ; loop until selected pin is clear
   movf       PORTA,W
   andwf      MASK,W
   skpz
   goto        gp_2

gp_3:
   movf       PORTA,W        ; loop until select pin is set
   andwf      MASK,W
   skpnz
   goto         gp_3

gp_4:
   incf          INDF                 ; loop until pin is clear, counting
the time as we go
   call           pause
   movf        PORTA,W
   andwf      MASK,W
   skpz
   goto         gp_4

   return


Bob Ammerman
RAm Systems

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

2003\02\02@035301 by Scott Pierce

flavicon
face
Thanks for the info, Bob.  I don't quite understand how it works
though.  Is << a legal statement in ASM or did you put it there just to
show what was going on?  Could you describe bit masking in a little more
detail for me?  I'm pretty new at programming in asm.  I spent a few hours
reading through the books on Pic programming as well as searching
piclist.com for "bit mask", "bit mask subroutine", and just plain "mask"
and none of the results were related to the topic.  I'd like to understand
how it works so if I make changes to it in the future I know exactly what
it's doing.  Thanks in advance.

Sincerely,
Scott Pierce



At 08:52 AM 2/1/2003 -0500, you wrote:
{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@044350 by William Chops Westfield

face picon face
   Thanks for the info, Bob.  I don't quite understand how it works
   though.  Is << a legal statement in ASM or did you put it there just
   to show what was going on?  Could you describe bit masking in a little
   more detail for me?

   >     movlw    1 << ROLP        ; get mask for roll pin

In this case "<<" means the same thing it does in C.  Shift the left-hand
argument left by the right-hand argument number of places.

So "1<<4" gives you 16, and so on.  This is the common assembler (and
C) algorithm for converting a "bit number" to a value that had that
particular bit set, for use as mask (select only that bit using AND)
set (using OR) or clear using something like ( word &= ~(1<<4))

Note that the operation is preformed by the assembler; it doesn't
cause PIC instructions to be generated just as a result of the "<<"
operator being using.  "movlw 1<<ROLP" is just like "movlw table-1"

The PIC complicates thinking in this area by having instructions that
have a bitnumber as one of the arguments.  If you're used to dealing
with "big" processors, where everything is usually done via masks, its
easy to get confused...

BillW

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@123310 by Olin Lathrop

face picon face
> Is << a legal statement in ASM ... ?

No, but it is a legal operator.  See table 8.3 "Arithmetic Operators and
Precedence" on page 92 of DS33014G "MPASM User's Guide with MPLINK and
MPLIB".

> Could you describe bit masking in a little more
> detail for me?

"Bit masking" usually refers to doing a bitwise logical AND operation on
two multi-bit words.  The result of anding two bits is 1 if both bits are
1 and 0 otherwise.  One use of such an operation is to "mask off" some
bits in a word.  In that case, you AND the data word with a "mask".  Think
about what happens to a data bit for each of the two possible mask bit
cases.  If the mask bit is 0, then the resulting data bit will be 0
regardless of the original data bit value.  If the mask bit is 1, then the
resulting data bit will be the same as the original data bit.  The bit
pattern in mask therefore decides which data bits get passed thru and
which ones get clobbered to 0.

For example, suppose DAT contains a value you want in the low 5 bits and
garbage in the upper 3 bits.  The sequence:

   movf   dat, w    ;get the original byte
   andlw  b'00011111' ;mask in the 5 bit data value

clears the garbage bits to 0 and leaves the valid data bits alone.  The
resulting value is guaranteed to be in the 0 .. 31 range.


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

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@180158 by Bob Ammerman

picon face
> Thanks for the info, Bob.  I don't quite understand how it works
> though.

> Is << a legal statement in ASM or did you put it there just to
> show what was going on?

The '<<' is not a legal 'statement' in ASM, but it is legal in an ASM
'expression'. The argument to the movlw is evaluated, at assembly time, by
the
assembler, not at run time by the PIC.

> Could you describe bit masking in a little more
> detail for me?  I'm pretty new at programming in asm.

Sure: imaging you have a binary value, for example the value of PORTA:

xxxxxxxx

Now if you want to examine the least significant bit you simply AND that
value with the bit mask:

00000001

This wll leave you with the following:

0000000x

in other words, the result will be non-zero if and only if the least
significant bit of the value was a one.

The process of ANDing the value with the bit mask is called 'masking'.

By using the eight different masks:

00000001
00000010
00000100
00001000
00010000
00100000
01000000
10000000

You can examine any bit you want.

Bob Ammerman
RAm Systems

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

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