INDF, W command

Status
Not open for further replies.

cyprio7

New Member
Hello guys, just a quick question.


I am going through nigels first manchester encoding tutorial line by line, trying to understand what is going on but i have become stuck on what i think is something trivial.

In the "send" subroutine it has a line of code as follows...

movf INDF,W


I assume this means, "move contents of file-register which FSR is pointing to, to the accumilator, W". Obviously, FSR is accessed via INDF. To check this i wrote a very short piece of code which i have attatched.

From this command above, (in my code), it should result in the number 7, being moved into W, however, in the watch window, it says 0xA2 instead.

Does this function differently to what i am thinking or have i written the code wrong?

Thanks
 

Attachments

  • confused.txt
    645 bytes · Views: 191
I think your understanding is correct, but your code is somewhere else.

You access the contents of the memory location pointed to by the value in the FSR register by reading/writing INDF

Try this.

Code:
        #include "p16f628.inc" 
        __CONFIG       _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT   & _MCLRE_ON & _LVP_OFF
 
        errorlevel -302 ; suppress banksel warning messages
 
        cblock 0x20
         userdata       ; userdata is GPR at address 0x20
        endc
 
        org     0x000   ; Reset vector
_start  movlw   .1        ; load 1 into W
        movwf   userdata  ; write W into userdata 
        movlw   0x20    ; load W with 0x20
        movwf   FSR     ; set FSR to value in W so it
                        ; points to address 0x20 (address of userdata )
 
        movfw   INDF    ; read back contents of GPR pointed to by FSR
        addlw   .1      ; add 1 to it
        movwf   INDF    ; write it back
                        ; so now value in userdata is 2
 
_stop   goto    _stop
 
        end
 
Last edited:
thanks for the reply... In nigels tutorial he uses...

movf INDF,W ... is this wrong though?



movlw mtx_buffer ;w = 22 << this works(when mtx_buffer is in GPR 0x22) I have checked it, its ok

Also how comes you put a dot before the number? What does that do?
 
movf INDF,W ... is this wrong though?

movf INDF,w is the same as movfw INDF, just different mnemonics - I prefer the latter.

The value placed in the FSR register points to a real data memory address. You access the contents of the memory address the FSR is pointing to by reading (or writing) to the INDF register.

This accesses address 0x20 directly
Code:
movf  0x20, W   ; loads the value in memory address 0x20 into W

this does the same but indirectly
Code:
movlw 0x20    ; loads the value 0x20 in to W
movwf FSR     ; write the value in W into the FSR register
movf INDF,W  ; read the contents of the register pointed to by FSR into W


movlw mtx_buffer ;w = 22 << this works(when mtx_buffer is in GPR 0x22) I have checked it, its ok

The code you posted didn't define mtx_buffer, also you started by using clrf INDF before you actually put a value in FSR so you would clear whatever random location the FSR was pointing to.

The code you posted also won't assemble so I decided to ignore your code completely and just give you an example that worked.

Also how comes you put a dot before the number? What does that do?

Tells the assembler the number is in decimal.

In MPLAB under 'Help' - Topics, check out the MPASM Assembler section
 
Last edited:
Compiling your code in and IDE would have gave you the error that mtx_buffer was not defined. From where are you working with the .asm?
 
Last edited:
One thing that hasn't been mentioned is the 9th bit of the indirect address which is contained in STATUS,IRP. It isn't normally a problem but if it inadvertently gets set then you will be accessing banks 2&3 instead of 0&1.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…