RRF and RLF problem

Discussion in 'Embedded Systems and Microcontrollers' started by wannaBinventor, Jun 17, 2010.

  1. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    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.

    Code ( (Unknown Language)):
    1. Just demonstration of what I understand the code to do, not the actual code of course:
    2. [COLOR=Black]
    3. [/COLOR] [FONT=Arial, Arial, Helvetica][COLOR=Black]                                 C [/COLOR][/FONT][FONT=Arial, Arial, Helvetica][COLOR=Black]76543210[/COLOR][/FONT][FONT=Arial, Arial, Helvetica][COLOR=Black]
    4.                                 0 00000001
    5.                     RLF     0 00000010
    6.                     RLF     0 00000100
    7.                     RLF     0 00001000
    8.                     RLF     0 00010000
    9.                     RLF     0 00100000
    10.                     RLF     0 01000000
    11.                     RLF     0 10000000
    12.                     RLF     1 00000000
    13.                     RLF     0 00000001[/COLOR][/FONT][COLOR=Black]
    14. [/COLOR]
    15.  
    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: Jun 17, 2010
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Just a comment on the code color - green on gray is really hard to make out.
     
  3. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    Fixed it. It defaulted to that.
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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: Jun 18, 2010
  5. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4

    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!
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
Loading...