/*
The following C program shows the uses of the EEPROM functions.
Program Description:
This program writes 5 data bytes in EEPROM memory from one user buffer, Temp1.
Then data bytes are read from the same EEPROM memory and stored in another
buffer, Temp2. The written data and data read are compared, by comparing the two
buffers.
*/
/*============================================================*/
/* Program Start */
#include "ST7lib_Config.h" /* File for user to select device as lite0 */
#ifdef _HIWARE_
unsigned char ptr_address @ 0x1000; 
#endif
#ifdef _COSMIC_
@near unsigned char ptr_address @ 0x1000; 
#endif

void main(void);

void main (void)
{
int i;
unsigned char NoofBytes = 5;
unsigned char Temp1[5] = {0x55,0xAA,0x7F,0x18,0x4C};
unsigned char Temp2[5] = {0x00,0x00,0x00,0x00,0x00};
   
/*@far unsigned char * ptr_write;
@far unsigned char * ptr_read;
ptr_read = &ptr_address;
ptr_write = &ptr_address;*/
                             
EEPROM_Init (); /* All EEPROM registers initialised to reset value */


EEPROM_Write (Temp1,NoofBytes,&ptr_address);

/* Data written from buffer Temp1 to EEPROM memory address 1000h */
/* EEPROM_Write (Temp1,5,(unsigned char * far )0x1000); */ /* Write function
is called in this way for hiware compiler, when small memory model is used */
while (EEPROM_Programming () != EEPROM_PROG_COMPLETE);
/* Waiting till all data bytes programmed from latch to EEPROM cells */

EEPROM_Read (Temp2,NoofBytes,&ptr_address);
/* Reads data from EEPROM address 1000h and stores it in buffer Temp2 */
/* EEPROM_Read (Temp2,5,(unsigned char * far) 0x1000); */ /* Read function
is called in this way for hiware compiler, when small memory model is used */
for (i = 0; i<5;i++)
{ /* Comparison of written data and data read */
if ((*(Temp1+i)) != (*(Temp2+i)))
{ /* Mismatch between written data and data read */
while (1);
}
}
}
/*Program Stop */
/*============================================================*/
