Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 177
5.5.5.2
EEPROM ACCESS FUNCTIONS
The library functions eeprom_read() and eeprom_write(), can be called to read 
from, and write to, the EEPROM during program execution. On PIC18 devices, these 
functions are derived from the peripheral library. The prototypes for these functions are 
as below.
#include <xc.h>
unsigned char eeprom_read(unsigned char address);
void eeprom_write(unsigned char address, unsigned char value);
These functions test and wait for any concurrent writes to EEPROM to conclude before 
performing the required operation. The eeprom_write() function will initiate the pro-
cess of writing to EEPROM and this process will not have completed by the time that 
eeprom_write()
 returns. The new data written to EEPROM will become valid at a 
later time. See your device data sheet for exact information about EEPROM on your 
target device.
It may also be convenient to use the preprocessor symbol, _EEPROMSIZE, in conjunc-
tion with some of these access methods. This symbol defines the number of EEPROM 
bytes available for the selected chip.
5.5.5.3
EEPROM ACCESS MACROS
Macro version of the EEPROM functions are also provided. The PIC18 version of these 
macros purely call the function equivalents. Those for other 8-bit PIC devices perform 
similar operations to their function counterparts, with the exception of some timing 
issues described below. Use the macro forms of these routines for faster execution and 
to save a level of stack, but note that their repeated use will increase code size.
The usage of these macros for all devices is as follows.
EEPROM_READ(address)
EEPROM_WRITE(addressvalue)
The EEPROM_READ macro returns the byte read.
In the case of the baseline and mid-range macro EEPROM_READ(), there is another 
very important difference from the function version to note. Unlike eeprom_read(), 
this macro does not wait for any concurrent EEPROM writes to complete before pro-
ceeding to select and read EEPROM. If it cannot be guaranteed that all writes to 
EEPROM have completed at the time of calling EEPROM_READ(), the appropriate flag 
should be polled prior to executing EEPROM_READ().
For example:
xc.h    // wait for end-of-write before EEPROM_READ
    while(WR)
        continue;    // read from EEPROM at address
    value = EEPROM_READ(address);