Je tohle způsob jakým se řídit? Zatím to takhle funguje.
[code]//==================================
// Include files
#include <p18f8720.h>
//==================================
// Function prototypes
unsigned char ReadEEPROM(unsigned int address);
void WriteEEPROM(unsigned int address, unsigned char data);
//==================================
// Declare EEPROM data and other global variables
// Note that EEPROM is mapped to program memory address 0xF00000
#pragma romdata dataEEPROM=0xF00000
rom unsigned char FirstByte = 0x55;
rom unsigned char SecondByte;
rom unsigned char FirstArray] = {0x00, 0x01, 0x02};
rom unsigned char SecondArray[3];
#pragma udata
unsigned char TestVar;
//==================================
// Main routine
#pragma code
void main(void)
{
// Configure the device to access Data EEPROM memory
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
// Read each of the EEPROM bytes defined in FirstByte and FirstArray]
TestVar = ReadEEPROM((unsigned int)&FirstByte);
TestVar = ReadEEPROM((unsigned int)&FirstArray[0]);
TestVar = ReadEEPROM((unsigned int)&FirstArray[1]);
TestVar = ReadEEPROM((unsigned int)&FirstArray[2]);
// Write to each of the EEPROM locations defined in SecondByte and SecondArray]
WriteEEPROM((unsigned int)&SecondByte, 0xaa);
WriteEEPROM((unsigned int)&SecondArray[0], 0x07);
WriteEEPROM((unsigned int)&SecondArray[1], 0x08);
WriteEEPROM((unsigned int)&SecondArray[2], 0x09);
// Wait forever
while (1);
}
//==================================
// EEPROM read routine
unsigned char ReadEEPROM(unsigned int Address)
{
EEADRH = (unsigned char)(Address>>8); // Load the high byte of the EEPROM address
EEADR = (unsigned char)Address; // Load the low byte of the EEPROM address
EECON1bits.RD = 1; // Do the read
return EEDATA; // Return with the data
}
//==================================
// EEPROM write routine
void WriteEEPROM(unsigned int Address, unsigned char Data)
{
static unsigned char GIE_Status; // Variable to save Global Interrupt Enable bit
EEADRH = (unsigned char)(Address>>8); // Load the high byte of the EEPROM address
EEADR = (unsigned char)Address; // Load the low byte of the EEPROM address
EEDATA = Data; // Load the EEPROM data
EECON1bits.WREN = 1; // Enable EEPROM writes
GIE_Status = INTCONbits.GIE; // Save the Global Interrupt Enable bit
INTCONbits.GIE = 0; // Disable global interrupts
EECON2 = 0x55; // Required sequence to start the write cycle
EECON2 = 0xAA; // Required sequence to start the write cycle
EECON1bits.WR = 1; // Required sequence to start the write cycle
INTCONbits.GIE = GIE_Status; // Restore the Global Interrupt Enable bit
EECON1bits.WREN = 0; // Disable EEPROM writes
while (EECON1bits.WR); // Wait for the write cycle to complete
}
[/code]