Page 175 - Programming Microcontrollers in C
P. 175

160    Chapter 4  Small 8-Bit Systems

                                            effect after this bit is erased until after the next
                                            chip reset.
                              Control of the EEPROM programming is through the EEPROMCTL
                          register found at address 0x07. The bits in this register are as follows:


                           EEPCTL/CLK   Bit 7   Bit 6   Bit 5   Bit 4   Bit 3   Bit 2   Bit 1   Bit 0
                               0x07       0     0      0     0    ECLK  E1ERA E1LAT  E1PGM

                          E1PGM  Bit 0  EEPROM Program Bit. This bit turns the internal
                                            Vpp charge pump on and off. When this bit is 0,
                                            the charge pump is turned off, and when it is at 1,
                                            the charge pump is turned on. The charge pump
                                            voltage can be measured on the pin Vpp1. This bit
                                            cannot be set until after the program data are latched
                                            in place by asserting the E1LAT bit. Resetting the
                                            E1LAT bit will also reset the E1PGM bit.
                          E1LAT  Bit 1  EEPROM Data/Address Latch. When this bit is re­
                                            set to zero, both the E1PGM bit and the E1ERA bit
                                            are reset to zero. When the E1LAT bit is reset, data
                                            can be read from the EEPROM. The first data write
                                            to the EEPROM array after this bit is set is latched
                                            until the E1LAT bit is reset. Data can be latched
                                            only when the E1PGM bit is reset to zero. This op­
                                            eration allows programming of the EEPROM.
                                            E1LAT is automatically reset when the chip is reset
                                            or when the STOP instruction is executed.
                          E1ERA  Bit 2  EEPROM Erase Bit. If the bit E1ERA is reset to
                                            zero when E1LAT and E1PGM are set to one, data
                                            are programmed into the EEPROM. Otherwise,
                                            if E1ERA is set to one and E1LAT and E1PGM
                                            are set to one, the specified address in the
                                            EEPROM will be erased. E1ERA cannot be set
                                            before E1LAT, and resetting E1LAT to zero will
                                            cause E1ERA to be reset.
                              Let us now examine a possible sequence of code that can be used
                          to program and erase locations in EEPROM. First, several macro
                          definitions should be used to define the various parameters used.
   170   171   172   173   174   175   176   177   178   179   180