You may try this comparing to your program ;void weprom(char adr, char value) ;{ EEADR=adr; EEDATA=value; EEPGD = 0; WREN = 1; GIE=0; EECON2 = 0x55; EECON2=0xAA; WR=1; GIE=1; weprom: BCF 0x03,RP0 BCF 0x03,RP1 MOVWF value ;save parameters only... not important for you MOVF adr_2,W BSF 0x03,RP1 MOVWF EEADR BCF 0x03,RP1 MOVF value,W BSF 0x03,RP1 MOVWF EEDATA BSF 0x03,RP0 BCF 0x18C,EEPGD BSF 0x18C,WREN BCF 0x0B,GIE MOVLW .85 MOVWF EECON2 MOVLW .170 MOVWF EECON2 BSF 0x18C,WR BSF 0x0B,GIE ; while (WR); m039 BSF 0x03,RP0 BSF 0x03,RP1 BTFSC 0x18C,WR GOTO m039 BSF 0x03,RP0 ;WREN=0; BSF 0x03,RP1 BCF 0x18C,WREN ;} RETURN ;char leprom (char adr) ;{ EEADR=adr; EEPGD=0; RD=1; return EEDATA; } leprom BCF 0x03,RP0 BCF 0x03,RP1 MOVWF adr :save parameters as above MOVF adr,W BSF 0x03,RP1 MOVWF EEADR BSF 0x03,RP0 BCF 0x18C,EEPGD BSF 0x18C,RD BCF 0x03,RP0 MOVF EEDATA,W RETURN It's written in C and not very optimized. Hope it helps you a little. Igor -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Jai Dhar Sent: 19. ledna 2003 21:24 To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: EEPROM on f877 Hi, I'm having a wierd problem writing/reading to the EEPROM on the f877. I wanted to make two routines to write and read, and this is what I came up with: ;Writes the value in W to the address in 'temp' EEPROMWrite bsf STATUS,RP1 ;Switch to bank 2 movwf EEDATA bcf STATUS,RP1 ;Back to Bank 0 movf temp,w bsf STATUS,RP1 ;And back again to Bank2 movwf EEADR ;Set to Bank 3 bsf STATUS,RP0 ;Enable EEPROM Writing bsf EECON1,WREN movlw 0x55 movwf EECON2 movlw 0xAA movwf EECON2 ;Begin Write bsf EECON1,WR bcf EECON1,WREN ;Switch back to Bank 0 bcf STATUS,RP0 bcf STATUS,RP1 retlw 0x00 ;Reads the value at address W and puts it back in temp EEPROMRead ;Switch to bank 2 bsf STATUS,RP1 ;Move the address in W to EEADR movwf EEADR ;Switch to bank 3 bsf STATUS,RP0 ;Start the reading bsf EECON1, RD ;Back to Bank 2 bcf STATUS,RP0 movf EEDATA,w ;Switch bank to Bank 0 bcf STATUS,RP1 bcf STATUS,RP0 ;Move the contents of W to temp movwf temp retlw 0x00 Now what's wierd is that I called the Write fn twice, two different values, different addresses... and then called read on one of them. I read it fine... I then rewrote the code to read the other address (just one at atime), and I got the same thing?? So I'm not sure which fn. is working incorrectly. Anything seem to be wrong with my code? I know it's probably a bit inefficient, but I just want to get it working first. If you guys do'nt see anything wrong with this, I will look a bit closer at my fn to display the numbers on my LCd, but I'm pretty sure that's not the problem since it works for everything else. Thanx, Jai ---------------------------------------- This mail sent through www.mywaterloo.ca -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.