Re: pic16f883 eeprom紀錄

作者 Ryang 於 2018年06月11日 09:38:19
查了一下 Hi-Tech PICC 的 Internal EEPROM 的用法,如下:
(HI-TECH C® for PIC10/12/16 User’s Guide)



For those PIC10/12/16 devices that support external programming of their EEPROM
data area
, the __EEPROM_DATA() macro can be used to place the initial EEPROM
data values into the HEX file ready
for programming. The macro is used as follows.
#include <htc.h>
__EEPROM_DATA(0, 1, 2, 3, 4, 5, 6, 7);

The library functions eeprom_read() and eeprom_write(), can be called to read
from
, and write to, the EEPROM during program execution. For example, to write a
byte
-size value to an address in EEPROM and retrieve it using these functions would
be
:
#include <htc.h>
void eetest(void) {
unsigned char value = 1;
unsigned char address = 0;
// write value to EEPROM address
eeprom_write(address, value);
// read from EEPROM at address
value = eeprom_read(address);
}


Be aware that if a program contains multiple instances of either macro, any code space
saving will be negated
as the full content of the macro is now duplicated in code space.
In the case of EEPROM_READ(), there is another very important detail to note. Unlike
eeprom_read
(), this macro does not wait for any concurrent EEPROM writes to complete
before proceeding to select
and read EEPROM. Had the previous example used
the EEPROM_READ
() macro in place of eeprom_read() the operation would have
failed
. 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:
#include <htc.h>
void eetest(void){
unsigned char value = 1;
unsigned char address = 0;
// Initiate writing value to address
EEPROM_WRITE(address,value);
// wait for end-of-write before EEPROM_READ
while(WR)
continue;
// read from EEPROM at address
value = EEPROM_READ(address);
}


附加檔案:



jpg  擷取.JPG (120.31 KB)
16_5b1dd2b184f50.jpg 901X675 px

來自: http://www.microchip.com.tw/newbb/viewtopic.php?forum=1&topic_id=22316&post_id=78244