Cantafford
Member
Hello,
I have 8 leds connected to PORTB of PIC16f870 and I'm trying to make them turn on and off in a knight rider fashion(light up one by one from left to right then one by one from right to left). I'm using RLF and RRF instructions.
I wrote this program:
All the LEDs stay off...
I noticed that if I clear the PORTB register then I do rlf PORTB the first LED lights up. But then if I do rlf again all the LEDs are off. Perhaps I do not understand the RRF instruction properly. Shouldn't the second LED light up when I do that?
I have 8 leds connected to PORTB of PIC16f870 and I'm trying to make them turn on and off in a knight rider fashion(light up one by one from left to right then one by one from right to left). I'm using RLF and RRF instructions.
I wrote this program:
Code:
#include "p16F870.inc"
; CONFIG
; __config 0xFF3A
__CONFIG _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _CP_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_ALL
cblock 0x20
d1
d2
d3
ledctr
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
BANKSEL STATUS
bsf STATUS, C
BANKSEL TRISB
movlw b'00000000'
movwf TRISB
BANKSEL PORTB
clrf PORTB
rlf PORTB
LOOP
movlw 0x07
movwf ledctr
_RotatePortLeft
rlf PORTB
call _delay_1s
decfsz ledctr
goto _RotatePortLeft
movlw 0x07
movwf ledctr
_RotatePortRight
rrf PORTB
call _delay_1s
decfsz ledctr
goto _RotatePortRight
GOTO LOOP
_delay_1s
movlw h'D0'
movwf d1
_actualdelay
decfsz d1
goto _actualdelay
return
END
All the LEDs stay off...
I noticed that if I clear the PORTB register then I do rlf PORTB the first LED lights up. But then if I do rlf again all the LEDs are off. Perhaps I do not understand the RRF instruction properly. Shouldn't the second LED light up when I do that?