	Title "PIC18F452 counting program"
	list p=18F452, f=inhx32
	#include <p18f452.inc>

ADR_EEP	EQU		00H

		ORG		00H
		GOTO 	START

		ORG		1CH
START	LFSR 	FSR0,20H
		MOVLW	1
NEXT1	MOVWF	POSTINC0
		INCF	WREG
		BTFSS	FSR0L,4
		GOTO	NEXT1


		LFSR 	FSR0,20H
		MOVLW	40H
		MOVWF	ADR_EEP 
	
NEXT2	MOVF	ADR_EEP,W
		MOVWF	EEADR	
		MOVF	POSTINC0,W
		MOVWF	EEDATA
		
		BCF		EECON1, EEPGD 		; Point to DATA memory
		BCF		EECON1, CFGS 		; Access program FLASH or Data EEPROM memory
		BSF		EECON1, WREN 		; Enable writes
		BCF		INTCON, GIE 		; Disable interrupts
Required
		MOVLW	55H 			;
Sequence
		MOVWF	EECON2 			; Write 55h
		MOVLW	0xAA			;
		MOVWF	EECON2 			; Write AAh
		BSF		EECON1, WR 		; Set WR bit to begin write
		INCF	ADR_EEP,F
LOOP	BTFSS	PIR2,EEIF
		GOTO	LOOP
		BCF		PIR2,EEIF
		BTFSS	FSR0L,4
		GOTO	NEXT2
		BSF		INTCON, GIE		; Enable Interrupts
HERE	BRA		HERE
		END