Why Must EECON2 Be Initialized with 0x55 and 0xAA in PIC18F EEPROM Programming?

  • Thread starter Thread starter Magna Visus
  • Start date Start date
  • Tags Tags
    Microcontroller
Click For Summary
The EECON2 register in PIC18F microcontrollers must be initialized with 0x55 and 0xAA before EEPROM writing to prevent unintended code execution that could corrupt the EEPROM. These specific values are not arbitrary; they are designed into the chip's architecture to ensure proper functionality. The binary representations of 0x55 (01010101) and 0xAA (10101010) are opposites, which may contribute to their selection. EECON2 is a logical register rather than a physical one, emphasizing the importance of these values in programming. Understanding this initialization process is crucial for effective EEPROM programming in PIC18F devices.
Magna Visus
Messages
23
Reaction score
0
Hello all,

Those who usually program microcontrollers in assembly, should be well familiar with the internal EEPROM (Series PIC18F).

In particular there's a register EECON2, that needs to be initialized ALWAYS with 0x55 then 0xAA before writing;
Why is that? What's the main reason behind these proper values?

Thanks.
 
Engineering news on Phys.org
It's to help prevent runaway code execution from overwriting the eeprom.
 
Thanks!

But why use 0x55 and 0xAA why not some other random hex numbers?
 
Because that is how the chip was designed to work. There isn't the answer to a question about life, the universe, and everything here.

Of course it's probably not a coincidence that two values are 01010101 and 10101010 in binary. And EECON2 is not a physical register either. http://ww1.microchip.com/downloads/en/DeviceDoc/31007a.pdf section 7.4
 
That's what I ment, the values were perfectly opposite (I mean NOT(01010101) is 10101010).
Anyways thanks for the answer and link
 
Thread 'I thought it was only Amazon that sold unsafe junk'
I grabbed an under cabinet LED light today at a big box store. Nothing special. 18 inches in length and made to plug several lights together. Here is a pic of the power cord: The drawing on the box led me to believe that it would accept a standard IEC cord which surprised me. But it's a variation of it. I didn't try it, but I would assume you could plug a standard IEC cord into this and have a double male cord AKA suicide cord. And to boot, it's likely going to reverse the hot and...

Similar threads

  • Sticky
  • · Replies 13 ·
Replies
13
Views
7K
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 71 ·
3
Replies
71
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K