This is my overall code:
INVERTED equ 20h
COUNT equ 21h
DE1 equ 25h
DE2 equ 26h
include <p16F877A.inc>
__CONFIG 0x3F7D
org 0
bsf STATUS, RP0
movlw h'00'
movwf TRISB
movlw b'00001110'
movwf OPTION_REG
bcf STATUS, RP0
movlw h'FF'
movwf COUNT
call counter
goto eop
counter
loop call invert
movf INVERTED,0
movwf PORTB
sleep
decfsz COUNT
goto loop
RETURN
invert
movlw h'00'
movwf INVERTED
BTFSC COUNT,0 ;set the right bits in portb
BSF INVERTED, 7
BTFSC COUNT,1
BSF INVERTED, 6
BTFSC COUNT,2
BSF INVERTED, 5
BTFSC COUNT,3
BSF INVERTED, 4
BTFSC COUNT,4
BSF INVERTED, 3
BTFSC COUNT,5
BSF INVERTED, 2
BTFSC COUNT,6
BSF INVERTED, 1
BTFSC COUNT,7
BSF INVERTED, 0
RETURN
delay ; 2 cycles for call
clrf DE1 ; 1 cycle to clear counter variable
Dloop decfsz DE1,F ; These two instructions provide a
goto Dloop ; (256 * 3) -1 cycle count
return ; 2 cycles for return
eop movlw h'00'
movwf PORTB
sleep
movlw h'FF'
movwf PORTB
sleep
end