On Wed, 13 Aug 1997 10:22:19 PDT Shane Buckham writes: >I > >Here is a portion of the code in two parts macro and eewrite >subroutine. > > >{macro write_ee} > >WRITE_EE MACRO ADR, DAT > > movlw ADR > movwf EEADR > movf DAT,W > movwf EEDATA > call Write_EEProm > > ENDM > >{Subroutine Write_EEprom} > >Write_EEProm: PAGE1 ;Macro, move to page 1 > bcf EECON1-0x80,WRERR > bcf EECON1-0x80,EEIF > movlw 0x55 > movwf EECON2-0x80 > movlw 0xAA > movwf EECON2-0x80 > bsf EECON1-0x80,WR > >Wait_EEProm: btfss EECON1-0x80,EEIF > goto Wait_EEProm > bcf EECON1-0x80,WREN > PAGE0 ;Macro, back to page 0 >return > >I would appreciate any suggestions you could offer. > You need to have WREN set before attempting to set WR (and before the 55, aa stuff) in the write routine. Hardware doesn't set or clear WREN except to clear it on a reset. I have had good results ignoring the WRERR and EEIF bits and polling the WR bit. It will stick at 1 until the write completes. While waiting, be sure to clear the WDT if it is set up for a short time. The WRERR bit is only of relevance if you want to be able to recover from a reset while a write was in progress. If you have an interrupt that reads the EEPROM, it must be disabled while a write is in progress. Once you get it working, you can save a code word everytime you reuse WRITE_EE by moving the movwf EEDATA into the Write_EEProm subroutine.