[Description]

Location = "Xicor (X)\X24C00";
Info = " Module for programming 2-Wire Serial EEPROMs",
       " Memory types: Xicor 24C00.",
        " --------------------------------------------------------------",
	"   Bus: I2C. Features Xicor.",
	"   Size: 16 bytes",
        " --------------------------------------------------------------",
	"   Author: ETL (C) 2004";
Buffer1 = "EEPROM",16;
Picture = "X24c00.bmp";
VCC = 8;
GND = 4;

[Menu]

Read	= "&Read",ReadButton,"Read chip";
Write   = "&Write",WriteButton,"Write chip";
Compare = "&Vertify",CheckButton,"Compare with buffer";
Info    = "&About module",ModuleInfoButton,"Show module info";

[Interface]

[Code]

define		END_ADR 16	
define		SDAOUT	POUT.4
define		SDAIN	PIN.4
define		SCL	POUT.5


//***********************************************************
//*       Read                                             **
//***********************************************************
Proc Read {
 
  var Error,Adress;

  print("");print("   Reading chip X24C00...");
  Init;
  Error = 0;Adress = 0;
  while(Adress != END_ADR) {
    FDATA = ReadByte(Adress);
    FDPTR++;Adress++;PBPos++;
  }
  print("   Reading is done. %d bytes were readed",Adress);	
}
//***********************************************************


//***********************************************************
//*       Compare                                          **
//***********************************************************
Proc Compare
{
  var Adress,Errors,Temp;

  print("");print("   Verifying chip X24C00...");
  Init;
  Adress = 0;Errors = 0;
  while(Adress != 16) {
    Temp = ReadByte(Adress);
    FSEL = 1;
    if(Temp != FDATA) {FSEL = 0; Errors++;}
    Adress++;PBPos++;FDPTR++;
  }
  print("   Verifying is done. %d bytes were compared. Number of mismatch %d.",Adress,Errors);
}

Proc Write {

  var Error;

  print("");print("   Writing chip X24C00...");
  Init;
  Error = 0;
  while(FDPTR != END_ADR) {
    WriteByte(FDPTR,FDATA);
    FDPTR++;PBPos++;
  }
  print("   Writing is done. %d bytes were writed.",FDPTR);
}


Proc WriteByte(Adress,Data) {

  var Temp;

  Temp = Adress << 2;
  Temp = Temp | 0b01000000;
  StartI2C;
  ShiftByteToI2C(Temp);
  ShiftByteToI2C(Data);
  StopI2C;
  Delay(10);
}


Proc ShiftByteFromI2C
{
  var Counter,Byte;
  SDAOUT = 1; Byte = 0; Counter = 8;
  while(Counter <> 0) {
    Byte = Byte << 1; SCL = 1; Byte.0 = SDAIN; SCL = 0; 
    Counter--; 
  }
  return(Byte);
}

Proc StartI2C { SDAOUT = 0; SCL = 0; } 

Proc StopI2C { SCL = 1; SDAOUT = 1; } 

Proc ReadByte(Adress) {

  var Temp;

  Temp = Adress << 2;
  Temp = Temp | 0b10000000;
  StartI2C;
  ShiftByteToI2C(Temp);
  Temp = ShiftByteFromI2C;
  StopI2C;
  return(Temp);
}

Proc ShiftByteToI2C(Byte)
{
  var Counter;
  Counter = 8;
  while(Counter <> 0) {
    SDAOUT = Byte.7; SCL = 1; SCL = 0; Byte = Byte << 1;
    Counter--;	
  }
  SDAOUT = 0;
}

Proc Init {
  PBMax = END_ADR;PBPos = 0;FDPTR = 0;
  POUT = 0x00;
  SDAOUT = 1; SCL = 1;
}


Proc Info {
  print("");
  print("  Module for programming 2-Wire(I2C) serial EEPROMs memory types X24C00.");
  print("");
  print("  Next functions are support:");
  print("     reading,");
  print("     writing,");
  print("     verifying.");
  print("");
  print("  Copyright (C) 2004 ETL.");
}

