Page 177 - Programming Microcontrollers in C
P. 177

162    Chapter 4  Small 8-Bit Systems

                       EEPROM_CTL.E1LAT=1; /* set the E1LAT bit */
                       EEPROM_CTL.E1ERA=1; /* set the E1ERA erase bit */
                       EEPROM[x]=0; /* select the address */
                       EEPROM_CTL.E1PGM=1; /* turn on the charge pump*/
                       delay(PROG_TIME); /* wait the appropriate time*/
                       EEPROM_CTL.E1LAT=0; /* reset the E1LAT bit turns
                                     off both E1PGM and E1ERA
                                     bits */
                   }          /* return when done */

                              The above program sequences are compiled and listed below.
                              The function delay is not included or linked into this program.
                          To handle this type of problem, the registers are set up for the func­
                          tion call, and the instruction JSR $**** is executed. A later linking
                          will replace the unknown function address with the correct value. An
                          appropriate delay() function will be written in the timer section.
                          The instructions for this function call are found at addresses 0x80c
                          to 0x80f in the following listing.

                   0020 0030 #pragma memory ROMPAGE0 [48] @ 32;
                   0800 1700 #pragma memory ROMPROG [5888] @ 2048;
                   0050 00B0 #pragma memory RAMPAGE0 [176] @ 80;
                   0100 0100 #pragma memory RAMPROG [256] @ 256;


                       /* pragmas to identify EEPROM control registers */


                   0007 #pragma portrw EEPROM_CTL @ 0x07;
                   0100 #pragma portrw OPTIONS @ 0x100;

                       /* EEPROM programming specific defines */


                   0000 #define E1PGM 0
                   0001 #define E1LAT 1
                   0002 #define E1ERA 2
                   000A #define PROG_TIME 10


                   /* some function prototypes */

                   void delay(long);
   172   173   174   175   176   177   178   179   180   181   182