PIC 12F675 pointers

Discussion in 'Embedded Systems and Microcontrollers' started by peter_morley, Aug 30, 2011.

  1. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    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?
     
  2. ian123

    Member

    Aug 24, 2011
    73
    2
    you can use indirect addressing FSR
     
  3. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    I don't see an FSR instruction in my PIC 12F675 instruction set.
     
  4. peter_morley

    Thread Starter Member

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

    Code ( (Unknown Language)):
    1. movlw 0x20 ;initialize pointer
    2. movwf FSR ;to RAM
    3. NEXT clrf INDF ;clear INDF register
    4. incf FSR ;inc pointer
    5. btfss FSR,4 ;all done?
    6. goto NEXT ;no clear next
    7. 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
     
  5. ian123

    Member

    Aug 24, 2011
    73
    2
    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
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    In your CBLOCK put:
    Code ( (Unknown Language)):
    1. pixelpointer:3       ;assigns 3 bytes to pixelpointer
    later put:

    Code ( (Unknown Language)):
    1. movlw pixelpointer          ;the address of pixelpointer
    2.    movwf FSR
    3. loop
    4.  
    5.    movf INDF, W
    6.    movwf GPIO
    7.    incf FSR, F
    8.    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.
     
  7. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    why assign 3 bytes to pixel pointer?
     
  8. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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:
    Anyway, you've probably got the general idea now.
     
Loading...