/*********************************************************************
*
* Functions for reading and writing to EEPROM.
*
*********************************************************************
* FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/Include/EEAccess.c $
* Last changed: $LastChangedDate: 2006-11-20 21:31:03 +0100 (Mon, 20 Nov 2006) $
* By: $LastChangedBy: johboh $
* Revision: $Revision: 139 $
********************************************************************/
#include <p18cxxx.h>
#include <EEaccess.h>
/*
* Function: EERead
*
* Input: WORD address to read from.
* Output: Byte read.
* Pre-conditions: none
* Affects: none.
* Depends: none.
*/
BYTE EERead(WORD addr)
{
EEADRH=(BYTE)(addr>>8);
EEADR=(BYTE)(addr & 0xFF);
EECON1bits.EEPGD=0;
EECON1bits.CFGS=0;
EECON1bits.RD=1;
return EEDATA;
}
/*
* Function: EEWrite
*
* Input: WORD address to write to and BYTE data to write.
* Output: none.
* Pre-conditions: none
* Affects: none.
* Depends: none.
*/
void EEWrite(WORD addr,BYTE data)
{
PIR2bits.EEIF=0;
EEADRH=(BYTE)(addr>>8);
EEADR=(BYTE)(addr & 0xFF);
EEDATA=data;
EECON1bits.EEPGD=0;
EECON1bits.CFGS=0;
EECON1bits.WREN=1;
INTCONbits.GIE=0;
EECON2=0x55;
EECON2=0xAA;
EECON1bits.WR=1;
INTCONbits.GIE=1;
while(!PIR2bits.EEIF);
EECON1bits.WREN=0;
}