
EraseFlashPage:
		mov	VDM0CN,#0A0h	;ERASE Flash Page @ dptr.  Enable VDD monitor and high threshold
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
		mov	FLKEY,#0A5h	;Key sequence 1
		mov	FLKEY,#0F1h	;Key sequence 2
      		mov	PSCTL,#3
		mov	VDM0CN,#0A0h	;Enable VDD monitor and high threshold
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
		clr	a
   		movx	@dptr,a  
		mov	A,PSCTL
		anl	a,#11111100b	;PSWE=0, PSEE=0
		mov	PSCTL,a
		ret
;



WriteFlashByte:				;Write the byte in accumulator to flash address in dptr
		push	acc
		mov	RSTSRC,#00h	;Disable VDD monitor as a reset source
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
		mov	VDM0CN,#0A0h	;Enable VDD monitor and high threshold

WFBc:		mov	r7,#0		;Wait for VDD monitor to stabilize
		djnz	r7,$
   		mov	a,VDM0CN
   		jnb	acc.6,WFBc	;Wait for the VDD voltage to be high enough
		mov	RSTSRC,#02h	;Enable VDD Monitor as a reset source
		mov	FLKEY,#0A5h	;Key sequence 1
		mov	FLKEY,#0F1h	;Key sequence 2
      		mov	PSCTL,#1
		mov	VDM0CN,#0A0h	;Enable VDD monitor and high threshold
		mov	RSTSRC,#02h     ;Enable VDD Monitor as a reset source
      		pop	acc
		movx	@dptr,a
		mov	PSCTL,#0
		inc	dptr
		ret

