Table Array Address To FSR ASM Macro (for small pics) - Joe's Cat Website


This macro proves itself useful for tiny projects with smaller PIC chips (such as the pic10, pic12, pic16 series) that need to work with large strings or arrays of up to 64 bytes in length.

The original macro this is based on can be found in AN656 (ISPPRGM.ASM 3-31-1997) and this version here is simplified so that Wreg works as {00h..3fh} instead of {10h..4fh}.


GET THE FILE

You can download addFSRM Macro, or you can copy and paste the code shown below into your ASM code editor.

;***************************************************************
;addresstofsr macro (AN656 In-Circuit Serial Programming (ICSP))
;Convert continuous address{00h-3Fh} to an FSR address to access
;4 banks of file registers in PIC16CXX or similar chips.
;	Array Address	FSR Value
;	00h-0Fh		10h-1Fh
;	10h-1Fh		30h-3Fh
;	20h-2Fh		50h-5Fh
;	30h-3Fh		70h-7Fh
;enter: w=address{00..3f}
;exit : FSR=address{10..1f,30..3f,50..5f,70..7f}
;
addFSRM macro
	movwf	FSR		;start with address[00..3f]
	btfsc	FSR,5		;shift bits 5,6 and 4,5
	bsf	FSR,6
	bcf	FSR,5
	btfsc	FSR,4
	bsf	FSR,5
	bsf	FSR,4		;addr{10-1f,30-3f,50-5f,70-7f}
	endm

To use the code above, you need to enter the macro with Wreg equal to an table array location {00..3fh}. when done, FSR will point to the correct file register location.

Another thing to note is that you may find yourself using this macro several times in your code, so if you want to make this macro more compact to give yourself more room for "other" code, then just turn it into a call instead. Both methods are shown below.

;Call example if you call addresstofsr many times in your code
addFSRC	addFSRM			;convert array[w] into index[FSR]
	retlw	0

;----------------------------------------------------------------
;main program code area showing how you can call addresstofsr

	movlw	.10		;get value w from array[10]
	call	addFSRC
	movfw	INDF

	movlw	.20		;store 5 into array[20]
	call	addFSRC
	movfw	INDF
	movlw	.5
	movwf	INDF

	movlw	.30		;example using macro, array[30]=0
	addFSRM
	clrf	INDF

If you find this macro useful, I will appreciate a little credit for providing it here for your use/project (for example, in your source code comments, or even a web link back to this web page is great if you have a project that uses it that you want to show/demonstrate). Thanks.

Other PIC Related Pages On This Web Site
Home Page A/B Long Term Timer ASCII To MorseCode Clear RAM Macro Cylon Eye
Delay Macro Random Number Generator (RNG) 7.96Hz Sinewave Generator Software RS232 PicDis Disassembler


Copyright© 2000..2017 Joe's Cat
counter