#include "SGM4591Q.h"
#include "Simulated_IIC_1_Master.h"
#include "Simulated_IIC_2_Master.h"
#include "Simulated_IIC_3_Master.h"
#include "Simulated_IIC_4_Master.h"




/*发送*/
void SGM4591Q_IIC1_Send(uint8_t Address, uint8_t Register, uint8_t Function)
{
  uint8_t u8Ack;
  /*开始*/
  Simulated_IIC_1_Start();
  /*地址*/
  Simulated_IIC_1_Transmit_Data(Address);
  /*ACK*/
  u8Ack = Simulated_IIC_1_Receive_ACK();
  /*寄存器*/
  Simulated_IIC_1_Transmit_Data(Register);
  /*控制数据*/
  Simulated_IIC_1_Transmit_Data(Function);
  /*停止*/
  Simulated_IIC_1_Stop();
}
/*发送*/
void SGM4591Q_IIC2_Send(uint8_t Address, uint8_t Register, uint8_t Function)
{
  uint8_t u8Ack;
  /*开始*/
  Simulated_IIC_2_Start();
  /*地址*/
  Simulated_IIC_2_Transmit_Data(Address);
  /*ACK*/
  u8Ack = Simulated_IIC_2_Receive_ACK();
  /*寄存器*/
  Simulated_IIC_2_Transmit_Data(Register);
  /*控制数据*/
  Simulated_IIC_2_Transmit_Data(Function);
  /*停止*/
  Simulated_IIC_2_Stop();
}
/*发送*/
void SGM4591Q_IIC3_Send(uint8_t Address, uint8_t Register, uint8_t Function)
{
  uint8_t u8Ack;
  /*开始*/
  Simulated_IIC_3_Start();
  /*地址*/
  Simulated_IIC_3_Transmit_Data(Address);
  /*ACK*/
  u8Ack = Simulated_IIC_3_Receive_ACK();
  /*寄存器*/
  Simulated_IIC_3_Transmit_Data(Register);
  /*控制数据*/
  Simulated_IIC_3_Transmit_Data(Function);
  /*停止*/
  Simulated_IIC_3_Stop();
}
/*发送*/
void SGM4591Q_IIC4_Send(uint8_t Address, uint8_t Register, uint8_t Function)
{
  uint8_t u8Ack;
  /*开始*/
  Simulated_IIC_4_Start();
  /*地址*/
  Simulated_IIC_4_Transmit_Data(Address);
  /*ACK*/
  u8Ack = Simulated_IIC_4_Receive_ACK();
  /*寄存器*/
  Simulated_IIC_4_Transmit_Data(Register);
  /*控制数据*/
  Simulated_IIC_4_Transmit_Data(Function);
  /*停止*/
  Simulated_IIC_4_Stop();
}
/*接收*/
void SGM4591Q_IIC_Receive(void)
{
  ;
}

uint16_t ADC_4=0;

uint8_t SGM4591Q_Init_Once = 0;
/*所有引脚设置为输出*/
void SGM4591Q_Init(void);
void SGM4591Q_Init(void)
{
  /*U59:A0低，A1低*/
  SGM4591Q_IIC1_Send(0xE8, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC1_Send(0xE8, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC1_Send(0xE8, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC1_Send(0xE8, 0x09, 0xFF);/*推挽输出*/

  /*U71:A0低，A1高*/
  SGM4591Q_IIC1_Send(0xEC, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC1_Send(0xEC, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC1_Send(0xEC, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC1_Send(0xEC, 0x09, 0xFF);/*推挽输出*/

  /*U72:A0高，A1低*/
  SGM4591Q_IIC1_Send(0xEA, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC1_Send(0xEA, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC1_Send(0xEA, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC1_Send(0xEA, 0x09, 0xFF);/*推挽输出*/
  
  /*U69:A0高，A1高*/
  SGM4591Q_IIC1_Send(0xEE, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC1_Send(0xEE, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC1_Send(0xEE, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC1_Send(0xEE, 0x09, 0xFF);/*推挽输出*/
  /***********************************************************/
  /*U62:A0低，A1低*/
  SGM4591Q_IIC2_Send(0xE8, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC2_Send(0xE8, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC2_Send(0xE8, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC2_Send(0xE8, 0x09, 0xFF);/*推挽输出*/

  /*U64:A0低，A1高*/
  SGM4591Q_IIC2_Send(0xEC, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC2_Send(0xEC, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC2_Send(0xEC, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC2_Send(0xEC, 0x09, 0xFF);/*推挽输出*/

  /*U70:A0高，A1低*/
  SGM4591Q_IIC2_Send(0xEA, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC2_Send(0xEA, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC2_Send(0xEA, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC2_Send(0xEA, 0x09, 0xFF);/*推挽输出*/
  
  /*U76:A0高，A1高*/
  SGM4591Q_IIC2_Send(0xEE, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC2_Send(0xEE, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC2_Send(0xEE, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC2_Send(0xEE, 0x09, 0xFF);/*推挽输出*/
  /***********************************************************/
  /*U61:A0低，A1低*/
  SGM4591Q_IIC3_Send(0xE8, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC3_Send(0xE8, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC3_Send(0xE8, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC3_Send(0xE8, 0x09, 0xFF);/*推挽输出*/

  /*U74:A0低，A1高*/
  SGM4591Q_IIC3_Send(0xEC, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC3_Send(0xEC, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC3_Send(0xEC, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC3_Send(0xEC, 0x09, 0xFF);/*推挽输出*/

  /*U67:A0高，A1低*/
  SGM4591Q_IIC3_Send(0xEA, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC3_Send(0xEA, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC3_Send(0xEA, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC3_Send(0xEA, 0x09, 0xFF);/*推挽输出*/
  
  /*U66:A0高，A1高*/
  SGM4591Q_IIC3_Send(0xEE, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC3_Send(0xEE, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC3_Send(0xEE, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC3_Send(0xEE, 0x09, 0xFF);/*推挽输出*/
  /***********************************************************/
  /*U60:A0低，A1低*/
  SGM4591Q_IIC4_Send(0xE8, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC4_Send(0xE8, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC4_Send(0xE8, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC4_Send(0xE8, 0x09, 0xFF);/*推挽输出*/

  /*U75:A0低，A1高*/
  SGM4591Q_IIC4_Send(0xEC, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC4_Send(0xEC, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC4_Send(0xEC, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC4_Send(0xEC, 0x09, 0xFF);/*推挽输出*/

  /*U77:A0高，A1低*/
  SGM4591Q_IIC4_Send(0xEA, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC4_Send(0xEA, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC4_Send(0xEA, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC4_Send(0xEA, 0x09, 0xFF);/*推挽输出*/
  
  /*U65:A0高，A1高*/
  SGM4591Q_IIC4_Send(0xEE, 0x06, 0);/*P0组引脚为输出*/
  SGM4591Q_IIC4_Send(0xEE, 0x07, 0);/*P1组引脚为输出*/
  SGM4591Q_IIC4_Send(0xEE, 0x08, 0xFF);/*推挽输出*/
  SGM4591Q_IIC4_Send(0xEE, 0x09, 0xFF);/*推挽输出*/
}

uint8_t SGM4591Q_U7_Out_P0 = 0xFF;
uint8_t SGM4591Q_U7_Out_Keep_P0 = 0x00;

uint8_t SGM4591Q_U7_Out_P1 = 0xFF;
uint8_t SGM4591Q_U7_Out_Keep_P1 = 0x00;

uint8_t SGM4591Q_U9_Out_P0 = 0;
uint8_t SGM4591Q_U9_Out_Keep_P0 = 0x00;

uint8_t SGM4591Q_U9_Out_P1 = 0;
uint8_t SGM4591Q_U9_Out_Keep_P1 = 0x00;

void SGM4591Q_Control(void)
{
  if (SGM4591Q_Init_Once == 0)
  {
    SGM4591Q_Init_Once = 1;
    SGM4591Q_Init();
  }

  if (ADC_4 > 2000) /*U9:03/07拉低*/
  {
    SGM4591Q_U9_Out_P0 = 0x77;
  }

  // if (ADC_4 < 1800) /*U9:03/07恢复*/
  // {
  //   SGM4591Q_U9_Out_P0 = 0xFF;
  // }

  // if (SGM4591Q_U7_Out_Keep_P0 != SGM4591Q_U7_Out_P0)
  // {
  //   SGM4591Q_IIC2_Send(0xEA, 0x02, SGM4591Q_U7_Out_P0);
  //   SGM4591Q_U7_Out_Keep_P0 = SGM4591Q_U7_Out_P0;
  // }

  // if (SGM4591Q_U7_Out_Keep_P1 != SGM4591Q_U7_Out_P1)
  // {
  //   SGM4591Q_IIC2_Send(0xEA, 0x03, SGM4591Q_U7_Out_P1);
  //   SGM4591Q_U7_Out_Keep_P1 = SGM4591Q_U7_Out_P1;
  // }

  if (SGM4591Q_U9_Out_Keep_P0 != SGM4591Q_U9_Out_P0)
  {
    /*设置端口输出电平高低*/
    SGM4591Q_IIC2_Send(0xE8, 0x02, SGM4591Q_U9_Out_P0);
    SGM4591Q_U9_Out_Keep_P0 = SGM4591Q_U9_Out_P0;
  }

  if (SGM4591Q_U9_Out_Keep_P1 != SGM4591Q_U9_Out_P1)
  {
    /*设置端口输出电平高低*/
    SGM4591Q_IIC2_Send(0xE8, 0x03, SGM4591Q_U9_Out_P1);
    SGM4591Q_U9_Out_Keep_P1 = SGM4591Q_U9_Out_P1;
  }
}
uint8_t SGM4591Q_Chip1_1_Segment0_Last;
uint8_t SGM4591Q_Chip1_1_Segment1_Last;
uint8_t SGM4591Q_Chip1_2_Segment0_Last;
uint8_t SGM4591Q_Chip1_2_Segment1_Last;
uint8_t SGM4591Q_Chip1_3_Segment0_Last;
uint8_t SGM4591Q_Chip1_3_Segment1_Last;
uint8_t SGM4591Q_Chip1_4_Segment0_Last;
uint8_t SGM4591Q_Chip1_4_Segment1_Last;
uint8_t SGM4591Q_Chip2_1_Segment0_Last;
uint8_t SGM4591Q_Chip2_1_Segment1_Last;
uint8_t SGM4591Q_Chip2_2_Segment0_Last;
uint8_t SGM4591Q_Chip2_2_Segment1_Last;
uint8_t SGM4591Q_Chip2_3_Segment0_Last;
uint8_t SGM4591Q_Chip2_3_Segment1_Last;
uint8_t SGM4591Q_Chip2_4_Segment0_Last;
uint8_t SGM4591Q_Chip2_4_Segment1_Last;
uint8_t SGM4591Q_Chip3_1_Segment0_Last;
uint8_t SGM4591Q_Chip3_1_Segment1_Last;
uint8_t SGM4591Q_Chip3_2_Segment0_Last;
uint8_t SGM4591Q_Chip3_2_Segment1_Last;
uint8_t SGM4591Q_Chip3_3_Segment0_Last;
uint8_t SGM4591Q_Chip3_3_Segment1_Last;
uint8_t SGM4591Q_Chip3_4_Segment0_Last;
uint8_t SGM4591Q_Chip3_4_Segment1_Last;
uint8_t SGM4591Q_Chip4_1_Segment0_Last;
uint8_t SGM4591Q_Chip4_1_Segment1_Last;
uint8_t SGM4591Q_Chip4_2_Segment0_Last;
uint8_t SGM4591Q_Chip4_2_Segment1_Last;
uint8_t SGM4591Q_Chip4_3_Segment0_Last;
uint8_t SGM4591Q_Chip4_3_Segment1_Last;
uint8_t SGM4591Q_Chip4_4_Segment0_Last;
uint8_t SGM4591Q_Chip4_4_Segment1_Last;
/*多次对引脚的控制，后面的操作不能影响之前的控制*/
/*
Chip:片选
Segment:段P0/P1
PIN:端口0--7
*/
void SGM4591Q_Global_Control(uint8_t Chip, uint8_t Segment)
{
  switch (Chip)
  {
  case SGM4591Q_Chip1_1:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip1_1_Segment0.UINT8 != SGM4591Q_Chip1_1_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xE8, 0x02, SGM4591Q_Chip1_1_Segment0.UINT8);
        SGM4591Q_Chip1_1_Segment0_Last = SGM4591Q_Chip1_1_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip1_1_Segment1.UINT8 != SGM4591Q_Chip1_1_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xE8, 0x03, SGM4591Q_Chip1_1_Segment1.UINT8);
        SGM4591Q_Chip1_1_Segment1_Last = SGM4591Q_Chip1_1_Segment1.UINT8;
      }
    }
    break;
  case SGM4591Q_Chip1_2:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip1_2_Segment0.UINT8 != SGM4591Q_Chip1_2_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEC, 0x02, SGM4591Q_Chip1_2_Segment0.UINT8);
        SGM4591Q_Chip1_2_Segment0_Last = SGM4591Q_Chip1_2_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip1_2_Segment1.UINT8 != SGM4591Q_Chip1_2_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEC, 0x03, SGM4591Q_Chip1_2_Segment1.UINT8);
        SGM4591Q_Chip1_2_Segment1_Last = SGM4591Q_Chip1_2_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip1_3:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip1_3_Segment0.UINT8 != SGM4591Q_Chip1_3_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEA, 0x02, SGM4591Q_Chip1_3_Segment0.UINT8);
        SGM4591Q_Chip1_3_Segment0_Last = SGM4591Q_Chip1_3_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip1_3_Segment1.UINT8 != SGM4591Q_Chip1_3_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEA, 0x03, SGM4591Q_Chip1_3_Segment1.UINT8);
        SGM4591Q_Chip1_3_Segment1_Last = SGM4591Q_Chip1_3_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip1_4:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip1_4_Segment0.UINT8 != SGM4591Q_Chip1_4_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEE, 0x02, SGM4591Q_Chip1_4_Segment0.UINT8);
        SGM4591Q_Chip1_4_Segment0_Last = SGM4591Q_Chip1_4_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip1_4_Segment1.UINT8 != SGM4591Q_Chip1_4_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEE, 0x03, SGM4591Q_Chip1_4_Segment1.UINT8);
        SGM4591Q_Chip1_4_Segment1_Last = SGM4591Q_Chip1_4_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip2_1:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip2_1_Segment0.UINT8 != SGM4591Q_Chip2_1_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xE8, 0x02, SGM4591Q_Chip2_1_Segment0.UINT8);
        SGM4591Q_Chip2_1_Segment0_Last = SGM4591Q_Chip2_1_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip2_1_Segment1.UINT8 != SGM4591Q_Chip2_1_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xE8, 0x03, SGM4591Q_Chip2_1_Segment1.UINT8);
        SGM4591Q_Chip2_1_Segment1_Last = SGM4591Q_Chip2_1_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip2_2:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip2_2_Segment0.UINT8 != SGM4591Q_Chip2_2_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEC, 0x02, SGM4591Q_Chip2_2_Segment0.UINT8);
        SGM4591Q_Chip2_2_Segment0_Last = SGM4591Q_Chip2_2_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip2_2_Segment1.UINT8 != SGM4591Q_Chip2_2_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEC, 0x03, SGM4591Q_Chip2_2_Segment1.UINT8);
        SGM4591Q_Chip2_2_Segment1_Last = SGM4591Q_Chip2_2_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip2_3:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip2_3_Segment0.UINT8 != SGM4591Q_Chip2_3_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEA, 0x02, SGM4591Q_Chip2_3_Segment0.UINT8);
        SGM4591Q_Chip2_3_Segment0_Last = SGM4591Q_Chip2_3_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip2_3_Segment1.UINT8 != SGM4591Q_Chip2_3_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEA, 0x03, SGM4591Q_Chip2_3_Segment1.UINT8);
        SGM4591Q_Chip2_3_Segment1_Last = SGM4591Q_Chip2_3_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip2_4:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip1_4_Segment0.UINT8 != SGM4591Q_Chip1_4_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEE, 0x02, SGM4591Q_Chip1_4_Segment0.UINT8);
        SGM4591Q_Chip1_4_Segment0_Last = SGM4591Q_Chip1_4_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip1_4_Segment1.UINT8 != SGM4591Q_Chip1_4_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEE, 0x03, SGM4591Q_Chip1_4_Segment1.UINT8);
        SGM4591Q_Chip1_4_Segment1_Last = SGM4591Q_Chip1_4_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip3_1:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip3_1_Segment0.UINT8 != SGM4591Q_Chip3_1_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xE8, 0x02, SGM4591Q_Chip3_1_Segment0.UINT8);
        SGM4591Q_Chip3_1_Segment0_Last = SGM4591Q_Chip3_1_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip3_1_Segment1.UINT8 != SGM4591Q_Chip3_1_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xE8, 0x03, SGM4591Q_Chip3_1_Segment1.UINT8);
        SGM4591Q_Chip3_1_Segment1_Last = SGM4591Q_Chip3_1_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip3_2:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip3_2_Segment0.UINT8 != SGM4591Q_Chip3_2_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEC, 0x02, SGM4591Q_Chip3_2_Segment0.UINT8);
        SGM4591Q_Chip3_2_Segment0_Last = SGM4591Q_Chip3_2_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip3_2_Segment1.UINT8 != SGM4591Q_Chip3_2_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEC, 0x03, SGM4591Q_Chip3_2_Segment1.UINT8);
        SGM4591Q_Chip3_2_Segment1_Last = SGM4591Q_Chip3_2_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip3_3:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip3_3_Segment0.UINT8 != SGM4591Q_Chip3_3_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEA, 0x02, SGM4591Q_Chip3_3_Segment0.UINT8);
        SGM4591Q_Chip3_3_Segment0_Last = SGM4591Q_Chip3_3_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip3_3_Segment1.UINT8 != SGM4591Q_Chip3_3_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEA, 0x03, SGM4591Q_Chip3_3_Segment1.UINT8);
        SGM4591Q_Chip3_3_Segment1_Last = SGM4591Q_Chip3_3_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip3_4:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip1_4_Segment0.UINT8 != SGM4591Q_Chip1_4_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEE, 0x02, SGM4591Q_Chip1_4_Segment0.UINT8);
        SGM4591Q_Chip1_4_Segment0_Last = SGM4591Q_Chip1_4_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip1_4_Segment1.UINT8 != SGM4591Q_Chip1_4_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEE, 0x03, SGM4591Q_Chip1_4_Segment1.UINT8);
        SGM4591Q_Chip1_4_Segment1_Last = SGM4591Q_Chip1_4_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip4_1:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip4_1_Segment0.UINT8 != SGM4591Q_Chip4_1_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xE8, 0x02, SGM4591Q_Chip4_1_Segment0.UINT8);
        SGM4591Q_Chip4_1_Segment0_Last = SGM4591Q_Chip4_1_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip4_1_Segment1.UINT8 != SGM4591Q_Chip4_1_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xE8, 0x03, SGM4591Q_Chip4_1_Segment1.UINT8);
        SGM4591Q_Chip4_1_Segment1_Last = SGM4591Q_Chip4_1_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip4_2:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip4_2_Segment0.UINT8 != SGM4591Q_Chip4_2_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEC, 0x02, SGM4591Q_Chip4_2_Segment0.UINT8);
        SGM4591Q_Chip4_2_Segment0_Last = SGM4591Q_Chip4_2_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip4_2_Segment1.UINT8 != SGM4591Q_Chip4_2_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEC, 0x03, SGM4591Q_Chip4_2_Segment1.UINT8);
        SGM4591Q_Chip4_2_Segment1_Last = SGM4591Q_Chip4_2_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip4_3:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip4_3_Segment0.UINT8 != SGM4591Q_Chip4_3_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEA, 0x02, SGM4591Q_Chip4_3_Segment0.UINT8);
        SGM4591Q_Chip4_3_Segment0_Last = SGM4591Q_Chip4_3_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip4_3_Segment1.UINT8 != SGM4591Q_Chip4_3_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEA, 0x03, SGM4591Q_Chip4_3_Segment1.UINT8);
        SGM4591Q_Chip4_3_Segment1_Last = SGM4591Q_Chip4_3_Segment1.UINT8;
      }
    }

    break;
  case SGM4591Q_Chip4_4:
    if (Segment == SGM4591Q_Segment0)
    {
      if (SGM4591Q_Chip1_4_Segment0.UINT8 != SGM4591Q_Chip1_4_Segment0_Last)
      {
        SGM4591Q_IIC2_Send(0xEE, 0x02, SGM4591Q_Chip1_4_Segment0.UINT8);
        SGM4591Q_Chip1_4_Segment0_Last = SGM4591Q_Chip1_4_Segment0.UINT8;
      }
    }
    else
    {
      if (SGM4591Q_Chip1_4_Segment1.UINT8 != SGM4591Q_Chip1_4_Segment1_Last)
      {
        SGM4591Q_IIC2_Send(0xEE, 0x03, SGM4591Q_Chip1_4_Segment1.UINT8);
        SGM4591Q_Chip1_4_Segment1_Last = SGM4591Q_Chip1_4_Segment1.UINT8;
      }
    }

    break;

  default:
    break;
  }
}
