Exemple #1
0
/**
  * @brief  Configures the touch Screen Controller (Single point detection)
  * @param  None
  * @retval IOE_OK if all initializations are OK. Other value if error.
  */
uint8_t IOE_TS_Config(void)
{
  uint8_t tmp = 0;

  /* Enable TSC Fct: already done in IOE_Config */
  tmp = I2C_ReadDeviceRegister(IOE_1_ADDR, IOE_REG_SYS_CTRL2);
  tmp &= ~(uint32_t)(IOE_TS_FCT | IOE_ADC_FCT);
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_SYS_CTRL2, tmp);

  /* Enable the TSC gloabl interrupts */
  tmp = I2C_ReadDeviceRegister(IOE_1_ADDR, IOE_REG_INT_EN);
  tmp |= (uint32_t)(IOE_GIT_TOUCH | IOE_GIT_FTH | IOE_GIT_FOV);
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_INT_EN, tmp);

  /* Select Sample Time, bit number and ADC Reference */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_ADC_CTRL1, 0x49);

  /* Wait for ~20 ms */
  _delay_(2);

  /* Select the ADC clock speed: 3.25 MHz */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_ADC_CTRL2, 0x01);

  /* Select TSC pins in non default mode */
  tmp = I2C_ReadDeviceRegister(IOE_1_ADDR, IOE_REG_GPIO_AF);
  tmp &= ~(uint8_t)TOUCH_IO_ALL;
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_GPIO_AF, tmp);

  /* Select 2 nF filter capacitor */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_TSC_CFG, 0x9A);

  /* Select single point reading  */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_FIFO_TH, 0x01);

  /* Write 0x01 to clear the FIFO memory content. */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_FIFO_STA, 0x01);

  /* Write 0x00 to put the FIFO back into operation mode  */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_FIFO_STA, 0x00);

  /* set the data format for Z value: 7 fractional part and 1 whole part */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_TSC_FRACT_XYZ, 0x01);

  /* set the driving capability of the device for TSC pins: 50mA */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_TSC_I_DRIVE, 0x01);

  /* Use no tracking index, touchscreen controller operation mode (XYZ) and
     enable the TSC */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_TSC_CTRL, 0x01);

  /*  Clear all the status pending bits */
  I2C_WriteDeviceRegister(IOE_1_ADDR, IOE_REG_INT_STA, 0xFF);

  /* Initialize the TS structure to their default values */
  TS_State.TouchDetected = TS_State.X = TS_State.Y = TS_State.Z = 0;

  /* All configuration done */
  return IOE_OK;
}
Exemple #2
0
/**
  * @brief  Clear the LCD
  * @param  None
  * @retval None
  */
void LCD_Clear(void)
{
  LCD_SendByte(COMMAND_TYPE, DISPLAY_CLR); /* Clear the LCD */

  /* Delay required to complete LCD clear command */
  _delay_(0x4000); /* 1ms _delay_ using Fcpu = 16Mhz*/

}
Exemple #3
0
/**
  * @brief  Power on the LCD.
  * @param  None
  * @retval None
  */
void LCD_PowerOn(void)
{
/* Power On sequence ---------------------------------------------------------*/
  LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
  LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude*/
  _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
  LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
  LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R7, 0x0173);  /* 262K color and display ON */
}
Exemple #4
0
/**
  * @brief  Initialize the LCD
  * @param  None
  * @retval None
  */
void STM8_EVAL_LCD_Init(void)
{
  /* Enable SPI clock */
  CLK_PeripheralClockConfig(LCD_SPI_CLK, ENABLE);

  /* Configure SPI pins: SCK and MOSI */
  GPIO_Init(LCD_SPI_GPIO_PORT, LCD_SPI_SCK_PIN | LCD_SPI_MOSI_PIN, GPIO_Mode_Out_PP_Low_Fast);

#ifdef USE_STM8L1528_EVAL
  /* SPI2 pin remap on Port I*/
  SYSCFG_REMAPPinConfig(REMAP_Pin_SPI2Full, ENABLE);
#endif /* USE_STM8L1528_EVAL */

  /* Initialize SPI */
  SPI_Init(LCD_SPI, SPI_FirstBit_MSB, SPI_BaudRatePrescaler_64, SPI_Mode_Master,
           SPI_CPOL_High, SPI_CPHA_2Edge,  SPI_Direction_1Line_Tx, SPI_NSS_Soft, 0x07);
  SPI_Cmd(LCD_SPI, ENABLE);

  /* Required to ensure proper LCD display when the board is powered-on ... */
  _delay_(0x4000); /* 1ms _delay_ using Fcpu = 16Mhz*/

  /* Configure LCD ChipSelect pin (NCS) in Output push-pull mode */
  GPIO_Init(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, GPIO_Mode_Out_PP_Low_Fast);


  /* Set the LCD in TEXT mode */
  LCD_SendByte(COMMAND_TYPE, SET_TEXT_MODE);

  /* Enable the display */
  LCD_SendByte(COMMAND_TYPE, DISPLAY_ON);

  /* Clear the LCD */
  LCD_SendByte(COMMAND_TYPE, DISPLAY_CLR);

  /* Delay required to complete LCD clear command */
  _delay_(0x4000); /* 1ms _delay_ using Fcpu = 16Mhz*/

  /* Select the entry mode type */
  LCD_SendByte(COMMAND_TYPE, ENTRY_MODE_SET_INC);
}
Exemple #5
0
/**
  * @brief  Resets the IO Expander by Software (SYS_CTRL1, RESET bit).
  * @param  DeviceAddr: The address of the IOExpander, could be : IOE_1_ADDR
  *         or IOE_2_ADDR.
  * @retval IOE_OK: if all initializations are OK. Other value if error.
  */
uint8_t IOE_Reset(uint8_t DeviceAddr)
{
  /* Power Down the IO_Expander */
  I2C_WriteDeviceRegister(DeviceAddr, IOE_REG_SYS_CTRL1, 0x02);

  /* wait for a delay to insure registers erasing */
  _delay_(2);

  /* Power On the Codec after the power off => all registers are reinitialized*/
  I2C_WriteDeviceRegister(DeviceAddr, IOE_REG_SYS_CTRL1, 0x00);

  /* If all OK return IOE_OK */
  return IOE_OK;
}
/**
  * @brief  Configures the touch Panel Controller (Single point detection)
  * @param  None
  * @retval IOE_OK if all initializations are OK. Other value if error.
  */
uint8_t IOE_TP_Config(void)
{ 
  /* Enable touch Panel functionality */
  IOE_FnctCmd(IOE_TP_FCT, ENABLE);
  
  /* Select Sample Time, bit number and ADC Reference */
  I2C_WriteDeviceRegister(IOE_REG_ADC_CTRL1, 0x49);
  
  /* Wait for ~20 ms */
  _delay_(2);  
  
  /* Select the ADC clock speed: 3.25 MHz */
  I2C_WriteDeviceRegister(IOE_REG_ADC_CTRL2, 0x01);
  
  /* Select TSC pins in non default mode */  
  IOE_IOAFConfig((uint8_t)TOUCH_IO_ALL, DISABLE);
  
  /* Select 2 nF filter capacitor */
  I2C_WriteDeviceRegister(IOE_REG_TP_CFG, 0x9A);   
  
  /* Select single point reading  */
  I2C_WriteDeviceRegister(IOE_REG_FIFO_TH, 0x01);
  
  /* Write 0x01 to clear the FIFO memory content. */
  I2C_WriteDeviceRegister(IOE_REG_FIFO_STA, 0x01);
  
  /* Write 0x00 to put the FIFO back into operation mode  */
  I2C_WriteDeviceRegister(IOE_REG_FIFO_STA, 0x00);
  
  /* set the data format for Z value: 7 fractional part and 1 whole part */
  I2C_WriteDeviceRegister(IOE_REG_TP_FRACT_XYZ, 0x01);
  
  /* set the driving capability of the device for TSC pins: 50mA */
  I2C_WriteDeviceRegister(IOE_REG_TP_I_DRIVE, 0x01);
  
  /* Use no tracking index, touch-panel controller operation mode (XYZ) and 
     enable the TSC */
  I2C_WriteDeviceRegister(IOE_REG_TP_CTRL, 0x03);
  
  /*  Clear all the status pending bits */
  I2C_WriteDeviceRegister(IOE_REG_INT_STA, 0xFF); 
  
  /* Initialize the TS structure to their default values */ 
  TP_State.TouchDetected = TP_State.X = TP_State.Y = TP_State.Z = 0;
  
  /* All configuration done */
  return IOE_OK;  
}
Exemple #7
0
/**
  * @brief  Display a string in rolling mode
  * @param  Line : line used for displaying the text (LCD_LINE1 or LCD_LINE2)
  * @param  ptr : Pointer to the text to display
  * @param  speed : Rolling speed
  * @retval
  * None
  */
void LCD_RollString(uint8_t Line, uint8_t *ptr, uint16_t speed)
{

  uint8_t CharPos = 0;
  uint8_t *ptr2;

  /* Set cursor position at beginning of line */
  LCD_SendByte(COMMAND_TYPE, Line);

  ptr2 = ptr;

  /* Display each character of the string */
  while (*ptr2 != 0)
  {
    if (*ptr != 0)
    {
      LCD_SendByte(DATA_TYPE, *ptr);
      ptr++;
    }
    else
    {
      LCD_SendByte(DATA_TYPE, ' ');
    }

    CharPos++;

    if (CharPos == LCD_LINE_MAX_CHAR)
    {
      _delay_(speed);

      /* Select the line to be cleared */
      LCD_SendByte(COMMAND_TYPE, Line);

      /* Clear the selected line */
      for (CharPos = 0; CharPos < LCD_LINE_MAX_CHAR; CharPos++)
      {
        LCD_SendByte(DATA_TYPE, ' ');
      }
      LCD_SendByte(COMMAND_TYPE, Line);
      CharPos = 0;
      ptr2++;
      ptr = ptr2;
    }
  }
}
Exemple #8
0
/**
  * @brief  Send a byte to LCD
  * @param  DataType Type of Data to be sent
  * @param  DataToSend Data to be sent
  * @retval None
  */
void LCD_SendByte(uint8_t DataType, uint8_t DataToSend)
{
  /* Enable access to LCD */
  LCD_NCS_HIGH();

  /* Send Synchro/Mode byte */
  LCD_SPISendByte(DataType);

  /* Send byte high nibble */
  LCD_SPISendByte((uint8_t)(DataToSend & (uint8_t)0xF0));

  /* Send byte low nibble */
  LCD_SPISendByte((uint8_t)((uint8_t)(DataToSend << 4) & (uint8_t)0xF0));
  _delay_(80);

  /* Disable access to LCD */
  LCD_NCS_LOW();
}
/**
  * @brief  Setups the LCD.
  * @param  None
  * @retval None
  */
void LCD_Setup(void)
{
/* Configure the LCD Control pins --------------------------------------------*/
  LCD_CtrlLinesConfig();
  
/* Configure the LCD_SPI interface ----------------------------------------------*/
  LCD_SPIConfig();
  
  if(LCDType == LCD_ILI9320)
  {
    _delay_(5); /* Delay 50 ms */
    /* Start Initial Sequence ------------------------------------------------*/
    LCD_WriteReg(LCD_REG_229, 0x8000); /* Set the internal vcore voltage */
    LCD_WriteReg(LCD_REG_0,  0x0001); /* Start internal OSC. */
    LCD_WriteReg(LCD_REG_1,  0x0100); /* set SS and SM bit */
    LCD_WriteReg(LCD_REG_2,  0x0700); /* set 1 line inversion */
    LCD_WriteReg(LCD_REG_3,  0x1030); /* set GRAM write direction and BGR=1. */
    LCD_WriteReg(LCD_REG_4,  0x0000); /* Resize register */
    LCD_WriteReg(LCD_REG_8,  0x0202); /* set the back porch and front porch */
    LCD_WriteReg(LCD_REG_9,  0x0000); /* set non-display area refresh cycle ISC[3:0] */
    LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
    LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
    LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
    LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
    /* Power On sequence -----------------------------------------------------*/
    LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
    LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
    LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
    _delay_(20);                      /* Dis-charge capacitor power voltage (200ms) */
    LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
    _delay_(5);                       /* Delay 50 ms */
    LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
    _delay_(5);                       /* Delay 50 ms */
    LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
    LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
    _delay_(5);                       /* Delay 50 ms */
    LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
    LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
    /* Adjust the Gamma Curve ------------------------------------------------*/
    LCD_WriteReg(LCD_REG_48, 0x0006);
    LCD_WriteReg(LCD_REG_49, 0x0101);
    LCD_WriteReg(LCD_REG_50, 0x0003);
    LCD_WriteReg(LCD_REG_53, 0x0106);
    LCD_WriteReg(LCD_REG_54, 0x0b02);
    LCD_WriteReg(LCD_REG_55, 0x0302);
    LCD_WriteReg(LCD_REG_56, 0x0707);
    LCD_WriteReg(LCD_REG_57, 0x0007);
    LCD_WriteReg(LCD_REG_60, 0x0600);
    LCD_WriteReg(LCD_REG_61, 0x020b);
  
    /* Set GRAM area ---------------------------------------------------------*/
    LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
    LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
    LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
    LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
    LCD_WriteReg(LCD_REG_96,  0x2700); /* Gate Scan Line */
    LCD_WriteReg(LCD_REG_97,  0x0001); /* NDL,VLE, REV */
    LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
    /* Partial Display Control -----------------------------------------------*/
    LCD_WriteReg(LCD_REG_128, 0x0000);
    LCD_WriteReg(LCD_REG_129, 0x0000);
    LCD_WriteReg(LCD_REG_130, 0x0000);
    LCD_WriteReg(LCD_REG_131, 0x0000);
    LCD_WriteReg(LCD_REG_132, 0x0000);
    LCD_WriteReg(LCD_REG_133, 0x0000);
    /* Panel Control ---------------------------------------------------------*/
    LCD_WriteReg(LCD_REG_144, 0x0010);
    LCD_WriteReg(LCD_REG_146, 0x0000);
    LCD_WriteReg(LCD_REG_147, 0x0003);
    LCD_WriteReg(LCD_REG_149, 0x0110);
    LCD_WriteReg(LCD_REG_151, 0x0000);
    LCD_WriteReg(LCD_REG_152, 0x0000);
    /* Set GRAM write direction and BGR = 1 */
    /* I/D=01 (Horizontal : increment, Vertical : decrement) */
    /* AM=1 (address is updated in vertical writing direction) */
    LCD_WriteReg(LCD_REG_3, 0x1018);
    LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
  }
  else if(LCDType == LCD_SPFD5408)
  {   
    /* Start Initial Sequence --------------------------------------------------*/
    LCD_WriteReg(LCD_REG_227, 0x3008); /* Set internal timing */
    LCD_WriteReg(LCD_REG_231, 0x0012); /* Set internal timing */
    LCD_WriteReg(LCD_REG_239, 0x1231); /* Set internal timing */
    LCD_WriteReg(LCD_REG_1, 0x0100);   /* Set SS and SM bit */
    LCD_WriteReg(LCD_REG_2, 0x0700);   /* Set 1 line inversion */
    LCD_WriteReg(LCD_REG_3, 0x1030);   /* Set GRAM write direction and BGR=1. */
    LCD_WriteReg(LCD_REG_4, 0x0000);   /* Resize register */
    LCD_WriteReg(LCD_REG_8, 0x0202);   /* Set the back porch and front porch */
    LCD_WriteReg(LCD_REG_9, 0x0000);   /* Set non-display area refresh cycle ISC[3:0] */
    LCD_WriteReg(LCD_REG_10, 0x0000);  /* FMARK function */
    LCD_WriteReg(LCD_REG_12, 0x0000);  /* RGB interface setting */
    LCD_WriteReg(LCD_REG_13, 0x0000);  /* Frame marker Position */
    LCD_WriteReg(LCD_REG_15, 0x0000);  /* RGB interface polarity */
    /* Power On sequence -------------------------------------------------------*/
    LCD_WriteReg(LCD_REG_16, 0x0000);  /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    LCD_WriteReg(LCD_REG_17, 0x0000);  /* DC1[2:0], DC0[2:0], VC[2:0] */
    LCD_WriteReg(LCD_REG_18, 0x0000);  /* VREG1OUT voltage */
    LCD_WriteReg(LCD_REG_19, 0x0000);  /* VDV[4:0] for VCOM amplitude */
    _delay_(20);                /* Dis-charge capacitor power voltage (200ms) */  
    LCD_WriteReg(LCD_REG_17, 0x0007);  /* DC1[2:0], DC0[2:0], VC[2:0] */
    _delay_(5);                 /* Delay 50 ms */
    LCD_WriteReg(LCD_REG_16, 0x12B0);  /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    _delay_(5);                  /* Delay 50 ms */
    LCD_WriteReg(LCD_REG_18, 0x01BD);  /* External reference voltage= Vci */
    _delay_(5);                 /* Delay 50 ms */ 
    LCD_WriteReg(LCD_REG_19, 0x1400);       /* VDV[4:0] for VCOM amplitude */
    LCD_WriteReg(LCD_REG_41, 0x000E);  /* VCM[4:0] for VCOMH */
    _delay_(5);                 /* Delay 50 ms */
    LCD_WriteReg(LCD_REG_32, 0x0000);  /* GRAM horizontal Address */
    LCD_WriteReg(LCD_REG_33, 0x013F);  /* GRAM Vertical Address */
    /* Adjust the Gamma Curve --------------------------------------------------*/
    LCD_WriteReg(LCD_REG_48, 0x0007);
    LCD_WriteReg(LCD_REG_49, 0x0302);
    LCD_WriteReg(LCD_REG_50, 0x0105);
    LCD_WriteReg(LCD_REG_53, 0x0206);
    LCD_WriteReg(LCD_REG_54, 0x0808);
    LCD_WriteReg(LCD_REG_55, 0x0206);
    LCD_WriteReg(LCD_REG_56, 0x0504);
    LCD_WriteReg(LCD_REG_57, 0x0007);
    LCD_WriteReg(LCD_REG_60, 0x0105);
    LCD_WriteReg(LCD_REG_61, 0x0808);
    /* Set GRAM area -----------------------------------------------------------*/
    LCD_WriteReg(LCD_REG_80, 0x0000);  /* Horizontal GRAM Start Address */
    LCD_WriteReg(LCD_REG_81, 0x00EF);  /* Horizontal GRAM End Address */
    LCD_WriteReg(LCD_REG_82, 0x0000);  /* Vertical GRAM Start Address */
    LCD_WriteReg(LCD_REG_83, 0x013F);  /* Vertical GRAM End Address */
    LCD_WriteReg(LCD_REG_96,  0xA700); /* Gate Scan Line */
    LCD_WriteReg(LCD_REG_97,  0x0001); /* NDL,VLE, REV */
    LCD_WriteReg(LCD_REG_106, 0x0000); /* Set scrolling line */
    /* Partial Display Control -------------------------------------------------*/
    LCD_WriteReg(LCD_REG_128, 0x0000);
    LCD_WriteReg(LCD_REG_129, 0x0000);
    LCD_WriteReg(LCD_REG_130, 0x0000);
    LCD_WriteReg(LCD_REG_131, 0x0000);
    LCD_WriteReg(LCD_REG_132, 0x0000);
    LCD_WriteReg(LCD_REG_133, 0x0000);
    /* Panel Control -----------------------------------------------------------*/
    LCD_WriteReg(LCD_REG_144, 0x0010);
    LCD_WriteReg(LCD_REG_146, 0x0000);
    LCD_WriteReg(LCD_REG_147, 0x0003);
    LCD_WriteReg(LCD_REG_149, 0x0110);
    LCD_WriteReg(LCD_REG_151, 0x0000);
    LCD_WriteReg(LCD_REG_152, 0x0000);
    /* Set GRAM write direction and BGR = 1
       I/D=01 (Horizontal : increment, Vertical : decrement)
       AM=1 (address is updated in vertical writing direction) */
    LCD_WriteReg(LCD_REG_3, 0x1018);
    LCD_WriteReg(LCD_REG_7, 0x0112);   /* 262K color and display ON */
  } 
  else if(LCDType == LCD_HX8347D)
  {
    /* Driving ability setting */
    LCD_WriteReg(LCD_REG_234, 0x00);
    LCD_WriteReg(LCD_REG_235, 0x20);
    LCD_WriteReg(LCD_REG_236, 0x0C);
    LCD_WriteReg(LCD_REG_237, 0xC4);
    LCD_WriteReg(LCD_REG_232, 0x40);
    LCD_WriteReg(LCD_REG_233, 0x38);
    LCD_WriteReg(LCD_REG_241, 0x01);
    LCD_WriteReg(LCD_REG_242, 0x10);
    LCD_WriteReg(LCD_REG_39, 0xA3);

    /* Adjust the Gamma Curve */
    LCD_WriteReg(LCD_REG_64, 0x01);
    LCD_WriteReg(LCD_REG_65, 0x00);
    LCD_WriteReg(LCD_REG_66, 0x00);
    LCD_WriteReg(LCD_REG_67, 0x10);
    LCD_WriteReg(LCD_REG_68, 0x0E);
    LCD_WriteReg(LCD_REG_69, 0x24);
    LCD_WriteReg(LCD_REG_70, 0x04);
    LCD_WriteReg(LCD_REG_71, 0x50);
    LCD_WriteReg(LCD_REG_72, 0x02);
    LCD_WriteReg(LCD_REG_73, 0x13);
    LCD_WriteReg(LCD_REG_74, 0x19);
    LCD_WriteReg(LCD_REG_75, 0x19);
    LCD_WriteReg(LCD_REG_76, 0x16);
    LCD_WriteReg(LCD_REG_80, 0x1B);
    LCD_WriteReg(LCD_REG_81, 0x31);
    LCD_WriteReg(LCD_REG_82, 0x2F);
    LCD_WriteReg(LCD_REG_83, 0x3F);
    LCD_WriteReg(LCD_REG_84, 0x3F);
    LCD_WriteReg(LCD_REG_85, 0x3E);
    LCD_WriteReg(LCD_REG_86, 0x2F);
    LCD_WriteReg(LCD_REG_87, 0x7B);
    LCD_WriteReg(LCD_REG_88, 0x09);
    LCD_WriteReg(LCD_REG_89, 0x06);
    LCD_WriteReg(LCD_REG_90, 0x06);
    LCD_WriteReg(LCD_REG_91, 0x0C);
    LCD_WriteReg(LCD_REG_92, 0x1D);
    LCD_WriteReg(LCD_REG_93, 0xCC);

    /* Power voltage setting */
    LCD_WriteReg(LCD_REG_27, 0x1B);
    LCD_WriteReg(LCD_REG_26, 0x01);
    LCD_WriteReg(LCD_REG_36, 0x2F);
    LCD_WriteReg(LCD_REG_37, 0x57);
    /*****VCOM offset ****/
    LCD_WriteReg(LCD_REG_35, 0x86);

    /* Power on setting up flow */
    LCD_WriteReg(LCD_REG_24, 0x36); /* Display frame rate = 70Hz RADJ = '0110' */
    LCD_WriteReg(LCD_REG_25, 0x01); /* OSC_EN = 1 */
    LCD_WriteReg(LCD_REG_28, 0x06); /* AP[2:0] = 111 */
    LCD_WriteReg(LCD_REG_29, 0x06); /* AP[2:0] = 111 */
    LCD_WriteReg(LCD_REG_31,0x90); /* GAS=1, VOMG=00, PON=1, DK=0, XDK=0, DVDH_TRI=0, STB=0*/
    LCD_WriteReg(LCD_REG_39, 1); /* REF = 1 */
    _delay_(10);

    /* 262k/65k color selection */
    LCD_WriteReg(LCD_REG_23, 0x05); /* default 0x06 262k color,  0x05 65k color */
    /* SET PANEL */
    LCD_WriteReg(LCD_REG_54, 0x09); /* SS_PANEL = 1, GS_PANEL = 0,REV_PANEL = 0, BGR_PANEL = 1 */

    /* Display ON flow */
    LCD_WriteReg(LCD_REG_40, 0x38); /* GON=1, DTE=1, D=10 */
    _delay_(60);
    LCD_WriteReg(LCD_REG_40, 0x3C); /* GON=1, DTE=1, D=11 */

    /* Set GRAM Area - Partial Display Control */
    LCD_WriteReg(LCD_REG_1, 0x00); /* DP_STB = 0, DP_STB_S = 0, SCROLL = 0, */
    LCD_WriteReg(LCD_REG_2, 0x00); /* Column address start 2 */
    LCD_WriteReg(LCD_REG_3, 0x00); /* Column address start 1 */
    LCD_WriteReg(LCD_REG_4, 0x01); /* Column address end 2 */
    LCD_WriteReg(LCD_REG_5, 0x3F); /* Column address end 1 */
    LCD_WriteReg(LCD_REG_6, 0x00); /* Row address start 2 */
    LCD_WriteReg(LCD_REG_7, 0x00); /* Row address start 2 */
    LCD_WriteReg(LCD_REG_8, 0x00); /* Row address end 2 */
    LCD_WriteReg(LCD_REG_9, 0xEF); /* Row address end 1 */
    LCD_WriteReg(LCD_REG_22, 0xE0); /* Memory access control: MY = 1, MX = 0, MV = 1, ML = 0 */
  } 
  /* Set default font */    
  LCD_SetFont(&LCD_DEFAULT_FONT);
}
/**
  * @brief  Setup the LCD for the HX8347D Controller.
  * @param  None
  * @retval None
  */
void LCD_Setup(void)
{ 
    /* Driving ability setting */
    LCD_WriteReg(LCD_REG_234, 0x00);
    LCD_WriteReg(LCD_REG_235, 0x20);
    LCD_WriteReg(LCD_REG_236, 0x0C);
    LCD_WriteReg(LCD_REG_237, 0xC4);
    LCD_WriteReg(LCD_REG_232, 0x40);
    LCD_WriteReg(LCD_REG_233, 0x38);
    LCD_WriteReg(LCD_REG_241, 0x01); /* RGB 18-bit interface ;0x0110 */
    LCD_WriteReg(LCD_REG_242, 0x10);
    LCD_WriteReg(LCD_REG_39, 0xA3);

    /* Adjust the Gamma Curve */
    LCD_WriteReg(LCD_REG_64, 0x01);
    LCD_WriteReg(LCD_REG_65, 0x00);
    LCD_WriteReg(LCD_REG_66, 0x00);
    LCD_WriteReg(LCD_REG_67, 0x10);
    LCD_WriteReg(LCD_REG_68, 0x0E);
    LCD_WriteReg(LCD_REG_69, 0x24);
    LCD_WriteReg(LCD_REG_70, 0x04);
    LCD_WriteReg(LCD_REG_71, 0x50);
    LCD_WriteReg(LCD_REG_72, 0x02);
    LCD_WriteReg(LCD_REG_73, 0x13);
    LCD_WriteReg(LCD_REG_74, 0x19);
    LCD_WriteReg(LCD_REG_75, 0x19);
    LCD_WriteReg(LCD_REG_76, 0x16);

    LCD_WriteReg(LCD_REG_80, 0x1B);
    LCD_WriteReg(LCD_REG_81, 0x31);
    LCD_WriteReg(LCD_REG_82, 0x2F);
    LCD_WriteReg(LCD_REG_83, 0x3F);
    LCD_WriteReg(LCD_REG_84, 0x3F);
    LCD_WriteReg(LCD_REG_85, 0x3E);
    LCD_WriteReg(LCD_REG_86, 0x2F);
    LCD_WriteReg(LCD_REG_87, 0x7B);
    LCD_WriteReg(LCD_REG_88, 0x09);
    LCD_WriteReg(LCD_REG_89, 0x06);
    LCD_WriteReg(LCD_REG_90, 0x06);
    LCD_WriteReg(LCD_REG_91, 0x0C);
    LCD_WriteReg(LCD_REG_92, 0x1D);
    LCD_WriteReg(LCD_REG_93, 0xCC);

    /* Power voltage setting */
    LCD_WriteReg(LCD_REG_27, 0x1B);
    LCD_WriteReg(LCD_REG_26, 0x01);
    LCD_WriteReg(LCD_REG_36, 0x2F);
    LCD_WriteReg(LCD_REG_37, 0x57);
    /*****VCOM offset ****/
    LCD_WriteReg(LCD_REG_35, 0x86);
  
    /* Power on setting */
    LCD_WriteReg(LCD_REG_24, 0x36); /* Display frame rate:75Hz(2.85MHz X 117%) */
    LCD_WriteReg(LCD_REG_25, 0x01); /* Internal oscillator start to oscillate */
    LCD_WriteReg(LCD_REG_1,0x00);
    LCD_WriteReg(LCD_REG_31, 0x88); /* Step-up Circuit 1 on,open abnormal power-off monitor */
    _delay_(2);
    LCD_WriteReg(LCD_REG_31, 0x80); /* Step-up Circuit 1 off */
    _delay_(2);
    LCD_WriteReg(LCD_REG_31, 0x90); /* VCOML voltage can output to negative voltage,
                                (1.0V ~ VCL+0.5V) */
    _delay_(2);
    LCD_WriteReg(LCD_REG_31, 0xD0); /* Step-up Circuit 2 on */
    _delay_(2);

    LCD_WriteReg(LCD_REG_23, 0x05);  /* COLMOD control */

    /* Set GRAM Area - Partial Display Control */
    LCD_WriteReg(LCD_REG_1, 0x00); /* Scroll off */

    LCD_WriteReg(LCD_REG_2, 0x00);
    LCD_WriteReg(LCD_REG_3, 0x00);
    LCD_WriteReg(LCD_REG_4, 0x01); /* X,Y swap */
    LCD_WriteReg(LCD_REG_5, 0x3F); /* X,Y swap */

    LCD_WriteReg(LCD_REG_6, 0x00);
    LCD_WriteReg(LCD_REG_7, 0x00);
    LCD_WriteReg(LCD_REG_8, 0x00); /* X,Y swap */
    LCD_WriteReg(LCD_REG_9, 0xEF); /* X,Y swap */

    /* Memory access control */
    /* bit7 controls left,right swap(X) */
    /* bit6 controls up,down swap(Y) */
    /* bit5 controls X,Y swap */
    LCD_WriteReg(LCD_REG_22, 0x28);

    /* SET PANEL */
    LCD_WriteReg(LCD_REG_54, 0x00); /* Panel characteristic control */
    LCD_WriteReg(LCD_REG_54, 0x04); /* Panel characteristic control: gate driver shift reverse[work] */
    LCD_WriteReg(LCD_REG_40, 0x38); /* Display control3: source output->PT(0,0) */
    _delay_(6);
    LCD_WriteReg(LCD_REG_40, 0x3C); /* Display control3: source output->Display */
}
/**
  * @brief  Setups the LCD.
  * @param  None
  * @retval None
  */
void LCD_Setup(void)
{ 
/* Configure the LCD Control pins --------------------------------------------*/
  LCD_CtrlLinesConfig();
  
/* Configure the LCD_SPI interface ----------------------------------------------*/
  LCD_SPIConfig();
  _delay_(5); /* Delay 50 ms */
  /* Start Initial Sequence ------------------------------------------------*/
  LCD_WriteReg(R229, 0x8000); /* Set the internal vcore voltage */
  LCD_WriteReg(R0,  0x0001); /* Start internal OSC. */
  LCD_WriteReg(R1,  0x0100); /* set SS and SM bit */
  LCD_WriteReg(R2,  0x0700); /* set 1 line inversion */
  LCD_WriteReg(R3,  0x1030); /* set GRAM write direction and BGR=1. */
  LCD_WriteReg(R4,  0x0000); /* Resize register */
  LCD_WriteReg(R8,  0x0202); /* set the back porch and front porch */
  LCD_WriteReg(R9,  0x0000); /* set non-display area refresh cycle ISC[3:0] */
  LCD_WriteReg(R10, 0x0000); /* FMARK function */
  LCD_WriteReg(R12, 0x0000); /* RGB interface setting */
  LCD_WriteReg(R13, 0x0000); /* Frame marker Position */
  LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */
  /* Power On sequence -----------------------------------------------------*/
  LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
  LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
  _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
  LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
  LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */
  LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */
  /* Adjust the Gamma Curve ------------------------------------------------*/
  LCD_WriteReg(R48, 0x0006);
  LCD_WriteReg(R49, 0x0101);
  LCD_WriteReg(R50, 0x0003);
  LCD_WriteReg(R53, 0x0106);
  LCD_WriteReg(R54, 0x0b02);
  LCD_WriteReg(R55, 0x0302);
  LCD_WriteReg(R56, 0x0707);
  LCD_WriteReg(R57, 0x0007);
  LCD_WriteReg(R60, 0x0600);
  LCD_WriteReg(R61, 0x020b);
  
  /* Set GRAM area ---------------------------------------------------------*/
  LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */
  LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */
  LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */
  LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */
  LCD_WriteReg(R96,  0x2700); /* Gate Scan Line */
  LCD_WriteReg(R97,  0x0001); /* NDL,VLE, REV */
  LCD_WriteReg(R106, 0x0000); /* set scrolling line */
  /* Partial Display Control -----------------------------------------------*/
  LCD_WriteReg(R128, 0x0000);
  LCD_WriteReg(R129, 0x0000);
  LCD_WriteReg(R130, 0x0000);
  LCD_WriteReg(R131, 0x0000);
  LCD_WriteReg(R132, 0x0000);
  LCD_WriteReg(R133, 0x0000);
  /* Panel Control ---------------------------------------------------------*/
  LCD_WriteReg(R144, 0x0010);
  LCD_WriteReg(R146, 0x0000);
  LCD_WriteReg(R147, 0x0003);
  LCD_WriteReg(R149, 0x0110);
  LCD_WriteReg(R151, 0x0000);
  LCD_WriteReg(R152, 0x0000);
  /* Set GRAM write direction and BGR = 1 */
  /* I/D=01 (Horizontal : increment, Vertical : decrement) */
  /* AM=1 (address is updated in vertical writing direction) */
  LCD_WriteReg(R3, 0x1018);
  LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
}
Exemple #12
0
/**
  * @brief  Initializes the LCD.
  * @param  None
  * @retval None
  */
void STM3210E_LCD_Init(void)
{ 
/* Configure the LCD Control pins --------------------------------------------*/
  LCD_CtrlLinesConfig();
/* Configure the FSMC Parallel interface -------------------------------------*/
  LCD_FSMCConfig();
  _delay_(5); /* delay 50 ms */
  /* Check if the LCD is SPFD5408B Controller */
  if(LCD_ReadReg(0x00) == 0x5408)
  {
    /* Start Initial Sequence ------------------------------------------------*/
    LCD_WriteReg(R1, 0x0100);  /* Set SS bit */
    LCD_WriteReg(R2, 0x0700);  /* Set 1 line inversion */
    LCD_WriteReg(R3, 0x1030);  /* Set GRAM write direction and BGR=1. */
    LCD_WriteReg(R4, 0x0000);  /* Resize register */
    LCD_WriteReg(R8, 0x0202);  /* Set the back porch and front porch */
    LCD_WriteReg(R9, 0x0000);  /* Set non-display area refresh cycle ISC[3:0] */
    LCD_WriteReg(R10, 0x0000); /* FMARK function */
    LCD_WriteReg(R12, 0x0000); /* RGB 18-bit System interface setting */
    LCD_WriteReg(R13, 0x0000); /* Frame marker Position */
    LCD_WriteReg(R15, 0x0000); /* RGB interface polarity, no impact */
    /* Power On sequence -----------------------------------------------------*/
    LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
    LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
    LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
    _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
    LCD_WriteReg(R17, 0x0007);	/* DC1[2:0], DC0[2:0], VC[2:0] */
    _delay_(5);                   /* Delay 50 ms */
    LCD_WriteReg(R16, 0x12B0);	/* SAP, BT[3:0], AP, DSTB, SLP, STB */
    _delay_(5);	                /* Delay 50 ms */
    LCD_WriteReg(R18, 0x01BD);  /* External reference voltage= Vci */
    _delay_(5); 
    LCD_WriteReg(R19, 0x1400);  /* VDV[4:0] for VCOM amplitude */
    LCD_WriteReg(R41, 0x000E);  /* VCM[4:0] for VCOMH */
    _delay_(5);                   /* Delay 50 ms */
    LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */
    LCD_WriteReg(R33, 0x013F); /* GRAM Vertical Address */
    /* Adjust the Gamma Curve (SPFD5408B)-------------------------------------*/
    LCD_WriteReg(R48, 0x0b0d);
    LCD_WriteReg(R49, 0x1923);
    LCD_WriteReg(R50, 0x1c26);
    LCD_WriteReg(R51, 0x261c);
    LCD_WriteReg(R52, 0x2419);
    LCD_WriteReg(R53, 0x0d0b);
    LCD_WriteReg(R54, 0x1006);
    LCD_WriteReg(R55, 0x0610);
    LCD_WriteReg(R56, 0x0706);
    LCD_WriteReg(R57, 0x0304);
    LCD_WriteReg(R58, 0x0e05);
    LCD_WriteReg(R59, 0x0e01);
    LCD_WriteReg(R60, 0x010e);
    LCD_WriteReg(R61, 0x050e);
    LCD_WriteReg(R62, 0x0403);
    LCD_WriteReg(R63, 0x0607);
    /* Set GRAM area ---------------------------------------------------------*/
    LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */
    LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */
    LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */
    LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */
    LCD_WriteReg(R96,  0xA700); /* Gate Scan Line */
    LCD_WriteReg(R97,  0x0001); /* NDL, VLE, REV */
    LCD_WriteReg(R106, 0x0000); /* set scrolling line */
    /* Partial Display Control -----------------------------------------------*/
    LCD_WriteReg(R128, 0x0000);
    LCD_WriteReg(R129, 0x0000);
    LCD_WriteReg(R130, 0x0000);
    LCD_WriteReg(R131, 0x0000);
    LCD_WriteReg(R132, 0x0000);
    LCD_WriteReg(R133, 0x0000);
    /* Panel Control ---------------------------------------------------------*/
    LCD_WriteReg(R144, 0x0010); 
    LCD_WriteReg(R146, 0x0000);
    LCD_WriteReg(R147, 0x0003);
    LCD_WriteReg(R149, 0x0110);
    LCD_WriteReg(R151, 0x0000);
    LCD_WriteReg(R152, 0x0000);
    /* Set GRAM write direction and BGR=1
       I/D=01 (Horizontal : increment, Vertical : decrement)
       AM=1 (address is updated in vertical writing direction) */
    LCD_WriteReg(R3, 0x1018);
    LCD_WriteReg(R7, 0x0112); /* 262K color and display ON */
    return;
  }
/* Start Initial Sequence ----------------------------------------------------*/
  LCD_WriteReg(R229,0x8000); /* Set the internal vcore voltage */
  LCD_WriteReg(R0,  0x0001); /* Start internal OSC. */
  LCD_WriteReg(R1,  0x0100); /* set SS and SM bit */
  LCD_WriteReg(R2,  0x0700); /* set 1 line inversion */
  LCD_WriteReg(R3,  0x1030); /* set GRAM write direction and BGR=1. */
  LCD_WriteReg(R4,  0x0000); /* Resize register */
  LCD_WriteReg(R8,  0x0202); /* set the back porch and front porch */
  LCD_WriteReg(R9,  0x0000); /* set non-display area refresh cycle ISC[3:0] */
  LCD_WriteReg(R10, 0x0000); /* FMARK function */
  LCD_WriteReg(R12, 0x0000); /* RGB interface setting */
  LCD_WriteReg(R13, 0x0000); /* Frame marker Position */
  LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */
/* Power On sequence ---------------------------------------------------------*/
  LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
  LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
  _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
  LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
  LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
  _delay_(5);                  /* Delay 50 ms */
  LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */
  LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */
/* Adjust the Gamma Curve ----------------------------------------------------*/
  LCD_WriteReg(R48, 0x0006);
  LCD_WriteReg(R49, 0x0101);
  LCD_WriteReg(R50, 0x0003);
  LCD_WriteReg(R53, 0x0106);
  LCD_WriteReg(R54, 0x0b02);
  LCD_WriteReg(R55, 0x0302);
  LCD_WriteReg(R56, 0x0707);
  LCD_WriteReg(R57, 0x0007);
  LCD_WriteReg(R60, 0x0600);
  LCD_WriteReg(R61, 0x020b);
  
/* Set GRAM area -------------------------------------------------------------*/
  LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */
  LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */
  LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */
  LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */
  LCD_WriteReg(R96,  0x2700); /* Gate Scan Line */
  LCD_WriteReg(R97,  0x0001); /* NDL,VLE, REV */
  LCD_WriteReg(R106, 0x0000); /* set scrolling line */
/* Partial Display Control ---------------------------------------------------*/
  LCD_WriteReg(R128, 0x0000);
  LCD_WriteReg(R129, 0x0000);
  LCD_WriteReg(R130, 0x0000);
  LCD_WriteReg(R131, 0x0000);
  LCD_WriteReg(R132, 0x0000);
  LCD_WriteReg(R133, 0x0000);
/* Panel Control -------------------------------------------------------------*/
  LCD_WriteReg(R144, 0x0010);
  LCD_WriteReg(R146, 0x0000);
  LCD_WriteReg(R147, 0x0003);
  LCD_WriteReg(R149, 0x0110);
  LCD_WriteReg(R151, 0x0000);
  LCD_WriteReg(R152, 0x0000);
  /* Set GRAM write direction and BGR = 1 */
  /* I/D=01 (Horizontal : increment, Vertical : decrement) */
  /* AM=1 (address is updated in vertical writing direction) */
  LCD_WriteReg(R3, 0x1018);
  LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */  
}
/**
  * @brief  Initializes the LCD.
  * @param  None
  * @retval None
  */
void STM3210E_LCD_Init(void)
{
	/* Configure the LCD Control pins */
	LCD_CtrlLinesConfig();

	/* Configure the FSMC Parallel interface */
	LCD_FSMCConfig();

	/* delay 50 ms */
	_delay_(5);

	/* Read the LCD ID */
	LCD_ID = LCD_ReadReg(0x00);

	/* Check if the LCD is HX8347D Controller */
	if (LCD_ID == LCD_HX8347D) {
		/* Driving ability setting */
		LCD_WriteReg(LCD_REG_234, 0x00);
		LCD_WriteReg(LCD_REG_235, 0x20);
		LCD_WriteReg(LCD_REG_236, 0x0C);
		LCD_WriteReg(LCD_REG_237, 0xC4);
		LCD_WriteReg(LCD_REG_232, 0x40);
		LCD_WriteReg(LCD_REG_233, 0x38);
		LCD_WriteReg(LCD_REG_241, 0x01);	/* RGB 18-bit interface ;0x0110 */
		LCD_WriteReg(LCD_REG_242, 0x10);
		LCD_WriteReg(LCD_REG_39, 0xA3);

		/* Adjust the Gamma Curve */
		LCD_WriteReg(LCD_REG_64, 0x01);
		LCD_WriteReg(LCD_REG_65, 0x00);
		LCD_WriteReg(LCD_REG_66, 0x00);
		LCD_WriteReg(LCD_REG_67, 0x10);
		LCD_WriteReg(LCD_REG_68, 0x0E);
		LCD_WriteReg(LCD_REG_69, 0x24);
		LCD_WriteReg(LCD_REG_70, 0x04);
		LCD_WriteReg(LCD_REG_71, 0x50);
		LCD_WriteReg(LCD_REG_72, 0x02);
		LCD_WriteReg(LCD_REG_73, 0x13);
		LCD_WriteReg(LCD_REG_74, 0x19);
		LCD_WriteReg(LCD_REG_75, 0x19);
		LCD_WriteReg(LCD_REG_76, 0x16);

		LCD_WriteReg(LCD_REG_80, 0x1B);
		LCD_WriteReg(LCD_REG_81, 0x31);
		LCD_WriteReg(LCD_REG_82, 0x2F);
		LCD_WriteReg(LCD_REG_83, 0x3F);
		LCD_WriteReg(LCD_REG_84, 0x3F);
		LCD_WriteReg(LCD_REG_85, 0x3E);
		LCD_WriteReg(LCD_REG_86, 0x2F);
		LCD_WriteReg(LCD_REG_87, 0x7B);
		LCD_WriteReg(LCD_REG_88, 0x09);
		LCD_WriteReg(LCD_REG_89, 0x06);
		LCD_WriteReg(LCD_REG_90, 0x06);
		LCD_WriteReg(LCD_REG_91, 0x0C);
		LCD_WriteReg(LCD_REG_92, 0x1D);
		LCD_WriteReg(LCD_REG_93, 0xCC);

		/* Power voltage setting */
		LCD_WriteReg(LCD_REG_27, 0x1B);
		LCD_WriteReg(LCD_REG_26, 0x01);
		LCD_WriteReg(LCD_REG_36, 0x2F);
		LCD_WriteReg(LCD_REG_37, 0x57);
    /*****VCOM offset ****/
		LCD_WriteReg(LCD_REG_35, 0x86);

		/* Power on setting */
		LCD_WriteReg(LCD_REG_24, 0x36);	/* Display frame rate:75Hz(2.85MHz X 117%) */
		LCD_WriteReg(LCD_REG_25, 0x01);	/* Internal oscillator start to oscillate */
		LCD_WriteReg(LCD_REG_1, 0x00);
		LCD_WriteReg(LCD_REG_31, 0x88);	/* Step-up Circuit 1 on,open abnormal power-off monitor */
		_delay_(6);
		LCD_WriteReg(LCD_REG_31, 0x80);	/* Step-up Circuit 1 off */
		_delay_(6);
		LCD_WriteReg(LCD_REG_31, 0x90);	/* VCOML voltage can output to negative voltage,
						   (1.0V ~ VCL+0.5V) */
		_delay_(6);
		LCD_WriteReg(LCD_REG_31, 0xD0);	/* Step-up Circuit 2 on */
		_delay_(6);

		LCD_WriteReg(LCD_REG_23, 0x05);	/* COLMOD control */

		/* Set GRAM Area - Partial Display Control */
		LCD_WriteReg(LCD_REG_1, 0x00);	/* Scroll off */

		LCD_WriteReg(LCD_REG_2, 0x00);
		LCD_WriteReg(LCD_REG_3, 0x00);
		LCD_WriteReg(LCD_REG_4, 0x01);	/* X,Y swap */
		LCD_WriteReg(LCD_REG_5, 0x3F);	/* X,Y swap */

		LCD_WriteReg(LCD_REG_6, 0x00);
		LCD_WriteReg(LCD_REG_7, 0x00);
		LCD_WriteReg(LCD_REG_8, 0x00);	/* X,Y swap */
		LCD_WriteReg(LCD_REG_9, 0xEF);	/* X,Y swap */

		/* Memory access control */
		/* bit7 controls left,right swap(X) */
		/* bit6 controls up,down swap(Y) */
		/* bit5 controls X,Y swap */
		LCD_WriteReg(LCD_REG_22, 0x28);

		/* SET PANEL */
		LCD_WriteReg(LCD_REG_54, 0x00);	/* Panel characteristic control */
		LCD_WriteReg(LCD_REG_54, 0x04);	/* Panel characteristic control: gate driver shift reverse[work] */
		LCD_WriteReg(LCD_REG_40, 0x38);	/* Display control3: source output->PT(0,0) */
		_delay_(20);
		LCD_WriteReg(LCD_REG_40, 0x3C);	/* Display control3: source output->Display */
	} else {
		/* Check if the LCD is SPFD5408B Controller */
		if (LCD_ReadReg(0x00) == 0x5408) {
			/* Start Initial Sequence ------------------------------------------------ */
			LCD_WriteReg(LCD_REG_1, 0x0100);	/* Set SS bit */
			LCD_WriteReg(LCD_REG_2, 0x0700);	/* Set 1 line inversion */
			LCD_WriteReg(LCD_REG_3, 0x1030);	/* Set GRAM write direction and BGR=1. */
			LCD_WriteReg(LCD_REG_4, 0x0000);	/* Resize register */
			LCD_WriteReg(LCD_REG_8, 0x0202);	/* Set the back porch and front porch */
			LCD_WriteReg(LCD_REG_9, 0x0000);	/* Set non-display area refresh cycle ISC[3:0] */
			LCD_WriteReg(LCD_REG_10, 0x0000);	/* FMARK function */
			LCD_WriteReg(LCD_REG_12, 0x0000);	/* RGB 18-bit System interface setting */
			LCD_WriteReg(LCD_REG_13, 0x0000);	/* Frame marker Position */
			LCD_WriteReg(LCD_REG_15, 0x0000);	/* RGB interface polarity, no impact */
			/* Power On sequence ----------------------------------------------------- */
			LCD_WriteReg(LCD_REG_16, 0x0000);	/* SAP, BT[3:0], AP, DSTB, SLP, STB */
			LCD_WriteReg(LCD_REG_17, 0x0000);	/* DC1[2:0], DC0[2:0], VC[2:0] */
			LCD_WriteReg(LCD_REG_18, 0x0000);	/* VREG1OUT voltage */
			LCD_WriteReg(LCD_REG_19, 0x0000);	/* VDV[4:0] for VCOM amplitude */
			_delay_(60);	/* Dis-charge capacitor power voltage (200ms) */
			LCD_WriteReg(LCD_REG_17, 0x0007);	/* DC1[2:0], DC0[2:0], VC[2:0] */
			_delay_(20);	/* Delay 50 ms */
			LCD_WriteReg(LCD_REG_16, 0x12B0);	/* SAP, BT[3:0], AP, DSTB, SLP, STB */
			_delay_(20);	/* Delay 50 ms */
			LCD_WriteReg(LCD_REG_18, 0x01BD);	/* External reference voltage= Vci */
			_delay_(20);
			LCD_WriteReg(LCD_REG_19, 0x1400);	/* VDV[4:0] for VCOM amplitude */
			LCD_WriteReg(LCD_REG_41, 0x000E);	/* VCM[4:0] for VCOMH */
			_delay_(20);	/* Delay 50 ms */
			LCD_WriteReg(LCD_REG_32, 0x0000);	/* GRAM horizontal Address */
			LCD_WriteReg(LCD_REG_33, 0x013F);	/* GRAM Vertical Address */
			/* Adjust the Gamma Curve (SPFD5408B)------------------------------------- */
			LCD_WriteReg(LCD_REG_48, 0x0b0d);
			LCD_WriteReg(LCD_REG_49, 0x1923);
			LCD_WriteReg(LCD_REG_50, 0x1c26);
			LCD_WriteReg(LCD_REG_51, 0x261c);
			LCD_WriteReg(LCD_REG_52, 0x2419);
			LCD_WriteReg(LCD_REG_53, 0x0d0b);
			LCD_WriteReg(LCD_REG_54, 0x1006);
			LCD_WriteReg(LCD_REG_55, 0x0610);
			LCD_WriteReg(LCD_REG_56, 0x0706);
			LCD_WriteReg(LCD_REG_57, 0x0304);
			LCD_WriteReg(LCD_REG_58, 0x0e05);
			LCD_WriteReg(LCD_REG_59, 0x0e01);
			LCD_WriteReg(LCD_REG_60, 0x010e);
			LCD_WriteReg(LCD_REG_61, 0x050e);
			LCD_WriteReg(LCD_REG_62, 0x0403);
			LCD_WriteReg(LCD_REG_63, 0x0607);
			/* Set GRAM area --------------------------------------------------------- */
			LCD_WriteReg(LCD_REG_80, 0x0000);	/* Horizontal GRAM Start Address */
			LCD_WriteReg(LCD_REG_81, 0x00EF);	/* Horizontal GRAM End Address */
			LCD_WriteReg(LCD_REG_82, 0x0000);	/* Vertical GRAM Start Address */
			LCD_WriteReg(LCD_REG_83, 0x013F);	/* Vertical GRAM End Address */
			LCD_WriteReg(LCD_REG_96, 0xA700);	/* Gate Scan Line */
			LCD_WriteReg(LCD_REG_97, 0x0001);	/* NDL, VLE, REV */
			LCD_WriteReg(LCD_REG_106, 0x0000);	/* set scrolling line */
			/* Partial Display Control ----------------------------------------------- */
			LCD_WriteReg(LCD_REG_128, 0x0000);
			LCD_WriteReg(LCD_REG_129, 0x0000);
			LCD_WriteReg(LCD_REG_130, 0x0000);
			LCD_WriteReg(LCD_REG_131, 0x0000);
			LCD_WriteReg(LCD_REG_132, 0x0000);
			LCD_WriteReg(LCD_REG_133, 0x0000);
			/* Panel Control --------------------------------------------------------- */
			LCD_WriteReg(LCD_REG_144, 0x0010);
			LCD_WriteReg(LCD_REG_146, 0x0000);
			LCD_WriteReg(LCD_REG_147, 0x0003);
			LCD_WriteReg(LCD_REG_149, 0x0110);
			LCD_WriteReg(LCD_REG_151, 0x0000);
			LCD_WriteReg(LCD_REG_152, 0x0000);
			/* Set GRAM write direction and BGR=1
			   I/D=01 (Horizontal : increment, Vertical : decrement)
			   AM=1 (address is updated in vertical writing direction) */
			LCD_WriteReg(LCD_REG_3, 0x1018);
			LCD_WriteReg(LCD_REG_7, 0x0112);	/* 262K color and display ON */
			LCD_SetFont(&LCD_DEFAULT_FONT);
			return;
		}
		/* Start Initial Sequence ---------------------------------------------------- */
		LCD_WriteReg(LCD_REG_229, 0x8000);	/* Set the internal vcore voltage */
		LCD_WriteReg(LCD_REG_0, 0x0001);	/* Start internal OSC. */
		LCD_WriteReg(LCD_REG_1, 0x0100);	/* set SS and SM bit */
		LCD_WriteReg(LCD_REG_2, 0x0700);	/* set 1 line inversion */
		LCD_WriteReg(LCD_REG_3, 0x1030);	/* set GRAM write direction and BGR=1. */
		LCD_WriteReg(LCD_REG_4, 0x0000);	/* Resize register */
		LCD_WriteReg(LCD_REG_8, 0x0202);	/* set the back porch and front porch */
		LCD_WriteReg(LCD_REG_9, 0x0000);	/* set non-display area refresh cycle ISC[3:0] */
		LCD_WriteReg(LCD_REG_10, 0x0000);	/* FMARK function */
		LCD_WriteReg(LCD_REG_12, 0x0000);	/* RGB interface setting */
		LCD_WriteReg(LCD_REG_13, 0x0000);	/* Frame marker Position */
		LCD_WriteReg(LCD_REG_15, 0x0000);	/* RGB interface polarity */
		/* Power On sequence --------------------------------------------------------- */
		LCD_WriteReg(LCD_REG_16, 0x0000);	/* SAP, BT[3:0], AP, DSTB, SLP, STB */
		LCD_WriteReg(LCD_REG_17, 0x0000);	/* DC1[2:0], DC0[2:0], VC[2:0] */
		LCD_WriteReg(LCD_REG_18, 0x0000);	/* VREG1OUT voltage */
		LCD_WriteReg(LCD_REG_19, 0x0000);	/* VDV[4:0] for VCOM amplitude */
		_delay_(20);	/* Dis-charge capacitor power voltage (200ms) */
		LCD_WriteReg(LCD_REG_16, 0x17B0);	/* SAP, BT[3:0], AP, DSTB, SLP, STB */
		LCD_WriteReg(LCD_REG_17, 0x0137);	/* DC1[2:0], DC0[2:0], VC[2:0] */
		_delay_(20);	/* Delay 50 ms */
		LCD_WriteReg(LCD_REG_18, 0x0139);	/* VREG1OUT voltage */
		_delay_(20);	/* Delay 50 ms */
		LCD_WriteReg(LCD_REG_19, 0x1d00);	/* VDV[4:0] for VCOM amplitude */
		LCD_WriteReg(LCD_REG_41, 0x0013);	/* VCM[4:0] for VCOMH */
		_delay_(20);	/* Delay 50 ms */
		LCD_WriteReg(LCD_REG_32, 0x0000);	/* GRAM horizontal Address */
		LCD_WriteReg(LCD_REG_33, 0x0000);	/* GRAM Vertical Address */
		/* Adjust the Gamma Curve ---------------------------------------------------- */
		LCD_WriteReg(LCD_REG_48, 0x0006);
		LCD_WriteReg(LCD_REG_49, 0x0101);
		LCD_WriteReg(LCD_REG_50, 0x0003);
		LCD_WriteReg(LCD_REG_53, 0x0106);
		LCD_WriteReg(LCD_REG_54, 0x0b02);
		LCD_WriteReg(LCD_REG_55, 0x0302);
		LCD_WriteReg(LCD_REG_56, 0x0707);
		LCD_WriteReg(LCD_REG_57, 0x0007);
		LCD_WriteReg(LCD_REG_60, 0x0600);
		LCD_WriteReg(LCD_REG_61, 0x020b);

		/* Set GRAM area ------------------------------------------------------------- */
		LCD_WriteReg(LCD_REG_80, 0x0000);	/* Horizontal GRAM Start Address */
		LCD_WriteReg(LCD_REG_81, 0x00EF);	/* Horizontal GRAM End Address */
		LCD_WriteReg(LCD_REG_82, 0x0000);	/* Vertical GRAM Start Address */
		LCD_WriteReg(LCD_REG_83, 0x013F);	/* Vertical GRAM End Address */
		LCD_WriteReg(LCD_REG_96, 0x2700);	/* Gate Scan Line */
		LCD_WriteReg(LCD_REG_97, 0x0001);	/* NDL,VLE, REV */
		LCD_WriteReg(LCD_REG_106, 0x0000);	/* set scrolling line */
		/* Partial Display Control --------------------------------------------------- */
		LCD_WriteReg(LCD_REG_128, 0x0000);
		LCD_WriteReg(LCD_REG_129, 0x0000);
		LCD_WriteReg(LCD_REG_130, 0x0000);
		LCD_WriteReg(LCD_REG_131, 0x0000);
		LCD_WriteReg(LCD_REG_132, 0x0000);
		LCD_WriteReg(LCD_REG_133, 0x0000);
		/* Panel Control ------------------------------------------------------------- */
		LCD_WriteReg(LCD_REG_144, 0x0010);
		LCD_WriteReg(LCD_REG_146, 0x0000);
		LCD_WriteReg(LCD_REG_147, 0x0003);
		LCD_WriteReg(LCD_REG_149, 0x0110);
		LCD_WriteReg(LCD_REG_151, 0x0000);
		LCD_WriteReg(LCD_REG_152, 0x0000);
		/* Set GRAM write direction and BGR = 1 */
		/* I/D=01 (Horizontal : increment, Vertical : decrement) */
		/* AM=1 (address is updated in vertical writing direction) */
		LCD_WriteReg(LCD_REG_3, 0x1018);
		LCD_WriteReg(LCD_REG_7, 0x0173);	/* 262K color and display ON */
	}
	LCD_SetFont(&LCD_DEFAULT_FONT);
}