PIC 12F675 pointers

Thread Starter

peter_morley

Joined Mar 12, 2011
179
I am trying to implement a system where I basically have a stack of information and I need to pop each byte by incrementing the memory/address position and placing it in the GPIO register. I tried to do this by storing information in the cblock when the program is initialized but I couldn't figure out how to increment the pointer position because each register has a different variable name.

I want my program to look something like this

incf PixelPointer,1
movf PixelPointer,0
movwf GPIO

this doesn't work because all it does is increase the value stored in pixel pointer and sends it to GPIO. I want the PixelPointer to only be used as an address holder that points to memory locations that have bytes of data to be put into GPIO.

Any suggestions?
 

ian123

Joined Aug 24, 2011
73
I am trying to implement a system where I basically have a stack of information and I need to pop each byte by incrementing the memory/address position and placing it in the GPIO register. I tried to do this by storing information in the cblock when the program is initialized but I couldn't figure out how to increment the pointer position because each register has a different variable name.

I want my program to look something like this

incf PixelPointer,1
movf PixelPointer,0
movwf GPIO

this doesn't work because all it does is increase the value stored in pixel pointer and sends it to GPIO. I want the PixelPointer to only be used as an address holder that points to memory locations that have bytes of data to be put into GPIO.

Any suggestions?
you can use indirect addressing FSR
 

Thread Starter

peter_morley

Joined Mar 12, 2011
179
Oh I see, it is a register alright thanks. Here is an example code.

Rich (BB code):
movlw 0x20 ;initialize pointer
movwf FSR ;to RAM
NEXT clrf INDF ;clear INDF register
incf FSR ;inc pointer
btfss FSR,4 ;all done?
goto NEXT ;no clear next
CONTINUE ;yes continue
Do I have to clear the indf register every cycle or can I just clear it first before loop? I need a sequence that only does three instructions.


movlw 0x25 ;initialize pointer
movwf FSR ;to RAM

;start of loop
clrf INDF ;clear INDF register
incf FSR ;inc pointer
movf FSR,0
movwf GPIO
 

ian123

Joined Aug 24, 2011
73
Do I have to clear the indf register every cycle or can I just clear it first before loop? I need a sequence that only does three instructions.


movlw 0x25 ;initialize pointer
movwf FSR ;to RAM

;start of loop
clrf INDF ;clear INDF register
incf FSR ;inc pointer
movf FSR,0
movwf GPIO[/QUOTE]

YOU CAN CLEAR IT BEFORE THE FIRST LOOP
 

Markd77

Joined Sep 7, 2009
2,806
In your CBLOCK put:
Rich (BB code):
pixelpointer:3       ;assigns 3 bytes to pixelpointer
later put:

Rich (BB code):
movlw pixelpointer          ;the address of pixelpointer
   movwf FSR
loop

   movf INDF, W
   movwf GPIO
   incf FSR, F
   goto loop
obviously you have to break out of the loop, etc.

There is no need to clear INDF, INDF is the file that FSR is pointing to.
 

Markd77

Joined Sep 7, 2009
2,806
Say if your cblock was

pixelpointer
x
y

then if you ran through the loop I posted 3 times, x and y would be overwritten.
Maybe I should have replaced the name pixelpointer with pixelarray.
Perhaps I misinterpreted this:
I need a sequence that only does three instructions.
Anyway, you've probably got the general idea now.
 
Top