EasyManua.ls Logo

STC micro STC8A8K64D4 Series - Page 618

Default Icon
901 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
STC8A8K64D4 Series Manual
- 602 -
sfr P5M1 = 0xc9;
sfr P5M0 = 0xca;
sbit SDA = P1^4;
sbit SCL = P1^5;
void Wait()
{
while (!(I2CMSST & 0x40));
I2CMSST &= ~0x40;
}
void Start()
{
I2CMSCR = 0x01; //Send START command
Wait();
}
void SendData(char dat)
{
I2CTXD = dat; //Write data to the data buffer
I2CMSCR = 0x02; //Send a SEND command
Wait();
}
void RecvACK()
{
I2CMSCR = 0x03; //Send read ACK command
Wait();
}
char RecvData()
{
I2CMSCR = 0x04; //Send RECV command
Wait();
return I2CRXD;
}
void SendACK()
{
I2CMSST = 0x00; //Setup the ACK signal
I2CMSCR = 0x05; //Send ACK command
Wait();
}
void SendNAK()
{
I2CMSST = 0x01; //Setup the NAK signal
I2CMSCR = 0x05; //Send ACK command
Wait();
}
void Stop()
{
I2CMSCR = 0x06; //Send STOP command
Wait();
}

Table of Contents

Related product manuals