The first part of this probably isn't working like you might expect.
Code:
movlw _bOutDataPos ; gets the "address" of bOutDataPos into W
addwf _bOutData,w ; adds the address + the "value" in bOutData
movwf FSR ; loads FSR with the wrong address
You want to add the base address of the array, which will never change, to the
offset value in bOutDataPos to get the address for each array element;
Code:
movf _bOutDataPos,W ; get the value of your index pointer in bOutDataPos
addlw _bOutData ; add the index to the base address of your array
movwf FSR ; load FSR with base address + offset
This will probably make it easier to follow;
Code:
Array VAR BYTE[8]
Index VAR BYTE
Address VAR BYTE
Action CON 10
ControlChar CON 20
CLEAR
Address = 15 ' address
Index = 0 ' starting Array Index position
Main:
Array[Index]=ControlChar
Index=Index+1
Array[Index]=0
Index=Index+1
Array[Index]=Address
Index=Index+1
Array[Index]=Action
Index=Index+1
GOTO Main
The code after Main would be something like this, which maintains your Index pointer.
Code:
asm
movf _Index, W ;get "offset" value from Index pointer
addlw _Array ;add it to Array[0] base address (result in W)
movwf FSR ;load pointer with base + offset
movlw _ControlChar ;load W with constant value in ControlChar
movwf INDF ;move it to Array[Index]
incf _Index, F ;inc Index pointer
movf _Index, W ;load new Index pointer value
addlw _Array ;add it to Array[0] base address
movwf FSR ;load pointer with base + offset
clrf INDF ;Clear Array[Index]
incf _Index, F ;inc Index pointer
movf _Index, W ;load new Index pointer value
addlw _Array ;add it to Array[0] base address
movwf FSR ;load pointer with base + offset
movf _Address, W ;get Address byte value
movwf INDF ;move it to Array[Index]
incf _Index, F ;inc Index pointer
movf _Index, W ;load new Index pointer value
addlw _Array ;add it to Array[0] base address
movwf FSR ;load pointer with base + offset
movlw _Action ;load W with Constant value in Action
movwf INDF ;move it to Array[Index]
incf _Index, F ;inc Index pointer
endasm
It could be made a bit smaller, and you could use incf FSR to increment the
pointer each time, but you could lose track of which array element you last
wrote to pretty quick.
Bookmarks