RRF and RLF problem

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
I was looking @ this tutorial about RRF and RLF commands.

http://www.mstracey.btinternet.co.uk/pictutorial/progtut9.htm

Of greatest interest is the section where it demonstrates how the bit moves through the files.

Rich (BB code):
Just demonstration of what I understand the code to do, not the actual code of course:

                                  C 76543210
                                0 00000001
                    RLF     0 00000010
                    RLF     0 00000100
                    RLF     0 00001000
                    RLF     0 00010000
                    RLF     0 00100000
                    RLF     0 01000000
                    RLF     0 10000000
                    RLF     1 00000000
                    RLF     0 00000001
My problem is two fold:

I am doing the program almost just as is given in the example that I linked to. However, it doesn't clear the bit behind it as what I've put above in the code tags would indicate. It leaves the bit behind it set (IE: LED's all stay on). The same happens if I start by setting bit 7 on PORTB and RRF (just in the opposite direction, of course).

The second issue:

The bit isn't rotating through carry. The tutorial indicates that if you rotate the file all the way through carry, and then tell it "RLF PORTB,1" again, it should come back to bit 0. Now, this may be actually working, its just that I can't tell because of all of the bits staying set.
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
A couple of things, before the first RLF you should do BCF STATUS, C to make sure carry is clear.
The second is more complicated and is explained in detail in "Mid-Range MCU Family
Reference Manual" section 9.10 from the Microchip site.
Basically if the port hasn't had time to change state, then the RLF reads the old value from the port, shifts it and then writes it back.
If you want to write robust code I'd recommend never using RLF, ADD, IOR, BCF, etc instructions on a PORT. Best to use a temporary file and write that to the port.
 
Last edited:

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
A couple of things, before the first RLF you should do BCF STATUS, C to make sure carry is clear.
The second is more complicated and is explained in detail in "Mid-Range MCU Family
Reference Manual" section 9.10 from the Microchip site.
Basically if the port hasn't had time to change state, then the RLF reads the old value from the port, shifts it and then writes it back.
If you want to write robust code I'd recommend never using RLF, ADD, IOR, BCF, etc instructions on a PORT. Best to use a temporary file and write that to the port.

Thanks for that. I ran it in MPLAB SIM, even starting with BCF STATUS,0 and even the simulator showed all the bits on PORTB staying set. I am using a delay of anywhere from 1/32nd of a second to 3/32nd of a second. I figured that would be long enough.

So this problem of leaving it set as it rotates left or right is solved by doing it into a user file and then moving it to the port? That's odd.

I'll have to look at the sheet. Thanks!
 

Markd77

Joined Sep 7, 2009
2,806
Odd, the simulator should work fine with this. This problem usually shows up when the circuit is built. Probably best to post the code including the port configuration part, unless using a temporary file has solved it.
 
Top