• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Assembly PIC rotate left instruction

Status
Not open for further replies.

Cantafford

Member
Hey,

I have 5 LEDs on PORTB of a PIC and I'm trying to make the LEDs light up after another with the rlf(rotate left) instruction.
I have written this code:

Code:
#include "p16F870.inc"

; CONFIG
; __config 0x3F3A
 __CONFIG _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _CP_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_ALL


cblock 0x20
 d1
 d2
 d3
endc


RES_VECT  CODE    0x0000            ; processor reset vector
    GOTO    MAIN                  ; go to beginning of program

; TODO ADD INTERRUPTS HERE IF USED

MAIN_PROG CODE                      ; let linker place main program

MAIN
    bsf STATUS, C
    clrf PORTB
   
    BANKSEL TRISB
    movlw b'11100000'
    movwf TRISB
   
    BANKSEL PORTB
    rlf PORTB
    call _delay_1s
    rlf PORTB
    call _delay_1s
    rlf PORTB
    call _delay_1s
    rlf PORTB
    call _delay_1s
    rlf PORTB
    call _delay_1s
   
   
    GOTO MAIN
   
    _delay_1s
    movlw h'D0'       
    movfw d1
    actualdelay
    decfsz d1
    goto actualdelay
    return
   
    END
However when I run it only the LED on RB0 blinks. The others do not light up at all. What am I doing wrong?
Thanks for reading.
 

Cantafford

Member
I'm simulating in proteus and I did not add any crystal to the PIC. I will try adding a 3Khz one and see if the program works.


I don't understand something tough. Prior to trying to shift the PORTB register I had some leds on the PORTB which I blinked(my other thread in which you helped me). They were blinking just fine so I'm guessing the delay should work(even if not precisly one second delay but it gave some time between blinks).
 

Jon Wilder

Active Member
Just thought I'd add this as an FYI for when you do PIC math routines...in base 2 (binary), a left shift is a simple multiply by 2 while a right shift is a simple division by 2. Just like in base 10 when you shift to the left it multiplies by 10 while a shift to the right divides by 10...it works the same in binary, just with a different multiplier. ;)
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top