求大家帮我看看下面这个程序(PIC16F1937作为I2C主节点向PCF8576D写数据,显示不正确),我按照应用笔记上的时序操作的,但是有问题,不知道问题出在哪?要延时还是怎么的?各位大侠有调试通过了的C语言的硬件I2C主模式的写程序吗?能否提供我一份,非常感谢!
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;
while(ACKSTAT);
}
PEN = 1;
while(PEN);
}
} |