stc15f104w iic初始化配置
时间: 2024-01-11 18:04:21 浏览: 82
根据引用内容,以下是STC15F104W的IIC初始化配置的示例代码:
```c
#include <reg52.h>
sbit SDA = P2^0; // 定义SDA引脚
sbit SCL = P2^1; // 定义SCL引脚
void IIC_Start()
{
SDA = 1;
SCL = 1;
SDA = 0;
SCL = 0;
}
void IIC_Stop()
{
SDA = 0;
SCL = 1;
SDA = 1;
}
bit IIC_WaitAck()
{
bit ack;
SDA = 1;
SCL = 1;
ack = SDA;
SCL = 0;
return ack;
}
void IIC_SendByte(unsigned char dat)
{
unsigned char i;
for (i = 0; i < 8; i++)
{
SDA = dat & 0x80;
SCL = 1;
SCL = 0;
dat <<= 1;
}
}
unsigned char IIC_ReceiveByte()
{
unsigned char i, dat = 0;
SDA = 1;
for (i = 0; i < 8; i++)
{
dat <<= 1;
SCL = 1;
dat |= SDA;
SCL = 0;
}
return dat;
}
void IIC_Init()
{
SDA = 1;
SCL = 1;
}
int main()
{
IIC_Init();
// 其他初始化配置代码
return 0;
}
```
阅读全文