求大家帮我看看,这个用MSSP模块实现PIC16F1937进行I2C主模式向从模块PCF8576D写数据的程序有什么问题吗?我写过去的显示数据很乱啊
uchar DisBuf[19] = {0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf};
void main()
{
OSCCON = 0x7a;
// INTOSCIO, PLL disabled, Fosc = 16MHz
PORTC = 0x60;
LATC = 0x60;
TRISC = 0x9e;
// SCL and SDA is input
SSPADD = 0x09;
// 0x09 for 400kHz at 16MHz
SSPSTAT = 0x00;
// Enable High speed 400kHz slew rate control
SSPCON1 = 0x28;
// Enable I2C Master initially
SSPCON2 = 0x00;
// Clear control bits
SSPCON3 = 0x08;
// Disable all interrupt of I2C Master, keep 300ns on SDA after SCL's falling edge
While(1){
SEN = 1;
while(SEN);
SSPBUF = PCF8576D_Addr & 0xfe;
while(ACKSTAT);
SSPBUF = 0xe0;
while(ACKSTAT);
SSPBUF = 0xc8;
while(ACKSTAT);
SSPBUF = 0x00;
while(ACKSTAT);
for(i=0;i<19;i++){
SSPBUF = DisBuf[i];
while(ACKSTAT);
}
PEN = 1;
while(PEN);
}
}
}
} |