#include <reg952.h>
#include "uart.c"
#include "i2c_callback.c"
#include "i2c.c"

#define address 0x0000
#define M24C01 0x50	// 0101 0000
void main(void)
{
  P1M1 &= 0xEF;
  P1M1 |= 0x20;
  P1M2 &= 0xDF;
  P1M2 |= 0x10;
  P1 |= 0x10;  // putting P1.4=1
  i2c_init(0x00, 0);
  EA=1;

  i2cVector[0]=(unsigned char)((address&0xFF00)>>8);
  i2cVector[1]=(unsigned char)(address&0xFF);
  i2cVector[2]=0x5A;

  i2cIndex=3;	// number of bytes to be transmited/received
  i2c_transmit(M24C01);	// send peripherical address
  while(i2c_getstatus() & I2C_BUSY);// wait to finish
  
  while(1);
}

// interrupt
  
// ACK for data byte
    case 0x28:
      if (i2c_master_islasttxbyte(mbytenum))  // only verify if byte is the last
      {
        // stop condition
        STA = 0;
        STO = 1;
        mi2cstatus = I2C_OK;
        i2c_transfer_finished();
	P1&=0xEF;  // This is NOT  work !
      }
      else
      {
        mbytenum++;
        I2DAT = i2c_master_getbyte(mbytenum);
        STA = 0;
        STO = 0;
      } // if

      break;