But the problem is with the  compiler if we compile the above code with sdcc 2.6.0 it will work but with sdcc 2.6.3 it will not work.

On 1/25/07, Ernst Bachmann <e.bachmann@xebec.de> wrote:
On Thursday 25 January 2007 08:50, george john wrote:
> >     EECON2 = 0x55;                          // Write "password" to EECON2
> >     EECON2 = 0xAA;
> >     WR     = 1;                             // Initiate a write cycle
> >

Well, the PIC Datasheet claims that an exact timed sequence is neccessary to
write the internal eeprom:

[quote the datasheet:]
The write will not initiate if the above sequence is not
exactly followed (write 55h to EECON2, write AAh to
EECON2, then set WR bit) for each byte. We strongly
recommend that interrupts be disabled during this
code segment. A cycle count is executed during the
required sequence. Any number that is not equal to the
required cycles to execute the required sequence will
prevent the data from being written into the EEPROM.
Additionally, the WREN bit in EECON1 must be set to
enable write. This mechanism prevents accidental
writes to data EEPROM due to errant (unexpected)
code execution (i.e., lost programs). The user should
keep the WREN bit clear at all times, except when
updating EEPROM. The WREN bit is not cleared
by hardware.

Depending on the compiler optimization, redundand banksels etc, your EECON2
writes won't be translated into the exact reqired ASM sequence.

Please check the intermediate ASM code generated by SDCC if that is the case.

The only solution working regardless of compiler version and settings would be
to implement it in inline ASM, like

[quote datasheet:]
BSF   STATUS,RP0  ;Bank 1
BSF   EECON1,WREN ;Enable write
MOVLW 55h         ;Unlock write
MOVLW AAh         ;
BSF   EECON1,WR   ;Start the write


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
Sdcc-user mailing list