And can you tell me how do I set frequency or baud rate my micro is running at 40MHz? I have to run EEPROM at <1MHz.
I never looked at the code before so this is with a large grain of salt but if this is the code to shift a bit out on the i2c bus
void bit_out(unsigned char data)
{
unsigned int i;
SCL = 0; // ensure SCL is low
SDA_TRIS=0; // configure SDA as an output
SDA= (data>>7); // output the MSB
for (i=0;i<2;i++) NOP();
SCL = 1; // pull SCL high to clock bit
for (i=0;i<3;i++) NOP();
SCL = 0; // pull SCL low for next bit
}
Then you can count the speed by looking up the nr of cycles each of the instructions will take, but easier (quicker) to hookup an oscilloscope and measure the bit time.
If you need a slower bit time then you can do it the quick and dirty way by adding more NOP statements in the for (i=0;i<2;i++) NOP(); loop so actually changing the i<x where x is the amount needed to slow it down.
Be sure to keep it 50% DC though, so both delay loops need to be equal or if you need a real slow bus by adding your interrupt service routine to some hardware timer you programmed (not sure if you have a hardware timer left) or even more slow a software timer.
But as I said I am not a Microchip programmer so maybe ask someone else.