|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#include "EW_iic.h"
void EW_IIC_Start(void )
{
SDA_H;
__delay_cycles(8); //1us
SCL_H;
__delay_cycles(8); //1us
SDA_L;
__delay_cycles(80); //10us
SCL_L;
__delay_cycles(80); //10us
}
void EW_IIC_Stop(void )
{
SDA_L;
__delay_cycles(8); //1us
SCL_L;
__delay_cycles(8); //1us
SCL_H;
__delay_cycles(80); //10us
SDA_H;
__delay_cycles(80); //10us
}
void EW_IIC_WriteByte(INT8U txbyte)
{
INT8U mask;
for(mask = 0x80; mask > 0; mask >>= 1)
{
if((mask & txbyte) == 0) SDA_L;
else SDA_H;
__delay_cycles(16); //2us
SCL_H;
__delay_cycles(16); //2us
SCL_L;
if(mask == 1)
{
SDA_InitInputF();
}
}
__delay_cycles(16); //2us
SCL_H;
/*
if(!SDA_READ)
{
LED_TOG;
}
*/
__delay_cycles(16); //2us
SCL_L;
__delay_cycles(16); //2us
SDA_H;
SDA_InitOutHigh();
}
void EW_IIC_ReadByte(INT8U *rxbyte, AckDef ack)
{
INT8U mask;
*rxbyte = 0x00;
SCL_L;
SDA_InitInputF();
for(mask = 0x80; mask > 0; mask >>= 1)
{
__delay_cycles(16);
SCL_H;
if(SDA_READ) *rxbyte |= mask;
__delay_cycles(16);
SCL_L;
}
SDA_InitOutHigh();
if(ack == ACK) SDA_L;
else SDA_H;
__delay_cycles(16);
SCL_H;
__delay_cycles(40);
SCL_L;
SDA_H;
__delay_cycles(16);
} |
|