Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Setting file registers with pointers

Status
Not open for further replies.

Yobortsa

Member
Hi all,

Does anybody have any low level ASM code to send/receive via SPI that will work on a 12F675 and that they are willing to share? That will solve my issue.

Otherwise, I'm writing my own...

I want to write a subroutine that saves 1, 2 .... x bytes into memory that it receives via SPI.

Is there any way on the mid-range MCUs to set a file register pointed to by another file register, for example something like:

movlw 022h ; Move 22h into W
movwf 021h ; Move W into file register 21h
movlw 0e6h ; Move e6h into W
movwf [021h] ; Move W into file register pointed to by 21h
.
.
.
inc 021h,1 ; Increment my pointer
goto writeloop ; Loop through

Obviously I won't look continuously incrementing forever. Just wanted to simplify the code above.

I don't think there is a way to do it, but hopefully somebody has some tricks.

Thanks,

David :)
 

Pommie

Well-Known Member
Most Helpful Member
Look at the FSR register.

Example,
Code:
	movlw	0x22
	movwf	FSR	;point to 0x22
	movlw	0xe6
	movwf	INDF	;0x22=0xe6
	incf	INDF,F	;0x22=0xe7

Mike.
 

Yobortsa

Member
Got it, thanks so much :)

Does the indirect addressing with FSR/INDF work for reading registers as well as writing to registers?

Thanks,

David
 

kpatz

New Member
Got it, thanks so much :)

Does the indirect addressing with FSR/INDF work for reading registers as well as writing to registers?

Thanks,

David
Yes... you use INDF like any other register, only instead of it being a fixed register, it reads or writes to whatever FSR is pointing at.

So... for example, let's copy the contents of 0x21 into 0x22 using indirect addressing...

Code:
    movlw    0x21
    movwf    FSR      ; Sets FSR to 0x21
    movf     INDF,W   ; Reads whatever is in 0x21 into W
    incf     FSR,F    ; Increments FSR (now points to 0x22)
    movwf    INDF     ; Writes W into 0x22
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top