我写了个小程序,本想用I2C模块来控制CH423来驱动液晶,但现在发现我的数据发不出去,这里的程序我把它简化了,我的目的是想让CH423的OC0-OC7输出低电平.请大家帮我看下程序哪里不对?先谢大家了
============================================================
#include "p30f2010.h"
int main()
{
OpenI2C();
write_I2C(0X48,0X00);//OC0-OC7为通用输出,OC8-OC15为通用输出,禁止电平变化中断,
write_I2C(0x44,0x00);//OC0-OC7输出低电平
}
int write_I2C( I2C_cmd, I2C_data)
{
StartI2C();
while(I2CCONbits.SEN==1);
MasterWriteI2C(I2C_cmd); /* 8 bit cmd*/
while(I2CSTATbits.TRSTAT);
if(I2CSTATbits.ACKSTAT)
{return 0;}
MasterWriteI2C(I2C_data); /*8 bit data*/
while(I2CSTATbits.TRSTAT);
if(I2CSTATbits.ACKSTAT)
{ return 0;}
StopI2C();
while(I2CCONbits.PEN);
return 1;
}
MasterWriteI2C(int data_out)
{
I2CTRN = data_out;
if(I2CSTATbits.IWCOL) /* If write collision occurs,return -1 */
{I2CSTATbits.IWCOL=0;return -1;}
else
{return 0;}
}
OpenI2C()
{
I2CBRG =12; /*BAUD= 400khz,at 7.3728mhz fcy*/
I2CCONbits.I2CEN=1;
}
StartI2C()
{
I2CCONbits.SEN=1; /* initiate Start on SDA and SCL pins */
}
StopI2C()
{
I2CCONbits.PEN=1; /* initiate Stop on SDA and SCL pins */
}
电路图
1072811209905502.pdf 1072811209905550.pdf CH423资料