PIC16F690, RLF does not loop

Discussion in 'Embedded Systems and Microcontrollers' started by NoJ, Sep 7, 2009.

  1. NoJ

    Thread Starter New Member

    Sep 7, 2009
    3
    0
    Hi guys,

    while toying around with a PIC16F690, I found it not looping over the carry flag when RLFing through the PORTC ports.
    I'm somewhat new to PICs and kept scratching my head for an explanation.

    The code is for a basic 8 LED chaser.

    I've included some code where I manually clear and set the respective ports, to assure that all the LEDs are connected and working before entering the main loop. Upon entering the loop everything works fine, until RC7 should be activated. The LEDs stop there, so neither RC7, nor the carry flag is set.

    Any hints on what causes this are greatly appreciated.

    The code I'm using is as follows:

    Code ( (Unknown Language)):
    1.  
    2. list        p=16f690        ; list directive to define processor
    3. #include    <P16F690.inc>        ; processor specific variable definitions
    4.  
    5.         __CONFIG        _PWRTE_ON & _WDT_OFF & _XT_OSC
    6.  
    7. loops   Equ     0x22            
    8. loops2  Equ     0x23            
    9.  
    10. Init
    11.         BCF        STATUS, RP0        ; Select Bank 2
    12.         BSF        STATUS, RP1
    13.         CLRF    ANSEL
    14.         BSF        STATUS, RP0        ; Select Bank 1
    15.         BCF        STATUS, RP1
    16.         MOVLW    B'00000000'     ; PortC all outputs
    17.         MOVWF    TRISC
    18.         BCF     STATUS, RP0     ; Select Bank 0
    19.         CLRF    PORTC           ; turn off all LEDs
    20.  
    21. ; Emulate the running light for testing the LEDs
    22.         CALL    Set1R
    23.         CALL    Set2R
    24.         CALL    Set3R
    25.         CALL    Set4R
    26.         CALL    Set5R
    27.         CALL    Set6R
    28.         CALL    Set7R
    29.         CALL    Set8R
    30.         CLRF    PORTC
    31.  
    32. ; Now set the first pin and start looping        
    33.         BSF      PORTC, 0
    34. Loop
    35.         CALL    Wait
    36.         RLF     PORTC, 1  
    37.         NOP
    38.         goto    Loop
    39.  
    40. ;**********************************************************
    41. ; Manually setting the pins here
    42. Set1R
    43.         bcf        PORTC, 7
    44.         NOP
    45.         bsf        PORTC, 0
    46.         CALL    Wait
    47.         RETLW    0
    48.  
    49. Set2R
    50.         bcf        PORTC, 0
    51.         NOP
    52.         bsf        PORTC, 1
    53.         CALL    Wait
    54.         RETLW    0
    55.  
    56. Set3R
    57.         bcf        PORTC, 1
    58.         NOP
    59.         bsf        PORTC, 2
    60.         CALL    Wait
    61.         RETLW    0
    62.  
    63. Set4R
    64.         bcf        PORTC, 2
    65.         NOP
    66.         bsf        PORTC, 3
    67.         CALL    Wait
    68.         RETLW    0
    69.  
    70. Set5R
    71.         bcf        PORTC, 3
    72.         NOP
    73.         bsf        PORTC, 4
    74.         CALL    Wait
    75.         RETLW    0
    76.  
    77. Set6R
    78.         bcf        PORTC, 4
    79.         NOP
    80.         bsf        PORTC, 5
    81.         CALL    Wait
    82.         RETLW    0
    83.  
    84. Set7R
    85.         bcf        PORTC, 5
    86.         NOP
    87.         bsf        PORTC, 6
    88.         CALL    Wait
    89.         RETLW    0
    90.  
    91. Set8R
    92.         bcf        PORTC, 6
    93.         NOP
    94.         bsf        PORTC, 7
    95.         CALL    Wait
    96.         RETLW    0
    97.  
    98. ;**********************************************************
    99. ; Wait for 250 ms
    100.  
    101. Wait
    102.         movlw   D'250'          
    103.         movwf   loops
    104.  
    105. Wai
    106.         movlw   .110          
    107.         movwf   loops2
    108. Wai2    nop                    ;
    109.         nop
    110.         nop
    111.         nop
    112.         nop
    113.         nop
    114.         decfsz  loops2, F
    115.         goto    Wai2      
    116.                                
    117.         decfsz  loops, F  
    118.         goto    Wai        
    119.         retlw   0            
    120.  
    121.         end
    122.  
     
  2. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Should be easy to spot if you run it through MPLABs simulator.
     
  3. NoJ

    Thread Starter New Member

    Sep 7, 2009
    3
    0
    Thanks for the hint blueroomelectronics, but all that MPLAB SIM revealed is the same behaviour that can be observed when putting the PIC in its circuit.

    the bit on PORTC wanders from 0x01 to 0x20, then to 0x00 and stays there for some reason.

    As the only code involved in this operation is
    Code ( (Unknown Language)):
    1.  
    2. Loop
    3.         CALL    Wait
    4.         RLF     PORTC, 1  
    5.         NOP
    6.         goto    Loop
    7.  
    there is not that much to debug there, as the Wait routine just NOPs to use up some time.
     
  4. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    Think of it this way... after you shift the only bit with the value of 1 to the carry, do you shift the carry bit immediately to bit 0? No? And what happen to the carry bit during the execution of the Wait function? Does it stay set to 1?
     
  5. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    The I/O ports are complex and do not always work like simple memory locations; you are writing one register and reading another. If a pin is allocated to a peripheral or is set as input, it will not read the same as the output register bit.

    Your 'rotate bit' code should work if you do the rotation in a memory variable, then copy that to the port.

    You may have to test the variable to be zero and set bit 0 to 're-start' the sequence after rotating the bit out past bit 7.
     
  6. NoJ

    Thread Starter New Member

    Sep 7, 2009
    3
    0
    Thanks a lot guys!

    When rotating in memory 1st and copying to port 2nd, everything works fine :)
     
Loading...