i have problem with indirect addressing in PIC16f877A, i wanna learn the indirect addressing so i saw the datasheet example and it was easy it clears memory from address 0x20 to 0x2f like this
so i decided to write my 1st program, i wanna save data indirectly and retrieve it indirectly and display it on portb the data is 0x01,0x02,0x04 which will blink leds on portb with time difference 0.5 sec between each display and before the whole process but
unfortunately the code doesn't work correctly it blink RB5,RB1,RB0 unlike what i wrote(RB0,RB1,RRB2) that my code here
Rich (BB code):
ORG 0x500
BCF PCLATH,4
BSF PCLATH,3 ;Select page 1
;(800h-FFFh)
CALL SUB1_P1 ;Call subroutine in
: ;page 1 (800h-FFFh)
:
ORG 0x900 ;page 1 (800h-FFFh)
SUB1_P1
: ;called subroutine
;page 1 (800h-FFFh)
:
RETURN ;return to
;Call subroutine
;in page 0
;(000h-7FFh)
unfortunately the code doesn't work correctly it blink RB5,RB1,RB0 unlike what i wrote(RB0,RB1,RRB2) that my code here
Rich (BB code):
;------------------------------------------
;device configuration
;------------------------------------------
processor 16f877A
#include<p16F877a.inc>
__config _CP_OFF&_DEBUG_OFF&_WRT_OFF&_CPD_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC
;------------------------------------------
;variable decleration
;------------------------------------------
cblock 0x24
d1
d2
d3
endc
;------------------------------------------
;device initialise
;------------------------------------------
org 0x00
bsf STATUS,RP0
movlw 0x00
movwf TRISB
bcf STATUS,RP0
movwf PORTB
;------------------------------------------
;load data in 0x20 ~ 0x22 with Fh,Eh,Dh
;------------------------------------------
movlw 0x20
movwf FSR
movlw 0x01
movwf INDF
INCF FSR,F
movlw 0x02
movwf INDF
INCF FSR,F
movlw 0x04
movwf INDF
;------------------------------------------
call long_delay;wait 0.5 sec
;------------------------------------------
;read data from 0x20 ~ 0x22 and show it on PORTB for 0.5 sec for each address then stop
;------------------------------------------
movlw 0x20
movwf FSR
next:
movf INDF
movwf PORTB
call long_delay
INCF FSR,F
movlw 0x23
xorwf FSR,W
btfss STATUS,Z
goto next;no
;------------------------------------------
stop
goto stop
;------------------------------------------
;0.5 sec subroutine
;------------------------------------------
long_delay
;499994 cycles
movlw 0x03
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;2 cycles
goto $+1
;4 cycles (including call)
return
;------------------------------------------
end