-
Readcode in asm
Hi,
I try to learn more about picbasicpro and asm.
I want to read out a byte on location $fff in the program code. The pic I use can do this with
readcode $fff, adrs ;place byte on location $fff into var adrs
I htought to do it like this;
bcf STATUS,RP0
bsf STATUS,RP1
MOVLW 0x0F
MOVWF PMADRH
MOVLW 0xFF
MOVWF PMADR
BSF STATUS, RP0 ; Bank 3
BSF PMCON1, RD
NOP
NOP
BCF STATUS, RP0 ; Bank 2
MOVF PMDATA, W
movwf dmxlowbyte
MOVF PMDATH, W
movwf dmxhighbyte
Does it contain a mistake?
-
That's pretty much just like the datasheet says.
The only thing I would recommend is to reset PBP's banking system, since you've changed the bank manually.
Code:
clrf STATUS
PREV_BANK = 0
-
Just noticed something else.
The dmxlowbyte and dmxhighbyte variables will have to be in BANK2 for it to work.
<br>
-
Thank you!
It was indeed a mistake from me, not to change back to bank0 to write te w into the variables.
Instead of defining the variables in bank 2, I switch back to bank 0:
BCF STATUS,RP0 ;bank2
BSF STATUS,RP1
MOVLW 0x0F
MOVWF PMADRH
MOVLW 0xFF
MOVWF PMADR
BSF STATUS, RP0 ; Bank 3
BSF PMCON1, RD ; EEPROM Read
NOP
NOP
BCF STATUS, RP0 ; Bank 2
MOVF PMDATA, W
BCF STATUS,RP1 ;bank0
movwf dmxlowbyte ; range is [0 255]
BSF STATUS,RP1 ;bank2
MOVF PMDATH, W
BCF STATUS,RP1 ;bank0
movwf dmxhighbyte
clrf STATUS ;ga naar bank0