#include "pcf8574.h"
IIC_STATUS PCF8574ReadByte(const IIC_PIN *I, uint8_t *ch)
{
uint8_t tmp;
IIC_STATUS status;
IIC_Start(I);
IIC_WriteByte(I, I->ADDR | 0x01);
status = IIC_Wait_ACK(I);
if(status)
{
return(IIC_WRITE_ERR);
}
else
{
IIC_ReadByte(I, &tmp);
IIC_NACK(I);
IIC_Stop(I);
*ch = tmp;
return(IIC_OK);
}
}
IIC_STATUS PCF8574WriteByte(const IIC_PIN *I, uint8_t ch)
{
IIC_STATUS status;
IIC_Start(I);
IIC_WriteByte(I, I->ADDR);
status = IIC_Wait_ACK(I);
if(status)
{
return(IIC_WRITE_ERR);
}
else
{
IIC_WriteByte(I, ch);
status |= IIC_Wait_ACK(I);
IIC_Stop(I);
if(status)
{
return(IIC_WRITE_ERR);
}
else
{
return(IIC_OK);
}
}
}
#ifndef __PCF8574_HEADER__
#define __PCF8574_HEADER__
#include "hal_iic.h"
IIC_STATUS PCF8574ReadByte(const IIC_PIN *I, uint8_t *ch);
IIC_STATUS PCF8574WriteByte(const IIC_PIN *I, uint8_t ch);
#endif
PCF8574中文手册.pdf