This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

help! how to use i2c of p89c669

who has the i2c program of p89c669 ?Please send me a copy!thanks a lot!my e-mail adrress is railyangjin@yahoo.com.cn
i have do it for several days,but i can't solve the problem.this is my program:
#include <reg669.h>
#include <absacc.h>
sbit P1_4=P1^4;
//**************************************
void int_i2c()
{
I2CLL=250; //&#35774;&#32622;I2C&#30340;&#27874;&#29305;&#29575;
I2CLH=0;
EI2C=1; //I2C&#20013;&#26029;&#20801;&#35768;&#20301;
}
//**************************************
void GetBus()
{
P1=0xC0;
I2CON=0xc4;
//I2EN=1 STA=0 STO=0 SI=0 AA=1
int_i2c();
I2CON=0xe4; // STA=1
while(I2CON&0x08==0);//&#31561;&#24453;&#36215;&#22987;&#20301;&#30340;&#21457;&#36865;
}
//***************************************
void SendByte(unsigned char c)
{
I2DAT=c; //I2CON=I2CON&0x0f7;
I2CON=0xc4; //SI=0 &#28165;&#38500;SI &#20301;&#31561;&#31561;
while(I2CON&0x08==0);//&#31561;&#24453;&#25968;&#25454;&#30340;&#21457;&#36865;
}
//***************************************
bit write_fm31256()
{
GetBus();
if(I2STA!=0x08){I2CON=0xD4;return(0);}
SendByte(0xa0);
//slave adress(ramtron's fm32256)
if(I2STA!=0x18){I2CON=0xD4;return(0);}SendByte(0x00);
if(I2STA!=0x28){I2CON=0xD4;return(0);}SendByte(0x00);
if(I2STA!=0x28){I2CON=0xD4;return(0);
SendByte(0x02);
if(I2STA!=0x28){I2CON=0xD4;return(0);}I2CON=0xD4; return(1);
}
//************************************
void main()
{ P1_4=1;
EI2C=0;
write_fm31256();
tt=write_fm31256();
if(tt) P1_4=0;
}
but the output of P1.4 is 1,it also means the write opration is fail.

0