EEpromWrite; write 'Tmp3' number of GPR bytes into EEPROM address starting at 'wreg' value. FSR preloaded to GPR start addr.
;FSR set for bank0,1, ; bank 2,3 GPR requires 'bsf STATUS,IRP' for FSR to work on those GPR. Preset this b4 calling this code.
banksel EEADR
movwf EEADR ; store dest. eprom address
incf Tmp3,f ; compensate for decfsz. Tmp3 is a multibank register
EEWloop decfsz Tmp3,f ; skip next if 0, else
goto Dowrite
clrf STATUS; bank0, irp clr etc.
return
Dowrite ; perform write of a gpr byte to eeprom.
movf INDF,w;get gpr data
Dwrite movwf EEDAT ; data value to write
banksel EECON1
bcf EECON1,EEPGD; set to ee data mem
bsf EECON1,WREN; enable ee write
bcf INTCON,GIE; halt ISRs
btfsc INTCON,GIE
goto $-2 ; verify isr halts
movlw 0x55 ; required
movwf EECON2; required
movlw 0xAA; required
movwf EECON2 ; write AA
bsf EECON1,WR; begin write
; now test if write is complete
btfsc EECON1,WR ;WAIT FOR
goto $-1 ;WRITE TO FINISH
bsf INTCON,GIE; enable isrs
bcf EECON1,WREN; disable write
banksel EEADR
incf FSR,f ; pt to next GPR byte, bank 0/1
incfsz EEADR,f ; next EEprom byte, skip if overflow of the eeprom bank.
goto EEWloop
clrf STATUS; bank0, irp clr etc.
return