PIC16F690, RLF does not loop

Thread Starter

NoJ

Joined Sep 7, 2009
3
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:

Rich (BB code):
list        p=16f690        ; list directive to define processor
#include    <P16F690.inc>        ; processor specific variable definitions

        __CONFIG        _PWRTE_ON & _WDT_OFF & _XT_OSC

loops   Equ     0x22            
loops2  Equ     0x23            

Init
        BCF        STATUS, RP0        ; Select Bank 2
        BSF        STATUS, RP1
        CLRF    ANSEL
        BSF        STATUS, RP0        ; Select Bank 1
        BCF        STATUS, RP1
        MOVLW    B'00000000'     ; PortC all outputs
        MOVWF    TRISC
        BCF     STATUS, RP0     ; Select Bank 0
        CLRF    PORTC           ; turn off all LEDs

; Emulate the running light for testing the LEDs
        CALL    Set1R
        CALL    Set2R
        CALL    Set3R
        CALL    Set4R
        CALL    Set5R
        CALL    Set6R
        CALL    Set7R
        CALL    Set8R
        CLRF    PORTC

; Now set the first pin and start looping        
        BSF      PORTC, 0
Loop
        CALL    Wait
        RLF     PORTC, 1  
        NOP
        goto    Loop 
 
;**********************************************************
; Manually setting the pins here
Set1R
        bcf        PORTC, 7
        NOP
        bsf        PORTC, 0
        CALL    Wait
        RETLW    0

Set2R
        bcf        PORTC, 0
        NOP
        bsf        PORTC, 1
        CALL    Wait
        RETLW    0

Set3R
        bcf        PORTC, 1
        NOP
        bsf        PORTC, 2
        CALL    Wait
        RETLW    0

Set4R
        bcf        PORTC, 2
        NOP
        bsf        PORTC, 3
        CALL    Wait
        RETLW    0

Set5R
        bcf        PORTC, 3
        NOP
        bsf        PORTC, 4
        CALL    Wait
        RETLW    0

Set6R
        bcf        PORTC, 4
        NOP
        bsf        PORTC, 5
        CALL    Wait
        RETLW    0

Set7R
        bcf        PORTC, 5
        NOP
        bsf        PORTC, 6
        CALL    Wait
        RETLW    0

Set8R
        bcf        PORTC, 6
        NOP
        bsf        PORTC, 7
        CALL    Wait
        RETLW    0

;**********************************************************
; Wait for 250 ms

Wait
        movlw   D'250'          
        movwf   loops 

Wai
        movlw   .110           
        movwf   loops2
Wai2    nop                    ; 
        nop
        nop
        nop
        nop
        nop
        decfsz  loops2, F
        goto    Wai2      
                               
        decfsz  loops, F  
        goto    Wai        
        retlw   0            

        end
 

Thread Starter

NoJ

Joined Sep 7, 2009
3
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
Rich (BB code):
Loop
        CALL    Wait
        RLF     PORTC, 1  
        NOP
        goto    Loop
there is not that much to debug there, as the Wait routine just NOPs to use up some time.
 

n9352527

Joined Oct 14, 2005
1,198
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?
 

rjenkins

Joined Nov 6, 2005
1,013
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.
 

Thread Starter

NoJ

Joined Sep 7, 2009
3
Thanks a lot guys!

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