Searching \ for 'RLF, through Carry?' 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/index.htm?key=rlf+through+carry
Search entire site for: 'RLF, through Carry?'.

Truncated match.
PICList Thread
'RLF, through Carry?'
1998\11\28@193822 by aureo

flavicon
face
What does it mean to rotate a file _through the carry bit_ (RLF and
RRF)?

When executing RLF on portB (8 LEDs) I get this:

portB = 00000001
       RLF     portb
portB = 00000011        ; I want only one bit high and 'walking' left
       RLF     portB
portB = 00000110
       RLF     portB
portB = 00001100

What is happening?

--
Seth Fischer
Auckland, New Zealand

1998\11\28@221913 by Hans Blichfeldt

flavicon
face
At 01:29 PM 29/11/1998 +1300, Seth Fischer wrote:
>What does it mean to rotate a file _through the carry bit_ (RLF and
>RRF)?
>
>When executing RLF on portB (8 LEDs) I get this:
>
>portB = 00000001
>        RLF     portb
>portB = 00000011        ; I want only one bit high and 'walking' left
>        RLF     portB
>portB = 00000110
>        RLF     portB
>portB = 00001100
>
>What is happening?
>
>--
>Seth Fischer
>Auckland, New Zealand
>
>
You rotate through carry: E.g.;: 1101 0101      (carry e.g.; =0 - you probably
dont know)
rlf = 1010 1010  - lat zero comes from carry!   (carry now = former bit7 = 1)
rlf = 0101 0101  - last 1 comes from carry!     (carry again =1 )

When you start operation, carry may or may not be set.
Correct (secure) way is therefore:

clrf    PORTB
bcf     STATUS,C
bsf     PORTB,0

then: rlf  etc


best regards,

Hans




--
Temperature Technology
263 Gilbert Street
ADELAIDE  SA  5000

web page:       http://dove.net.au/~ttec
email:          spam_OUTttecTakeThisOuTspamdove.net.au

--

1998\11\28@224750 by Michael J. Ghormley

flavicon
face
Hans Blichfeldt wrote:

<SNIP>

> When you start operation, carry may or may not be set.
> Correct (secure) way is therefore:
>
> clrf    PORTB
> bcf     STATUS,C
> bsf     PORTB,0
>
> then: rlf  etc

I am just using the 12C50x parts right now (which is the older 12-bit core) but
none of
the instructions CLRF, BCF, or BSF clears the CARRY flag for those parts.

For my education, does one of these instructions clear the CARRY flag in the 14-
bit
parts?  Or am I just missing the point?

I would have used:
       CLRW            ; W = b'00000000', CARRY = ?
       ADDWF   W,W     ; W = b'00000000', CARRY = 0
and then done the rotate.

Am I wrong?  Did I miss something?

Michael

*************************************************************************
When the way of the Tao is forgotten, kindness and ethics must be taught.
Men must learn to pretend to be wise and good.  --  Lao Tzu
*************************************************************************

1998\11\29@031708 by engelec

picon face
Seth Fischer wrote:

> What does it mean to rotate a file _through the carry bit_ (RLF and
> RRF)?
>

to determine when it will pass over  0xFF.

{Quote hidden}

did you clear portb and w before setting bit 0 high ?

>
>
> Seth Fischer
> Auckland, New Zealand


Andre Abelian

1998\11\29@123524 by J Nagy

flavicon
face
Michael J. Ghormley wrote:

<SNIP>
>I would have used:
>        CLRW            ; W = b'00000000', CARRY = ?
>        ADDWF   W,W     ; W = b'00000000', CARRY = 0
>and then done the rotate.
>
>Am I wrong?  Did I miss something?


I do the same thing to clear the Carry, and I generally use:

       CLRW
       SUBWF   Anyfile,F

to set it. This works since the Carry is always set (as a borrow) before a
subtraction. Don't remember right now why I do it this way. I think the
data sheets were a little unclear when I first read them, so I started this
way, and never looked back.

       Jim
       Elm Electronics
Makers of unique integrated circuits
http://www.elmelectronics.com/

1998\11\29@140612 by Michael J. Ghormley

flavicon
face
J Nagy wrote:

> I do the same thing to clear the Carry, and I generally use:
>
>         CLRW
>         SUBWF   Anyfile,F
>
> to set it. This works since the Carry is always set (as a borrow) before a
> subtraction. Don't remember right now why I do it this way. I think the
> data sheets were a little unclear when I first read them, so I started this
> way, and never looked back.

I got a very nice private response from Mike DeMetz who pointed out that the
instruction BCF in the original code doesn't automatically effect the CARRY
flag, but when you do a BCF  STATUS,C it does!

I hadn't looked at the register that the BCF was acting upon.

Of course, our ADD or SUB works but it trashes W and takes more cycles.

Thanks again to Mike DeMetz,

Michael

*************************************************************************
When the way of the Tao is forgotten, kindness and ethics must be taught.
Men must learn to pretend to be wise and good.  --  Lao Tzu
*************************************************************************

1998\11\29@180503 by mkeitz

picon face
On Sun, 29 Nov 1998 13:29:44 +1300 Seth Fischer <.....aureoKILLspamspam@spam@xtra.co.nz>
writes:
>What does it mean to rotate a file _through the carry bit_ (RLF and
>RRF)?

The value of the carry bit before the instruction goes into one end of
the byte being rotated.  The bit that is rotated out of the byte goes
into the carry bit.  In somewhat graphical form, we have

rlf :  C <- dddddddd <- C
rrf :  C -> dddddddd -> C

A single rrf is merely a shift.  But repeated rrf or rlf will rotate 9
bits of data, 8 being in the data byte and one in the carry bit.

{Quote hidden}

The result you see is exactly what should happen if the C bit were 1 at
the start of the process.  To keep from getting more than one 1 bit in
the result, you should clear the carry bit before each rotate, except for
the case of 10000000 going back to 00000001.

This code will approximatley "work."  However I don't recommend that you
use it for anything other than an exercise.  It implements a true 8 bit
rotate by setting the C bit before shifting.  You would need to
initialize PORTB to 00000001 first.

       clrc            ;Always clear C
       btfsc   PORTB,7 ;except if a 1 is coming out
       setc            ; in which case set C.
       rlf     PORTB,f

Now this code does "work" but it has a couple of bad practices in it.
First, it is possible for patterns other than the desired ones containing
just one 1 to continually rotate around.  If a glitch causes the PORTB
pins to read back improperly (which can happen because of heavy loads on
the pins for example), some bits may get set when they aren't supposed
to.  Or, an all-zero pattern could persist.  We should use a better test
to be sure that the routine will "count out of" undesired states.  A
better method is to shift in zeros unless the value is X0000000.  Here's
a test for X0000000:

       movfw   PORTB
       andlw   b'01111111'     ;Test if 7 low bits are all zero.
       clrc                    ;Prepare to have C clear if they
aren't.
       skpnz
       setc
       rlf     PORTB

The other bad practice is reading back the output pins.  Sure it works
most of the time, but unless you just can't avoid it it is best to read
ports only to determine the state of the input pins.  This makes the
program less likely to malfunction due to transients from the external
circuitry.  Set up the output value in RAM instead and write it to the
port.  So we'd define a RAM varaible "shadowb" and do all the rotating on
it instead.  Combining that with the enhanced test above:

       movfw   shadowb
       andlw   b'00000001'
       clrc
       skpnz
       setc
       rlf     shadowb,f
       movfw   shadowb         ;Get bit pattern out of RAM
       movwf   PORTB           ;Write to PORTB.

This code can be optimized some, though it becomes more obscure.

       rlf     shadowb,w       ;W= dddddddX
       andlw   b'11111110'     ;See if need to put in a new 1.
       skpnz                   ;No, value OK.
       movlw   b'00000001'     ;Restart at 00000001
       movwf   shadowb         ;Update RAM variable
       movwf   PORTB           ;Update port value.

With these routines there isn't a need to initialize the shadowb/PORTB
values unless it is important that the output be correct for the first 8
shifts.


___________________________________________________________________
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\11\29@192337 by Dale Wescombe

flavicon
face
There was a usefull tip from last years Microchip Masterclass workshop that
suggested the following solution. I use it and it works fine.

RLF REG,W      ;where reg is the register who's contents you want to rotate
RLF REG        ; This does leave the W register scrambled.
              ; but you can enter with REG having "abcdefgh" and leave
with it having "bcdefgha"

For anyone who can get their hands on the latest microchip cd there is this
and several other usefull tips from the masterclass. If there is enough
interest sent to me privately I will try to post them.
wescombespamKILLspamarwnet.com.au
Dale




.....mkeitzKILLspamspam.....JUNO.COM on 11/30/98 08:12:56 AM

Please respond to pic microcontroller discussion list
     <EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU>

To:   PICLISTspamspam_OUTMITVMA.MIT.EDU
cc:    (bcc: dale.wescombe)
Subject:  Re: RLF, through Carry?




On Sun, 29 Nov 1998 13:29:44 +1300 Seth Fischer <@spam@aureoKILLspamspamxtra.co.nz>
writes:
>What does it mean to rotate a file _through the carry bit_ (RLF and
>RRF)?

The value of the carry bit before the instruction goes into one end of
the byte being rotated.  The bit that is rotated out of the byte goes
into the carry bit.  In somewhat graphical form, we have

rlf :  C <- dddddddd <- C
rrf :  C -> dddddddd -> C

A single rrf is merely a shift.  But repeated rrf or rlf will rotate 9
bits of data, 8 being in the data byte and one in the carry bit.

{Quote hidden}

The result you see is exactly what should happen if the C bit were 1 at
the start of the process.  To keep from getting more than one 1 bit in
the result, you should clear the carry bit before each rotate, except for
the case of 10000000 going back to 00000001.

This code will approximatley "work."  However I don't recommend that you
use it for anything other than an exercise.  It implements a true 8 bit
rotate by setting the C bit before shifting.  You would need to
initialize PORTB to 00000001 first.

       clrc            ;Always clear C
       btfsc   PORTB,7 ;except if a 1 is coming out
       setc            ; in which case set C.
       rlf     PORTB,f

Now this code does "work" but it has a couple of bad practices in it.
First, it is possible for patterns other than the desired ones containing
just one 1 to continually rotate around.  If a glitch causes the PORTB
pins to read back improperly (which can happen because of heavy loads on
the pins for example), some bits may get set when they aren't supposed
to.  Or, an all-zero pattern could persist.  We should use a better test
to be sure that the routine will "count out of" undesired states.  A
better method is to shift in zeros unless the value is X0000000.  Here's
a test for X0000000:

       movfw   PORTB
       andlw   b'01111111'     ;Test if 7 low bits are all zero.
       clrc                    ;Prepare to have C clear if they
aren't.
       skpnz
       setc
       rlf     PORTB

The other bad practice is reading back the output pins.  Sure it works
most of the time, but unless you just can't avoid it it is best to read
ports only to determine the state of the input pins.  This makes the
program less likely to malfunction due to transients from the external
circuitry.  Set up the output value in RAM instead and write it to the
port.  So we'd define a RAM varaible "shadowb" and do all the rotating on
it instead.  Combining that with the enhanced test above:

       movfw   shadowb
       andlw   b'00000001'
       clrc
       skpnz
       setc
       rlf     shadowb,f
       movfw   shadowb         ;Get bit pattern out of RAM
       movwf   PORTB           ;Write to PORTB.

This code can be optimized some, though it becomes more obscure.

       rlf     shadowb,w       ;W= dddddddX
       andlw   b'11111110'     ;See if need to put in a new 1.
       skpnz                   ;No, value OK.
       movlw   b'00000001'     ;Restart at 00000001
       movwf   shadowb         ;Update RAM variable
       movwf   PORTB           ;Update port value.

With these routines there isn't a need to initialize the shadowb/PORTB
values unless it is important that the output be correct for the first 8
shifts.


___________________________________________________________________
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\11\30@055810 by Stefan Sczekalla-Waldschmidt

flavicon
face
Hi,

while I4m not sure if this was the original question:

My problem was to simply rotate a 8-Bit Value.

I came to this solution:

       rrl     FLAG, F         ;msb -> carry
       bcf     FLAG, 0         ;to be sure new LSB = 0 ( trash unknown former c
arry )
       skpnc                   ;former MSB now in carry
       bsf     FLAG, 0         ;carry was set - so set LSB

or for  rlf

       rlf     FLAG, F         ; lsb -> carry
       bcf     FLAG, 7         ; trash unkown old carry
       skpnc                   ; former lsb now in carry
       bsf     FLAG, 7         ; modify MSB according carry

comments ?

Kind regards

       Stefan Sczekalla-Waldschmidt
       KILLspamsswKILLspamspamoikossw.de

1998\11\30@104250 by Dmitry Kiryashov

flavicon
face
Hello Seth. Try the following:

RLF     PORTB,W         ;copy .7 bit to carry
RLF     PORTB,F         ;rotate PORTB

or

RRF     PORTB,W         ;copy .0 bit to carry
RRF     PORTB,F         ;rotate PORTB

WBR Dmitry.


Seth Fischer wrote:
{Quote hidden}

1998\11\30@140905 by Dwayne Reid

flavicon
face
Guys - the EASY way to clear carry is use the pseudo-op 'clrc' (this is
translated by MPASM into 'bcf status,0'); the EASY way to set carry is to
use the matching pseudo-op 'setc' (translated by MPASM into 'bsf status,0').

There is a handful of pseudo-ops in the MPASM documentation that make doing
simple things easier to do and understand.

As far as the original question goes, both RLF and RRF rotate through the
carry bit.  If you want to do a standard rotate without having the carry bit
affect the result, you first have to preset the carry bit to the proper
value.  This may not be obvious - you can't just set or clear carry - it has
to be set to the 'proper' value!

If you can afford to trash W, this is very easy:

   rlf reg,W       ;rotate reg into W (discard) BUT also preset C
   rlf reg,F       ;rotate reg for real - C contains proper value


If you can't afford to trash W, it is slightly more difficult:

   clrc            ;ensure C matches bit about to be shifted into it
   btfsc reg,7     ;use bit 0 if rotating right
     setc          ;
   rlf reg,F

hope this helps.

dwayne


{Quote hidden}

Dwayne Reid   <RemoveMEdwaynerTakeThisOuTspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(403) 489-3199 voice     (403) 487-6397 fax

1998\11\30@190254 by Regulus Berdin

picon face
Hi Seth,

I think you want only 1 high bit walking LED.  What happened in your
code is that the Carry Flag is _set_ before the first RLF is executed.

If your purpose is to make a 'walking' LED, it will not be visible
because the PIC is very fast.  You should insert delays between RLFs.

Try this:

       CLRC                    ;clear carry flag
       RLF     PORTB
       CALL    DELAY           ;delay
       RLF     PORTB
       CALL    DELAY           ;delay
       RLF     PORTB
       CALL    DELAY           ;delay
       .
       .
       .

regards,
Reggie


Seth Fischer wrote:
{Quote hidden}


'RLF, through Carry?'
1998\12\01@025926 by Caisson
flavicon
face
> Van: Stefan Sczekalla-Waldschmidt <spamBeGonesswspamBeGonespamOIKOSSW.DE>
> Aan: TakeThisOuTPICLISTEraseMEspamspam_OUTMITVMA.MIT.EDU
> Onderwerp: Re: RLF, through Carry?
> Datum: maandag 30 november 1998 11:57

Hello Stefan,

> My problem was to simply rotate a 8-Bit Value.
>
> I came to this solution:

<Snip>

> comments ?

 rlf FileReg,w  'Copy High-bit into Carry
 rlf FileReg     'Rotate left File-Register

Just one drawback - It destroys the W-Reg. :-)

Greetz,
 Rudy Wieser

1998\12\01@050303 by Stefan Sczekalla-Waldschmidt

flavicon
face
Hi,

Rudy wrot:

{Quote hidden}

What would I do without the PICLIST :)

Thanks.

       Stefan

1998\12\02@023942 by Caisson

flavicon
face
> Van: Stefan Sczekalla-Waldschmidt <RemoveMEsswspamTakeThisOuTOIKOSSW.DE>
> Aan: PICLISTEraseMEspam.....MITVMA.MIT.EDU
> Onderwerp: Re: RLF, through Carry?
> Datum: dinsdag 1 december 1998 11:02
>
> Rudy wrot:
>
> > > I came to this solution:
> >
> > <Snip>

<Snip-ped another solution>

> What would I do without the PICLIST :)
>
> Thanks.
>
>         Stefan

You would do the same I would : Pulling my hear's by the root  :-)   The
things you are learning now now will be in a while (I hope) another persons
answers.  At least, that's how it worked for me.

"Jesterdaj I koeld not write PIK now I'm writing ehhh...  stuff for it"

Greetz,
 Rudy Wieser

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