I have discovered the problem with my code. I should be checking the state of the WR bit and not the EEIF. The manual does imply the user should set and Int or poll the EEIF bit and doesn't make complete sense to me but it now works. Justin ----- Original Message ----- From: "Justin Richards" To: Sent: Saturday, January 27, 2001 12:23 AM Subject: [PIC]: EEPROM problem with writes Greetings All, I have tried to implement EEPROM writes on 16F84 at 3.2768 Mhz using Charles Manning's Assembler, KIT 81 and PICALL. WDT disabled, Power up timer enabled. GIE and TMR0 enabled at initialization Once the subroutine below has been called all subsequent reads to any EEPROM location returns the '9' (used as the write test data). However, if it is put thru a power down/up cycle then subsequent reads return values as expected. ie the '9' is in the right place and everything else as it should be. If I rem out the 6 lines as shown '*', all subsequent reads are normal. Anyone any idea where I am going wrong. Justin RamToEeprom ;************************************************* movlw EEFaceTens ;Address where data written movwf EEADR,f ;move it to the address reg movlw 9 ;just some test data movwf EEData,f ;move it the Data reg ShiftNextRamByte ;Sub will later move 5 bytes bcf GIE ;Disable all interrupts btfsc GIE ;was it successful goto ShiftNextRamByte ;no, try and set it again bsf RP0 ;switch to bank 1 bsf WREN ;Enable EEprom writes bcf EEIF ;clear the write success flag * movlw 55h,w ;55 cause manual says so * movwf EECON2,f ;write it to the control reg * movlw 0AAh,w ;AA cause manual says so * movwf EECON2,f ;write it to the control reg bsf WR ;this initiates the write bsf GIE ;re-enable interrupts nop ;just in case it needs some time *WaitForWrite btfsc EEIF ;has the write finished * goto WaitForWrite ;no, then wait some more bcf EEIF ;clear the flag bcf WREN ;clear WREN when not writing bcf RP0 ;switch back to bank 0 return ;RamToEeprom End Sub -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads