/*********************************************************************************************************
** Function name : WriteCommdByte
** Descriptions : 设置HT16C21参数
** input parameters : ComByte(命令);ComSet(写入的设置数据)
** output parameters : 无
** Returned value : 无
*********************************************************************************************************/
_Bool WriteCommdByte(unsigned char ComByte, unsigned char ComSet)
{
unsigned char ack;
IIC_Start(); //开始数据传递
ack=IIC_WriteByte(0x70); //HT16C21芯片地址,硬件I2c时为0x38
if(ack==0) {return 0;}
ack=IIC_WriteByte(ComByte); //写入命令
if(ack==0) {return 0;}
ack=IIC_WriteByte(ComSet); //写入命令设置数据
if(ack==0) {return 0;}
IIC_Stop(); //停止数据传递
return 1;
/*********************************************************************************************************
** Function name : WriteRAMByte
** Descriptions : 向HT16C21中的指定地址写入数据
** 在指定地址addr处写入数据date
** input parameters : Address (储存指定的地址)Data 存储读出的数据
** output parameters : 无
** Returned value : 无
*********************************************************************************************************/
void
WriteRAMByte(
unsigned
char Address,
unsigned
char Data)
{
IIC_Start();
//开始数据传递
IIC_WriteByte(0x70);
////HT16C21芯片地址,硬件I2c时为0x38
IIC_WriteByte(0x80);
//写入读写命令
IIC_WriteByte(Address);
//写入指定地址
IIC_WriteByte(Data);
//向当前地址(上面指定的地址)写入数据
IIC_Stop();
//停止数据传递
}
/*********************************************************************************************************/
/*********************************************************************************************************
** Function name : IIC_ReadSet
** Descriptions : 从HT16C21中的指定地址读取数据
** 在指定地址读取数据
** input parameters : Address 指定地址
** output parameters : 无
** Returned value : ReadValue 存储的数据
*********************************************************************************************************/
unsigned
char
IIC_ReadSet(
unsigned
char Address)
{
unsigned
char ReadValue,Ack;
IIC_Start();
//开始数据传递
Ack=
IIC_WriteByte(0x70);
////HT16C21芯片地址,硬件I2c时为0x38
if(Ack==
0) {
return
0;}
Ack=
IIC_WriteByte(0x80);
//选择要操作的HT16C21芯片,写入读数据命令
if(Ack==
0) {
return
0;}
Ack=
IIC_WriteByte(Address);
//写入读数据的指定地址
if(Ack==
0) {
return
0;}
IIC_Start();
//开始数据传递
Ack=
IIC_WriteByte(OpRead);
//选择要操作的HT16C21芯片,写入读操作指令
if(Ack==
0) {
return
0;}
ReadValue=
IIC_ReadByte();
//在指定地址读取数据
IIC_Stop();
//停止数据传递
return(ReadValue);
//将指定地址读出的数据返回
}
/*********************************************************************************************************/