📄 i2c.h
字号:
sbit SDA=P2^1;
sbit SCL=P2^0;
void Delayus(unsigned int number)
{
while(number--);
}
void DelayMs(unsigned int number)
{
unsigned char temp;
for(;number!=0;number--)
{
for(temp=112;temp!=0;temp--);
{}
}
}
void iic_start()
{
SDA=1;
Delayus(4);
SCL=1;
Delayus(4);
SDA=0;
Delayus(4);
SCL=0;
Delayus(4);
}
void iic_stop()
{
SCL=0;
Delayus(4);
SDA=0;
Delayus(4);
SCL=1;
Delayus(4);
SDA=1;
Delayus(4);
}
void iic_ack()
{
SDA=0;
Delayus(4);
SCL=1;
Delayus(4);
SCL=0;
Delayus(4);
SDA=1;
Delayus(4);
}
void iic_NoAck()
{
SDA=1;
Delayus(4);
SCL=1;
Delayus(4);
SCL=0;
Delayus(4);
SDA=0;
}
bit iic_testack()
{
bit ErrorBit;
SDA=1;
Delayus(4);
SCL=1;
Delayus(4);
ErrorBit=SDA;
Delayus(4);
SCL=0;
return ErrorBit;
}
void iic_write8bit(unsigned char input)
{
unsigned char temp;
for(temp=8;temp!=0;temp--)
{
SDA=(bit)(input&0x80);
Delayus(4);
SCL=1;
Delayus(4);
SCL=0;
Delayus(4);
input=input<<1;
}
}
unsigned char iic_read8bit()
{
unsigned char temp,rbyte=0;
for(temp=8;temp!=0;temp--)
{
SCL=1;
Delayus(4);
rbyte=rbyte<<1;
rbyte=rbyte|((unsigned char)SDA);
SCL=0;
}
return rbyte;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -