
#include<I2C.h>
#include<generic.h>
#include<serial.h>
void serial_interrupt() interrupt 4
{
	if(TI)
		{
		TI = 0;
		}	
	if(RI)
		{
		RI = 0;
		}
}

void main()
{
char BYTE_GET = 0x00;//this is to store and send the data that is read 
char DATA_ = 0x00;//this is to store the present value of data
char ADD_ = 0x10;//this is to store the present value of address
initialize_serial();//intializes the serial port
while(1)
 {
 /********WRITE TO ADDRESS********/
 i2c_transmit_start();
 i2c_transmit_byte(0xA0);
 i2c_transmit_byte(0x10);//higher byte of address
 i2c_transmit_byte(ADD_);//lower byte of address
 i2c_transmit_byte(DATA_);
 i2c_transmit_stop();

 msec_wait(200);//wait after write for 200 mili-seconds
 /********READ FROM ADDRESS*******/
 i2c_transmit_start();
 i2c_transmit_byte(0xA0);
 i2c_transmit_byte(0x10);//higher byte of address
 i2c_transmit_byte(ADD_);//lower byte of address
 i2c_transmit_restart();
 i2c_transmit_byte(0xA1);
 BYTE_GET = i2c_receive_byte(I2C_NAK);
 i2c_transmit_stop(); 
 SBUF = BYTE_GET;//sends the character read serially to my PC 
 DATA_++;//increments the data that is to be written next
/******************************************/ 
 ADD_++;//increments the lower byte of address
 }
}

