Page 174 - Programming Microcontrollers in C
P. 174
Microcontroller Memory 159
Programming EEPROM
EEPROM is read like any other memory in the microcontroller.
Two different types of EEPROM can be found on a microcontroller:
program memory and data storage memory. Program memory usu
ally cannot be programmed without the aid of an externally applied
programming voltage. Data storage memory can be programmed from
within the program and requires no externally applied programming
voltage. In the case of the M68HC805B6, there are 5888 bytes of
program EEPROM and 255 bytes of data storage EEPROM. Other
than the reduced size of the data storage memory, this memory is no
different from the program memory. It is possible to write code to
the data storage EEPROM and execute this code.
One additional byte of data storage EEPROM exists and is called
the OPTION register. This register content is saved in EEPROM which
is read into a latched register during the initialization of the
microcontroller. The address of this register is 0x100. The bits in this
register control the security option of the part and control a block
protect region in the data storage EEPROM that will prevent acci
dental writing of data into the protected memory area. A description
of these bits follows:
Options Reg Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
0x0100 EE1P SEC
SEC Bit 0 Security Bit. When the SEC bit is programmed to
zero, the contents of the EPROM are secured by
preventing access to the test mode. The only way
to erase the SEC bit to a one state is to enter the
self-check mode. In this event, the data on
EEPROM will all be erased. When the SEC bit is
changed, its new value will have no effect until
after the next chip reset.
EE1P Bit 1 EEPROM Block Protect Bit. The EEPROM is in
two parts: 0x101 to 0x11f is part 1 and 0x120 to
0x1ff is part 2. The EE1P bit allows part 2 to be
protected. If this bit is in the erased state, (1), part
2 of the EEPROM will be protected. This memory
area can be read as usual, but any attempt to write
to this area will fail. The protection remains in