EasyManua.ls Logo

STC micro STC8A8K64D4 Series - Page 630

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
- 614 -
}
else if (I2CSLST & 0x10)
{
I2CSLST &= ~0x10; //Handle the SEND event
if (I2CSLST & 0x02)
{
I2CTXD = 0xff; //Stop receiving data when receiving NAK
}
else
{
I2CTXD = buffer[++addr]; //Continue reading data when receiving ACK
}
}
else if (I2CSLST & 0x08)
{
I2CSLST &= ~0x08; //Handle the STOP event
isda = 1;
isma = 1;
}
_pop_(P_SW2);
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
I2CCFG = 0x81; //Enable I2C slave mode
I2CSLADR = 0x5a; //Set the slave device address to 5A
//That is, I2CSLADR[7:1]=010_1101B, MA=0B.
//Since MA is 0, the device address sent by the host must be
// the same as I2CSLADR[7:1] to access this I2C slave device.
//If the host needs to write data, it will send 5AH(0101_1010B)
I2CSLST = 0x00;
I2CSLCR = 0x78; //Enable interrupt of slave mode
EA = 1;
isda = 1; //User variable initialization
isma = 1;
addr = 0;
I2CTXD = buffer[addr];
while (1);
}

Table of Contents

Related product manuals