1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| #include "p30fxxxx.h"
#include "DataEEPROM.h"
_FOSC(CSW_FSCM_OFF & XT_PLL8); /* Set up for XTxPLL8 mode since */
/* we will be tuning the FRC in this example */
_FWDT(WDT_OFF); /* Turn off the Watch-Dog Timer. */
_FBORPOR(MCLR_EN & PWRT_OFF); /* Enable MCLR reset pin and turn off the power-up timers. */
_FGS(CODE_PROT_OFF); /* Disable Code Protection */
/*Declare constants/coefficients/calibration data to be stored in DataEEPROM*/
int _EEDATA(32) fooArrayInDataEE[] = {0,1,2,3,4,5,6,7,8,9,0xA,0xB,0xC,0xD,0xE,0xF};
/*Declare variables to be stored in RAM*/
int fooArray1inRAM[] = {0xAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEE, 0xFFFF, 0xABCD, 0xBCDE,
0xCDEF, 0xDEFA, 0x0000, 0x1111, 0x2222, 0x3333, 0x4444, 0x5555};
int fooArray2inRAM[16];
int main(void);
void _ISR _DefaultInterrupt(void);
int gPage = 0x0000, gOffset = 0x0000, gSize = 16;
int main(void)
{
while(1) {
WriteEE(&fooArray1inRAM, gPage, gOffset, gSize);
gPage = 0x0000;
gOffset = 0x0000;
gSize = 16;
ReadEE(gPage, gOffset, &fooArray2inRAM, gSize);
}
}
void __attribute__((interrupt, no_auto_psv)) _DefaultInterrupt(void)
{
while(1) ClrWdt()
}
/*
* WriteEErow prototype:
* Parameters Definition:
* Page: is the 8 most significant bits of the destination address in EEPROM
* Offset: is 16 least significant bits of the destination address in EEPROM
* DataIn: is the 16-bit address of the source RAM location or array
* Size: is the number of words to read from EEPROM and is a value of 1 or 16
* Return Value:
* Function returns ERROREE (or -1) if Size is invalid
extern int WriteEE(int* DataIn, int Page, int Offset, int Size);
* ReadEErow prototype:
* Parameters Definition:
* Page: is the 8 most significant bits of the source address in EEPROM
* Offset: is 16 least significant bits of the source address in EEPROM
* DataOut: is the 16-bit address of the destination RAM location or array
* Size: is the number of words to read from EEPROM and is a value of 1 or 16
* Return Value:
* Function returns ERROREE (or -1) if Size is invalid
extern int ReadEE(int Page, int Offset, int* DataOut, int Size);
*/ |