To do an alarm function of East, the request can be remote control to change the content. The watchdog is used because of the high stability requirements of the system.
However, the watchdog reset will cause all registers to reset and revert to the default state. Remote control to change the content has also been reset, so only with the use of EEPROM to store alarm signs.
I'm using the Mplab X IDE +xc8 compiler, XC8 is a bit different from the PICC in syntax.
The EEPROM operation has two methods, defining a named variable in the storage space, or using a block accessor to read or write to the EEPROM.
1. EEPROM Object
The __eeprom qualifier can be used to indicate that the variable should be positioned in the EEPROM.
Example __eeprom int serialnos[4]
Put the int type array serialnos[] into the EEPROM, note that the int length in XC8 is 16bit, and in other MCUs, such as the Pc,int value size is related to the system.
2. EEPROM initialization
For devices that support external programming of their EEPROM data regions, you can use the __eeprom_data () macro to place the initial values into a hex file that can be programmed.
Example:#include <xc.h>
__eeprom_data (0,1,2,3,4,5,6,7);
The macro has 8 parameters, representing 8 data values, each with a value of 1BYTE. Unused values are specified as zero, or the compiler will give an error.
Each time it is used, the __eeprom_data will be written from the EEPROM address zero and automatically incremented by 8.
If you want to use more data, you can define the required number of EEPROM data by calling the macro multiple times. It is a good idea to put the macro outside of all function definitions.
The macro cannot be written to the EEPROM at run time, but is loaded into the EEPROM when programmed to write.
Use __eepromsize to indicate the number of EEPROM bytes available.
3. Access functions
You can call library functions to read and write to the EEPROM.
void Eeprom_write (unsigned char addr, unsigned char value);
unsigned char eeprom_read (unsigned char addr);
When these functions are used, they are automatically tested and wait for all concurrent write operations to the EEPROM to complete before performing the required operations.
4. Access macros
The macro version is different from the access function, and the macro usage is as follows.
Eeprom_read (Address)
Eeprom_write (address, value)
The Eeprom_read macro returns the bytes read.
In low-and mid-range devices, such as the PIC8 PIC16 PIC18 series, the macro function read will not wait for the EEPROM write operation to complete, use should query flag.
When using macro version access, it is best to close the interrupt.
Example: xc.h
while (WR)
Continue
Value=eeprom_read (address);
PIC XC8 EEPROM operation