Clear RAM ASM Macro (for small pics) - Joe's Cat Website


This Clear RAM macro is a useful little routine to erase RAM to zero in a Microchip PIC.

It can be inserted at the start, to run once at the chip reset, or it could be put into a call routine to be called several times when needed (for erasing tables or strings).

The way this macro works is by using the FSR index register to go through all the file registers from the end back towards the start, and when finished, the FSR Index points to start.

This Clear RAM macro works on all PIC chips including the smaller pic10, pic12, pic16 versions. As an example, to clear RAM for a PIC16F54, you would use "ClearRamM 08h,1fh" to erase RAM File Registers from 08h to 1fh.


GET THE FILE

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

;***************************************************************
;Clear Ram Macro
;enter:	startR,endR is range of ram to clear
;exit:	memory area reset to zero. FSR points to startR
ClrRamM macro	startR,endR
	local	ClrLp
	movlw	endR+1		;begin at end, and stop at start
	movwf	FSR
	movwf	startR		;loop until startR=0
ClrLp	decf	FSR,f		;move to next reg
	clrf	INDF		;clear buffer register
	movfw	startR		;loop until startR=0
	skpz
	goto	ClrLp
	endm

If you find this macro useful for yourself, or a project, 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 Cylon Eye Delay Macro
Random Number Generator (RNG) 7.96Hz Sinewave Generator Software RS232 Table Array FSR Macro PicDis Disassembler


Copyright© 2000..2017 Joe's Cat
counter