小弟最近調試STM8S105C6T6對顯示面板IC的通訊
總是卡在I2C_BUSY或I2C_SB
以下是小弟試寫的I2C程式,煩請神人指點一二
void I2C_Write(unsigned char *address, unsigned char number)
{
while( I2C_BUSY )
I2C_START=1;
while( !I2C_SB );
I2C_DR=0x78;
while( !I2C_ADDR );
while( !I2C_TXE || !I2C_BTF);
_asm("NOP");
_asm("NOP");
if( number )
{
while( number --)
{
while( !I2C_BTF || !I2C_TXE );
I2C_DR = 0x00;
while( !I2C_BTF || !I2C_TXE );
I2C_DR = *(address++);
}
}
while(!I2C_BTF || !I2C_TXE);
I2C_STOP=1;
}
|