Hi, I try use this subroutine to write to data EEPROM. In my main routine, I use this code: FCALL EEPROM_init The function EEPROM_init didn't work as my LCD always show the message indicate that failure in writing to EEPROM. I am using F877 chip, and W0~W7 stay at 0x70, what should I call this area of RAM? A 'shared bank RAM' ? Subrutine listing: EEPROM_init ;*************************************************************************** ****** ; Initialize EEPROM from 0x00 ~ 0xFF to value 0x00 ; ; BF ;*************************************************************************** ****** clrf W7 ; 256 bytes of Data EEPROM to be ; initialize. Address to ; access EEPROM. NextAddress movf W7, w movwf W0 ; Address. movlw 0xFF ; Data. call EEPROM_write movwf W6 ; For checking write result. movf W6, f skpz goto WriteNG ; NG incf W7, f ; OK, increase address. skpz ; Are ROM finish? goto NextAddress ; No retlw 0x00 ; Yes WriteNG FCALL LCD_clear FCALL LCD_home DispMsg EEPROM_WriteNG movlw 0xFF FCALL X_DELAY500 FCALL LCD_clear retlw 0xFF EEPROM_write ;*************************************************************************** * ; Input: Address to be write in W0 ; Data to be write in W ; ; Output: If write-verify OK, w = 0 ; NG W = 0xFF ;*************************************************************************** ** BANK3 btfsc EECON1, WR ; Make sure no writing goto $-1 ; operation in progress. BANK2 movwf EEDATA ; Data to be write. ?? movf W0, w ; movwf EEADR ; Address to be written. BANK3 bcf EECON1, EEPGD ; Point to data memory. bsf EECON1, WREN ; Enable WRITE. bcf INTCON, GIE ; Disable ISR. btfsc INTCON, GIE ; Confirm? goto $-2 movlw 0x55 ; 0x55 must be written to EECON2 movwf EECON2 ; to start write sequence movlw 0xAA ; Next, write 0xAA to EECON2 movwf EECON2 bsf EECON1, WR ; Set WR bit begin write bcf EECON1, WREN ; Disable WRITE. EEPROM_verify bsf EECON1, RD btfsc EECON1, RD goto $-1 BANK2 ; Is the data in W0 same as EEDATA? movf W0, w subwf EEDATA, w BANK0 bsf INTCON, GIE ; Enable interrupt. btfss STATUS, Z ; Is 0? retlw 0xFF ; No, return 0xFF retlw 0x00 ; Yes, return 0x00 I have no clue for the result I get here. I have check through the contents of EEPROM and there are not updated to 0xFF. May someone help me on this? Thanks & regards. WH Tan -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads