/*******************************************************************************
* Function Name  : STM3210B_LCD_Init
* Description    : Initializes the LCD.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void STM3210B_LCD_Init(void)
{
  /* Setups the LCD */
  LCD_Setup();

  /* Try to read new LCD controller ID 0x9320 */
  if (LCD_ReadReg(R0) == LCD_ILI9320)
  {
    LCDType = LCD_ILI9320;
  }
  else
  {
    LCDType = LCD_SPFD5408;

    /* Setups the LCD */
    LCD_Setup();

    /* Try to read new LCD controller ID 0x5408 */
    if (LCD_ReadReg(R0) != LCD_SPFD5408)
    {
      LCDType = LCD_HX8312;
      /* Setups the LCD */
      LCD_Setup();
    }
  }
}
Exemplo n.º 2
0
//******************************************************************************
// Font functions
uint16_t readTypeLCD(void)
{
	uint16_t lcdid = 0;


    lcdid = LCD_ReadReg(0x0000);
	
    if (lcdid == 0)
    {
    	lcdid = LCD_ReadReg(0x0067);
    }

    return lcdid;
}
Exemplo n.º 3
0
/**
  * @brief  Initializes the LCD.
  * @param  None
  * @retval None
  */
void STM32303C_LCD_Init(void)
{
  __IO uint32_t lcdid = 0;
  
  /* Setups the LCD */
  LCD_Setup();

  /* Read the LCD ID */
  lcdid = LCD_ReadReg(0x00);  
  
  if (lcdid == LCD_SPFD5408)
  {
    LCDType = LCD_SPFD5408;
        /* Setups the LCD */
    LCD_Setup();
  }
  else if (lcdid == LCD_ILI9320)
  {
    LCDType = LCD_ILI9320;
    /* Setups the LCD */
    LCD_Setup();    
  }  
  else
  {
    LCDType = LCD_HX8347D;
        /* Setups the LCD */
    LCD_Setup();
  } 
    
  LCD_SetFont(&LCD_DEFAULT_FONT);
}
Exemplo n.º 4
0
/*******************************************************************************
* Function Name  : Serial_ROM_select1
* Description    : Serial Flash/ROM 0 or 1 I/F is selected.
* Input          : None
* Output         : None
* Return         : None
* Attention	     : None
*******************************************************************************/
void Serial_ROM_select1(void)
{
    uint8_t temp;
    temp = LCD_ReadReg(0x05); //SROC
    temp |=0x80;
    LCD_WriteData(temp);
}
Exemplo n.º 5
0
/*******************************************************************************
* Function Name  : PCLK_non_inversion (Pixel Clock Setting Register)
* Description    : PDAT is fetched at PCLK rising edge.
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void PCLK_non_inversion(void)
{
    uint8_t temp;
    temp = LCD_ReadReg(0x04); //PCRS
    temp &= 0x7f;
    LCD_WriteData(temp);
}
Exemplo n.º 6
0
/*******************************************************************************
* Function Name  : PCLK_inversion (Pixel Clock Setting Register)
* Description    : PDAT is fetched at PCLK falling edge.
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void PCLK_inversion(void)
{
    uint8_t temp;
    temp = LCD_ReadReg(0x04); //PCRS
    temp |= 0x80;
    LCD_WriteData(temp);
}
Exemplo n.º 7
0
u16 LCD_ReadPoint(u16 x,u16 y)
{
	LCD_SetCursor(x,y);
	LCD_ReadReg(0x0022);	//读的第一个数据丢弃
   
	opt_delay(2);	  
	return LCD->LCD_RAM;
}
Exemplo n.º 8
0
/*******************************************************************************
* Function Name  : PCLK_width
* Description    : PCLK Period Setting  (Pixel clock (PCLK) period setting. )
* Input          : setx:
							00b: PCLK period = System Clock period.
							01b: PCLK period = 2 times of System Clock period.
							10b: PCLK period = 4 times of System Clock period.
							11b: PCLK period = 8 times of System Clock period.
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void PCLK_width(uint8_t setx) //uint8_t[1:0]
{
    uint8_t temp;
    temp = LCD_ReadReg(0x04); //PCRS
    temp &=0x80;
    temp |= setx;
    LCD_WriteData(temp);
}
Exemplo n.º 9
0
void LCD_Init(void)
{ 
  	u32 lcdid=0;

   	LCD_LineConf();
  	LCD_FSMCConf();
  	delay_ms(5); 
  	lcdid=LCD_ReadReg(0x00);  
  	if(lcdid == 0x9320)
  	{
		LCD_WriteReg(0xE5,0x8000);
		LCD_WriteReg(0x00,0x0001);
		LCD_WriteReg(0x01,0x0100);
		LCD_WriteReg(0x02,0x0700);
		LCD_WriteReg(0x03,0x1030);
		LCD_WriteReg(0x04,0x0000);
		LCD_WriteReg(0x08,0x0202);
		LCD_WriteReg(0x09,0x0000);
		LCD_WriteReg(0x0A,0x0000);
		LCD_WriteReg(0x0B,0x0000);
		LCD_WriteReg(0x0C,0x0000);
		LCD_WriteReg(0x0F,0x0000);
		LCD_WriteReg(0x10,0x0000);
		LCD_WriteReg(0x11,0x0000);
		LCD_WriteReg(0x12,0x0000);
		LCD_WriteReg(0x13,0x0000);
		delay_ms(20);
		LCD_WriteReg(0x10,0x17B0);
		LCD_WriteReg(0x11,0x0137);
		delay_ms(5);
		LCD_WriteReg(0x12,0x0139);
		delay_ms(5);
		LCD_WriteReg(0x13,0x1d00);
		LCD_WriteReg(0x29,0x0013);
		delay_ms(5);
		LCD_WriteReg(0x20,0x0000);
		LCD_WriteReg(0x21,0x0000);
		LCD_WriteReg(0x30,0x0006);
		LCD_WriteReg(0x31,0x0101);
		LCD_WriteReg(0x32,0x0003);
		LCD_WriteReg(0x35,0x0106);
		LCD_WriteReg(0x36,0x0b02);
		LCD_WriteReg(0x37,0x0302);
		LCD_WriteReg(0x38,0x0707);
		LCD_WriteReg(0x39,0x0007);
		LCD_WriteReg(0x3C,0x0600);
		LCD_WriteReg(0x3D,0x020b);
		LCD_WriteReg(0x50,0x0000);
		LCD_WriteReg(0x51,0x00EF);
		LCD_WriteReg(0x52,0x0000);
		LCD_WriteReg(0x53,0x013F);
		LCD_WriteReg(0x60,0x2700);
		LCD_WriteReg(0x61,0x0001);
		LCD_WriteReg(0x6A,0x0000);
		LCD_WriteReg(0x80,0x0000);
		LCD_WriteReg(0x81,0x0000);
		LCD_WriteReg(0x82,0x0000);
		LCD_WriteReg(0x83,0x0000);
		LCD_WriteReg(0x84,0x0000);
		LCD_WriteReg(0x85,0x0000);
		LCD_WriteReg(0x90,0x0010);
		LCD_WriteReg(0x92,0x0000);
		LCD_WriteReg(0x93,0x0003);
		LCD_WriteReg(0x95,0x0110);
		LCD_WriteReg(0x97,0x0000);
		LCD_WriteReg(0x98,0x0000);
		LCD_WriteReg(0x03,0x1018);
		LCD_WriteReg(0x07,0x0173); 
  	}
  	else if(lcdid == 0x9325)
  	{
		LCD_WriteReg(0x00,0x0001);
		LCD_WriteReg(0x01,0x0100);
		LCD_WriteReg(0x02,0x0700);
		LCD_WriteReg(0x03,0x1018);
		LCD_WriteReg(0x04,0x0000);
		LCD_WriteReg(0x08,0x0202);
		LCD_WriteReg(0x09,0x0000);
		LCD_WriteReg(0x0A,0x0000);
		LCD_WriteReg(0x0C,0x0000);
		LCD_WriteReg(0x0D,0x0000);
		LCD_WriteReg(0x0F,0x0000);
		LCD_WriteReg(0x10,0x0000);
		LCD_WriteReg(0x11,0x0000);
		LCD_WriteReg(0x12,0x0000);
		LCD_WriteReg(0x13,0x0000);
		delay_ms(20);
		LCD_WriteReg(0x10,0x17B0);
		LCD_WriteReg(0x11,0x0137);
		delay_ms(5);
		LCD_WriteReg(0x12,0x0139);
		delay_ms(5);
		LCD_WriteReg(0x13,0x1d00);
		LCD_WriteReg(0x29,0x0013);
		delay_ms(5);
		LCD_WriteReg(0x20,0x0000);
		LCD_WriteReg(0x21,0x0000);
		LCD_WriteReg(0x30,0x0007);
		LCD_WriteReg(0x31,0x0302);
		LCD_WriteReg(0x32,0x0105);
		LCD_WriteReg(0x35,0x0206);
		LCD_WriteReg(0x36,0x0808);
		LCD_WriteReg(0x37,0x0206);
		LCD_WriteReg(0x38,0x0504);
		LCD_WriteReg(0x39,0x0007);
		LCD_WriteReg(0x3C,0x0105);
		LCD_WriteReg(0x3D,0x0808);
		LCD_WriteReg(0x50,0x0000);
		LCD_WriteReg(0x51,0x00EF);
		LCD_WriteReg(0x52,0x0000);
		LCD_WriteReg(0x53,0x013F);
		LCD_WriteReg(0x60,0xA700);
		LCD_WriteReg(0x61,0x0001);
		LCD_WriteReg(0x6A,0x0000);
		LCD_WriteReg(0x80,0x0000);
		LCD_WriteReg(0x81,0x0000);
		LCD_WriteReg(0x82,0x0000);
		LCD_WriteReg(0x83,0x0000);
		LCD_WriteReg(0x84,0x0000);
		LCD_WriteReg(0x85,0x0000);
		LCD_WriteReg(0x90,0x0010);
		LCD_WriteReg(0x92,0x0000);
		LCD_WriteReg(0x93,0x0003);
		LCD_WriteReg(0x95,0x0110);
		LCD_WriteReg(0x97,0x0000);
		LCD_WriteReg(0x98,0x0000);
		LCD_WriteReg(0x03,0x1018);
		LCD_WriteReg(0x07,0x0133);
  	}
  	else if(lcdid==0x4531)
  	{		
		LCD_WriteReg(0x00,0x0001);
		LCD_WriteReg(0x10,0x0628);
		LCD_WriteReg(0x12,0x0006);
		LCD_WriteReg(0x13,0x0A32);
		LCD_WriteReg(0x11,0x0040);
		LCD_WriteReg(0x15,0x0050);
		LCD_WriteReg(0x12,0x0016);
		delay_ms(15);
		LCD_WriteReg(0x10,0x5660);
		delay_ms(15);
		LCD_WriteReg(0x13,0x2A4E);
		LCD_WriteReg(0x01,0x0100);
		LCD_WriteReg(0x02,0x0300);	
		LCD_WriteReg(0x03,0x1018);
		LCD_WriteReg(0x08,0x0202);
		LCD_WriteReg(0x0A,0x0000);
		LCD_WriteReg(0x30,0x0000);
		LCD_WriteReg(0x31,0x0402);
		LCD_WriteReg(0x32,0x0106);
		LCD_WriteReg(0x33,0x0700);
		LCD_WriteReg(0x34,0x0104);
		LCD_WriteReg(0x35,0x0301);
		LCD_WriteReg(0x36,0x0707);
		LCD_WriteReg(0x37,0x0305);
		LCD_WriteReg(0x38,0x0208);
		LCD_WriteReg(0x39,0x0F0B);
		delay_ms(15);
		LCD_WriteReg(0x41,0x0002);
		LCD_WriteReg(0x60,0x2700);
		LCD_WriteReg(0x61,0x0001);
		LCD_WriteReg(0x90,0x0119);
		LCD_WriteReg(0x92,0x010A);
		LCD_WriteReg(0x93,0x0004);
		LCD_WriteReg(0xA0,0x0100);
		delay_ms(15);
		delay_ms(15);
		LCD_WriteReg(0x07,0x0133);
		delay_ms(15);
		LCD_WriteReg(0xA0,0x0000);
		delay_ms(20);
  	} 
	LCD_Clear(BLUE);
	LCD_Font(&Font16x24);
	LCD_Mode(4);							 
}
Exemplo n.º 10
0
/*****************************************************************************
** �������: LCD_Init
** ��������: LCD��ʼ��
** ��  ����: Dream
** �ա�  ��: 2010��12��06��
*****************************************************************************/
void LCD_Init(void)
{
	static uint16_t DeviceCode;
	LCD_Configuration();
	LCD_WriteReg(0x0000,0x0001);
	LCD_Delay(5); // LCD_Delay 50 ms 
	DeviceCode = LCD_ReadReg(0x0000);   
	printf(" ID=0x%x\n",DeviceCode); 
	if(DeviceCode==0x9325||DeviceCode==0x9328)//ILI9325
	{
 		LCD_WriteReg(0x00e5,0x78F0);      
//        LCD_WriteReg(0x0000,0x0001);
        LCD_WriteReg(0x0001,0x0100);     
        LCD_WriteReg(0x0002,0x0700);                   
        LCD_WriteReg(0x0003,0x1030);    
        LCD_WriteReg(0x0004,0x0000);                                   
        LCD_WriteReg(0x0008,0x0202);	           
        LCD_WriteReg(0x0009,0x0000);         
        LCD_WriteReg(0x000a,0x0000);         
        LCD_WriteReg(0x000c,0x0001);         
        LCD_WriteReg(0x000d,0x0000);          
        LCD_WriteReg(0x000f,0x0000);
//Power On sequence //
        LCD_WriteReg(0x0010,0x0000);   
        LCD_WriteReg(0x0011,0x0007);
        LCD_WriteReg(0x0012,0x0000);                                                                 
        LCD_WriteReg(0x0013,0x0000);
        LCD_WriteReg(0x0007,0x0001);          
        LCD_Delay(5); 
        LCD_WriteReg(0x0010,0x1690);   
        LCD_WriteReg(0x0011,0x0227);
        LCD_Delay(5); 
        LCD_WriteReg(0x0012,0x009d);                   
        LCD_Delay(5); 
        LCD_WriteReg(0x0013,0x1900);   
        LCD_WriteReg(0x0029,0x0025);
        LCD_WriteReg(0x002b,0x000d);
        LCD_Delay(5); 
        LCD_WriteReg(0x0020,0x0000);                                                            
        LCD_WriteReg(0x0021,0x0000);           
		LCD_Delay(5); 
		//٤��У��
        LCD_WriteReg(0x0030,0x0007); 
        LCD_WriteReg(0x0031,0x0303);   
        LCD_WriteReg(0x0032,0x0003);
        LCD_WriteReg(0x0035,0x0206);
        LCD_WriteReg(0x0036,0x0008); 
        LCD_WriteReg(0x0037,0x0406);
        LCD_WriteReg(0x0038,0x0304);        
        LCD_WriteReg(0x0039,0x0007);     
        LCD_WriteReg(0x003c,0x0602);
        LCD_WriteReg(0x003d,0x0008);
        LCD_Delay(5); 
        LCD_WriteReg(0x0050,0x0000);
        LCD_WriteReg(0x0051,0x00ef);                   
        LCD_WriteReg(0x0052,0x0000);                   
        LCD_WriteReg(0x0053,0x013f); 
        
        LCD_WriteReg(0x0060,0xa700);        
        LCD_WriteReg(0x0061,0x0001); 
        LCD_WriteReg(0x006a,0x0000);
        LCD_WriteReg(0x0080,0x0000);
        LCD_WriteReg(0x0081,0x0000);
        LCD_WriteReg(0x0082,0x0000);
        LCD_WriteReg(0x0083,0x0000);
        LCD_WriteReg(0x0084,0x0000);
        LCD_WriteReg(0x0085,0x0000);
      
        LCD_WriteReg(0x0090,0x0010);     
        LCD_WriteReg(0x0092,0x0600);  
		   
        LCD_WriteReg(0x0007,0x0133);
	}
	else if(DeviceCode==0x9320||DeviceCode==0x9300)
	{
		LCD_WriteReg(0x00,0x0000);
		LCD_WriteReg(0x01,0x0100);	//Driver Output Contral.
		LCD_WriteReg(0x02,0x0700);	//LCD Driver Waveform Contral.
		LCD_WriteReg(0x03,0x1030);//Entry Mode Set.
		//LCD_WriteReg(0x03,0x1018);	//Entry Mode Set.
	
		LCD_WriteReg(0x04,0x0000);	//Scalling Contral.
		LCD_WriteReg(0x08,0x0202);	//Display Contral 2.(0x0207)
		LCD_WriteReg(0x09,0x0000);	//Display Contral 3.(0x0000)
		LCD_WriteReg(0x0a,0x0000);	//Frame Cycle Contal.(0x0000)
		LCD_WriteReg(0x0c,(1<<0));	//Extern Display Interface Contral 1.(0x0000)
		LCD_WriteReg(0x0d,0x0000);	//Frame Maker Position.
		LCD_WriteReg(0x0f,0x0000);	//Extern Display Interface Contral 2.	    
		LCD_Delay(10); 
		LCD_WriteReg(0x07,0x0101);	//Display Contral.
		LCD_Delay(10); 								  
		LCD_WriteReg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4));	//Power Control 1.(0x16b0)
		LCD_WriteReg(0x11,0x0007);								//Power Control 2.(0x0001)
		LCD_WriteReg(0x12,(1<<8)|(1<<4)|(0<<0));				//Power Control 3.(0x0138)
		LCD_WriteReg(0x13,0x0b00);								//Power Control 4.
		LCD_WriteReg(0x29,0x0000);								//Power Control 7.
	
		LCD_WriteReg(0x2b,(1<<14)|(1<<4));	    
		LCD_WriteReg(0x50,0);	//Set X Star
		//ˮƽGRAM��ֹλ��Set X End.
		LCD_WriteReg(0x51,239);	//Set Y Star
		LCD_WriteReg(0x52,0);	//Set Y End.t.
		LCD_WriteReg(0x53,319);	//
	
		LCD_WriteReg(0x60,0x2700);	//Driver Output Control.
		LCD_WriteReg(0x61,0x0001);	//Driver Output Control.
		LCD_WriteReg(0x6a,0x0000);	//Vertical Srcoll Control.
	
		LCD_WriteReg(0x80,0x0000);	//Display Position? Partial Display 1.
		LCD_WriteReg(0x81,0x0000);	//RAM Address Start? Partial Display 1.
		LCD_WriteReg(0x82,0x0000);	//RAM Address End-Partial Display 1.
		LCD_WriteReg(0x83,0x0000);	//Displsy Position? Partial Display 2.
		LCD_WriteReg(0x84,0x0000);	//RAM Address Start? Partial Display 2.
		LCD_WriteReg(0x85,0x0000);	//RAM Address End? Partial Display 2.
	
		LCD_WriteReg(0x90,(0<<7)|(16<<0));	//Frame Cycle Contral.(0x0013)
		LCD_WriteReg(0x92,0x0000);	//Panel Interface Contral 2.(0x0000)
		LCD_WriteReg(0x93,0x0001);	//Panel Interface Contral 3.
		LCD_WriteReg(0x95,0x0110);	//Frame Cycle Contral.(0x0110)
		LCD_WriteReg(0x97,(0<<8));	//
		LCD_WriteReg(0x98,0x0000);	//Frame Cycle Contral.	   
		LCD_WriteReg(0x07,0x0173);	//(0x0173)
		LCD_Delay(10);
	}
	LCD_Clear(BACK_COLOR);	
}
//初始化lcd
//该初始化函数可以初始化各种ILI93XX液晶,但是其他函数是基于ILI9320的!!!
//在其他型号的驱动芯片上没有测试! 
void LCD_Init(void)
{ 
 	RCC->APB2ENR|=1<<3;//先使能外设PORTB时钟
 	RCC->APB2ENR|=1<<4;//先使能外设PORTC时钟

	RCC->APB2ENR|=1<<0;    //开启辅助时钟
	JTAG_Set(SWD_ENABLE);  //开启SWD
											 
	//PORTC6~10复用推挽输出 	
	GPIOC->CRH&=0XFFFFF000;
	GPIOC->CRH|=0X00000333; 
	GPIOC->CRL&=0X00FFFFFF;
	GPIOC->CRL|=0X33000000;  
	GPIOC->ODR|=0X07C0; 	 
	//PORTB 推挽输出 	
	GPIOB->CRH=0X33333333;
	GPIOB->CRL=0X33333333; 	 
	GPIOB->ODR=0XFFFF;
	  					 
	delay_ms(50); // delay 50 ms 
	LCD_WriteReg(0x0000,0x0001);
	delay_ms(50); // delay 50 ms 
	DeviceCode = LCD_ReadReg(0x0000);   
	printf(" LCD ID:%x\n",DeviceCode); //打印LCD ID  
 	if(DeviceCode==0x9325)
	{
		LCD_WriteReg(0x00E5,0x78F0); 
		LCD_WriteReg(0x0001,0x0100); 
		LCD_WriteReg(0x0002,0x0700); 
		LCD_WriteReg(0x0003,0x1030); 
		LCD_WriteReg(0x0004,0x0000); 
		LCD_WriteReg(0x0008,0x0202);  
		LCD_WriteReg(0x0009,0x0000);
		LCD_WriteReg(0x000A,0x0000); 
		LCD_WriteReg(0x000C,0x0000); 
		LCD_WriteReg(0x000D,0x0000);
		LCD_WriteReg(0x000F,0x0000);
		//power on sequence VGHVGL
		LCD_WriteReg(0x0010,0x0000);   
		LCD_WriteReg(0x0011,0x0007);  
		LCD_WriteReg(0x0012,0x0000);  
		LCD_WriteReg(0x0013,0x0000); 
		LCD_WriteReg(0x0007,0x0000); 
		//vgh 
		LCD_WriteReg(0x0010,0x1690);   
		LCD_WriteReg(0x0011,0x0227);
		//delayms(100);
		//vregiout 
		LCD_WriteReg(0x0012,0x009D); //0x001b
		//delayms(100); 
		//vom amplitude
		LCD_WriteReg(0x0013,0x1900);
		//delayms(100); 
		//vom H
		LCD_WriteReg(0x0029,0x0025); 
		LCD_WriteReg(0x002B,0x000D); 
		//gamma
		LCD_WriteReg(0x0030,0x0007);
		LCD_WriteReg(0x0031,0x0303);
		LCD_WriteReg(0x0032,0x0003);// 0006
		LCD_WriteReg(0x0035,0x0206);
		LCD_WriteReg(0x0036,0x0008);
		LCD_WriteReg(0x0037,0x0406); 
		LCD_WriteReg(0x0038,0x0304);//0200
		LCD_WriteReg(0x0039,0x0007); 
		LCD_WriteReg(0x003C,0x0602);// 0504
		LCD_WriteReg(0x003D,0x0008); 
		//ram
		LCD_WriteReg(0x0050,0x0000); 
		LCD_WriteReg(0x0051,0x00EF);
		LCD_WriteReg(0x0052,0x0000); 
		LCD_WriteReg(0x0053,0x013F);  
		LCD_WriteReg(0x0060,0xA700); 
		LCD_WriteReg(0x0061,0x0001); 
		LCD_WriteReg(0x006A,0x0000); 
		//
		LCD_WriteReg(0x0080,0x0000); 
		LCD_WriteReg(0x0081,0x0000); 
		LCD_WriteReg(0x0082,0x0000); 
		LCD_WriteReg(0x0083,0x0000); 
		LCD_WriteReg(0x0084,0x0000); 
		LCD_WriteReg(0x0085,0x0000); 
		//
		LCD_WriteReg(0x0090,0x0010); 
		LCD_WriteReg(0x0092,0x0600); 
		
		LCD_WriteReg(0x0007,0x0133);
		LCD_WriteReg(0x00,0x0022);//	
	}else if(DeviceCode==0x9328)//ILI9328
	{
  		LCD_WriteReg(0x00e7,0x0010);      
        LCD_WriteReg(0x0000,0x0001);//开启内部时钟
        LCD_WriteReg(0x0001,0x0100);     
        LCD_WriteReg(0x0002,0x0700);//电源开启                    
		//LCD_WriteReg(0x0003,(1<<3)|(1<<4) ); 	//65K  RGB
		//DRIVE TABLE(寄存器 03H)
		//BIT3=AM BIT4:5=ID0:1
		//AM ID0 ID1   FUNCATION
		// 0  0   0	   R->L D->U
		// 1  0   0	   D->U	R->L
		// 0  1   0	   L->R D->U
		// 1  1   0    D->U	L->R
		// 0  0   1	   R->L U->D
		// 1  0   1    U->D	R->L
		// 0  1   1    L->R U->D 正常就用这个.
		// 1  1   1	   U->D	L->R
        LCD_WriteReg(0x0003,(1<<12)|(3<<4)|(0<<3) );//65K    
        LCD_WriteReg(0x0004,0x0000);                                   
        LCD_WriteReg(0x0008,0x0207);	           
        LCD_WriteReg(0x0009,0x0000);         
        LCD_WriteReg(0x000a,0x0000);//display setting         
        LCD_WriteReg(0x000c,0x0001);//display setting          
        LCD_WriteReg(0x000d,0x0000);//0f3c          
        LCD_WriteReg(0x000f,0x0000);
		//电源配置
        LCD_WriteReg(0x0010,0x0000);   
        LCD_WriteReg(0x0011,0x0007);
        LCD_WriteReg(0x0012,0x0000);                                                                 
        LCD_WriteReg(0x0013,0x0000);                 
        delay_ms(50); 
        LCD_WriteReg(0x0010,0x1590);   
        LCD_WriteReg(0x0011,0x0227);
        delay_ms(50); 
        LCD_WriteReg(0x0012,0x009c);                  
        delay_ms(50); 
        LCD_WriteReg(0x0013,0x1900);   
        LCD_WriteReg(0x0029,0x0023);
        LCD_WriteReg(0x002b,0x000e);
        delay_ms(50); 
        LCD_WriteReg(0x0020,0x0000);                                                            
        LCD_WriteReg(0x0021,0x013f);           
		delay_ms(50); 
		//伽马校正
        LCD_WriteReg(0x0030,0x0007); 
        LCD_WriteReg(0x0031,0x0707);   
        LCD_WriteReg(0x0032,0x0006);
        LCD_WriteReg(0x0035,0x0704);
        LCD_WriteReg(0x0036,0x1f04); 
        LCD_WriteReg(0x0037,0x0004);
        LCD_WriteReg(0x0038,0x0000);        
        LCD_WriteReg(0x0039,0x0706);     
        LCD_WriteReg(0x003c,0x0701);
        LCD_WriteReg(0x003d,0x000f);
        delay_ms(50); 
        LCD_WriteReg(0x0050,0x0000); //水平GRAM起始位置 
        LCD_WriteReg(0x0051,0x00ef); //水平GRAM终止位置                    
        LCD_WriteReg(0x0052,0x0000); //垂直GRAM起始位置                    
        LCD_WriteReg(0x0053,0x013f); //垂直GRAM终止位置  
        
        LCD_WriteReg(0x0060,0xa700);        
        LCD_WriteReg(0x0061,0x0001); 
        LCD_WriteReg(0x006a,0x0000);
        LCD_WriteReg(0x0080,0x0000);
        LCD_WriteReg(0x0081,0x0000);
        LCD_WriteReg(0x0082,0x0000);
        LCD_WriteReg(0x0083,0x0000);
        LCD_WriteReg(0x0084,0x0000);
        LCD_WriteReg(0x0085,0x0000);
      
        LCD_WriteReg(0x0090,0x0010);     
        LCD_WriteReg(0x0092,0x0000);  
        LCD_WriteReg(0x0093,0x0003);
        LCD_WriteReg(0x0095,0x0110);
        LCD_WriteReg(0x0097,0x0000);        
        LCD_WriteReg(0x0098,0x0000);  
        //开启显示设置    
        LCD_WriteReg(0x0007,0x0133);   
        LCD_WriteReg(0x0020,0x0000);                                                            
        LCD_WriteReg(0x0021,0x013f);
	}else if(DeviceCode==0x9320||DeviceCode==0x9300)
	{
		LCD_WriteReg(0x00,0x0000);
		LCD_WriteReg(0x01,0x0100);	//Driver Output Contral.
		LCD_WriteReg(0x02,0x0700);	//LCD Driver Waveform Contral.
		LCD_WriteReg(0x03,0x1030);//Entry Mode Set.
		//LCD_WriteReg(0x03,0x1018);	//Entry Mode Set.
	
		LCD_WriteReg(0x04,0x0000);	//Scalling Contral.
		LCD_WriteReg(0x08,0x0202);	//Display Contral 2.(0x0207)
		LCD_WriteReg(0x09,0x0000);	//Display Contral 3.(0x0000)
		LCD_WriteReg(0x0a,0x0000);	//Frame Cycle Contal.(0x0000)
		LCD_WriteReg(0x0c,(1<<0));	//Extern Display Interface Contral 1.(0x0000)
		LCD_WriteReg(0x0d,0x0000);	//Frame Maker Position.
		LCD_WriteReg(0x0f,0x0000);	//Extern Display Interface Contral 2.	    
		delay_ms(50); 
		LCD_WriteReg(0x07,0x0101);	//Display Contral.
		delay_ms(50); 								  
		LCD_WriteReg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4));	//Power Control 1.(0x16b0)
		LCD_WriteReg(0x11,0x0007);								//Power Control 2.(0x0001)
		LCD_WriteReg(0x12,(1<<8)|(1<<4)|(0<<0));				//Power Control 3.(0x0138)
		LCD_WriteReg(0x13,0x0b00);								//Power Control 4.
		LCD_WriteReg(0x29,0x0000);								//Power Control 7.
	
		LCD_WriteReg(0x2b,(1<<14)|(1<<4));	    
		LCD_WriteReg(0x50,0);	//Set X Star
		//水平GRAM终止位置Set X End.
		LCD_WriteReg(0x51,239);	//Set Y Star
		LCD_WriteReg(0x52,0);	//Set Y End.t.
		LCD_WriteReg(0x53,319);	//
	
		LCD_WriteReg(0x60,0x2700);	//Driver Output Control.
		LCD_WriteReg(0x61,0x0001);	//Driver Output Control.
		LCD_WriteReg(0x6a,0x0000);	//Vertical Srcoll Control.
	
		LCD_WriteReg(0x80,0x0000);	//Display Position? Partial Display 1.
		LCD_WriteReg(0x81,0x0000);	//RAM Address Start? Partial Display 1.
		LCD_WriteReg(0x82,0x0000);	//RAM Address End-Partial Display 1.
		LCD_WriteReg(0x83,0x0000);	//Displsy Position? Partial Display 2.
		LCD_WriteReg(0x84,0x0000);	//RAM Address Start? Partial Display 2.
		LCD_WriteReg(0x85,0x0000);	//RAM Address End? Partial Display 2.
	
		LCD_WriteReg(0x90,(0<<7)|(16<<0));	//Frame Cycle Contral.(0x0013)
		LCD_WriteReg(0x92,0x0000);	//Panel Interface Contral 2.(0x0000)
		LCD_WriteReg(0x93,0x0001);	//Panel Interface Contral 3.
		LCD_WriteReg(0x95,0x0110);	//Frame Cycle Contral.(0x0110)
		LCD_WriteReg(0x97,(0<<8));	//
		LCD_WriteReg(0x98,0x0000);	//Frame Cycle Contral.	   
		LCD_WriteReg(0x07,0x0173);	//(0x0173)
	}else if(DeviceCode==0x5408)
	{
		LCD_WriteReg(0x01,0x0100);								  
		LCD_WriteReg(0x02,0x0700);//LCD Driving Waveform Contral 
		LCD_WriteReg(0x03,0x1030);//Entry Mode设置 	   
		//指针从左至右自上而下的自动增模式
		//Normal Mode(Window Mode disable)
		//RGB格式
		//16位数据2次传输的8总线设置
		LCD_WriteReg(0x04,0x0000); //Scalling Control register     
		LCD_WriteReg(0x08,0x0207); //Display Control 2 
		LCD_WriteReg(0x09,0x0000); //Display Control 3	 
		LCD_WriteReg(0x0A,0x0000); //Frame Cycle Control	 
		LCD_WriteReg(0x0C,0x0000); //External Display Interface Control 1 
		LCD_WriteReg(0x0D,0x0000); //Frame Maker Position		 
		LCD_WriteReg(0x0F,0x0000); //External Display Interface Control 2 
 		delay_ms(20);
		//TFT 液晶彩色图像显示方法14
		LCD_WriteReg(0x10,0x16B0); //0x14B0 //Power Control 1
		LCD_WriteReg(0x11,0x0001); //0x0007 //Power Control 2
		LCD_WriteReg(0x17,0x0001); //0x0000 //Power Control 3
		LCD_WriteReg(0x12,0x0138); //0x013B //Power Control 4
		LCD_WriteReg(0x13,0x0800); //0x0800 //Power Control 5
		LCD_WriteReg(0x29,0x0009); //NVM read data 2
		LCD_WriteReg(0x2a,0x0009); //NVM read data 3
		LCD_WriteReg(0xa4,0x0000);	 
		LCD_WriteReg(0x50,0x0000); //设置操作窗口的X轴开始列
		LCD_WriteReg(0x51,0x00EF); //设置操作窗口的X轴结束列
		LCD_WriteReg(0x52,0x0000); //设置操作窗口的Y轴开始行
		LCD_WriteReg(0x53,0x013F); //设置操作窗口的Y轴结束行
		LCD_WriteReg(0x60,0x2700); //Driver Output Control
		//设置屏幕的点数以及扫描的起始行
		LCD_WriteReg(0x61,0x0001); //Driver Output Control
		LCD_WriteReg(0x6A,0x0000); //Vertical Scroll Control
		LCD_WriteReg(0x80,0x0000); //Display Position – Partial Display 1
		LCD_WriteReg(0x81,0x0000); //RAM Address Start – Partial Display 1
		LCD_WriteReg(0x82,0x0000); //RAM address End - Partial Display 1
		LCD_WriteReg(0x83,0x0000); //Display Position – Partial Display 2
		LCD_WriteReg(0x84,0x0000); //RAM Address Start – Partial Display 2
		LCD_WriteReg(0x85,0x0000); //RAM address End – Partail Display2
		LCD_WriteReg(0x90,0x0013); //Frame Cycle Control
		LCD_WriteReg(0x92,0x0000);  //Panel Interface Control 2
		LCD_WriteReg(0x93,0x0003); //Panel Interface control 3
		LCD_WriteReg(0x95,0x0110);  //Frame Cycle Control
		LCD_WriteReg(0x07,0x0173);		 
		delay_ms(50);
	}	
	else if(DeviceCode==0x1505)
	{
		// second release on 3/5  ,luminance is acceptable,water wave appear during camera preview
        LCD_WriteReg(0x0007,0x0000);
        delay_ms(50); 
        LCD_WriteReg(0x0012,0x011C);//0x011A   why need to set several times?
        LCD_WriteReg(0x00A4,0x0001);//NVM	 
        LCD_WriteReg(0x0008,0x000F);
        LCD_WriteReg(0x000A,0x0008);
        LCD_WriteReg(0x000D,0x0008);	    
  		//伽马校正
        LCD_WriteReg(0x0030,0x0707);
        LCD_WriteReg(0x0031,0x0007); //0x0707
        LCD_WriteReg(0x0032,0x0603); 
        LCD_WriteReg(0x0033,0x0700); 
        LCD_WriteReg(0x0034,0x0202); 
        LCD_WriteReg(0x0035,0x0002); //?0x0606
        LCD_WriteReg(0x0036,0x1F0F);
        LCD_WriteReg(0x0037,0x0707); //0x0f0f  0x0105
        LCD_WriteReg(0x0038,0x0000); 
        LCD_WriteReg(0x0039,0x0000); 
        LCD_WriteReg(0x003A,0x0707); 
        LCD_WriteReg(0x003B,0x0000); //0x0303
        LCD_WriteReg(0x003C,0x0007); //?0x0707
        LCD_WriteReg(0x003D,0x0000); //0x1313//0x1f08
        delay_ms(50); 
        LCD_WriteReg(0x0007,0x0001);
        LCD_WriteReg(0x0017,0x0001);//开启电源
        delay_ms(50); 
  		//电源配置
        LCD_WriteReg(0x0010,0x17A0); 
        LCD_WriteReg(0x0011,0x0217);//reference voltage VC[2:0]   Vciout = 1.00*Vcivl
        LCD_WriteReg(0x0012,0x011E);//0x011c  //Vreg1out = Vcilvl*1.80   is it the same as Vgama1out ?
        LCD_WriteReg(0x0013,0x0F00);//VDV[4:0]-->VCOM Amplitude VcomL = VcomH - Vcom Ampl
        LCD_WriteReg(0x002A,0x0000);  
        LCD_WriteReg(0x0029,0x000A);//0x0001F  Vcomh = VCM1[4:0]*Vreg1out    gate source voltage??
        LCD_WriteReg(0x0012,0x013E);// 0x013C  power supply on
        //Coordinates Control//
        LCD_WriteReg(0x0050,0x0000);//0x0e00
        LCD_WriteReg(0x0051,0x00EF); 
        LCD_WriteReg(0x0052,0x0000); 
        LCD_WriteReg(0x0053,0x013F); 
    	//Pannel Image Control//
        LCD_WriteReg(0x0060,0x2700); 
        LCD_WriteReg(0x0061,0x0001); 
        LCD_WriteReg(0x006A,0x0000); 
        LCD_WriteReg(0x0080,0x0000); 
    	//Partial Image Control//
        LCD_WriteReg(0x0081,0x0000); 
        LCD_WriteReg(0x0082,0x0000); 
        LCD_WriteReg(0x0083,0x0000); 
        LCD_WriteReg(0x0084,0x0000); 
        LCD_WriteReg(0x0085,0x0000); 
  		//Panel Interface Control//
        LCD_WriteReg(0x0090,0x0013);//0x0010 frenqucy
        LCD_WriteReg(0x0092,0x0300); 
        LCD_WriteReg(0x0093,0x0005); 
        LCD_WriteReg(0x0095,0x0000); 
        LCD_WriteReg(0x0097,0x0000); 
        LCD_WriteReg(0x0098,0x0000); 
  
        LCD_WriteReg(0x0001,0x0100); 
        LCD_WriteReg(0x0002,0x0700); 
        LCD_WriteReg(0x0003,0x1030); 
        LCD_WriteReg(0x0004,0x0000); 
        LCD_WriteReg(0x000C,0x0000); 
        LCD_WriteReg(0x000F,0x0000); 
        LCD_WriteReg(0x0020,0x0000); 
        LCD_WriteReg(0x0021,0x0000); 
        LCD_WriteReg(0x0007,0x0021); 
        delay_ms(20);
        LCD_WriteReg(0x0007,0x0061); 
        delay_ms(20);
        LCD_WriteReg(0x0007,0x0173); 
        delay_ms(20);
	}else if(DeviceCode==0xB505)
	{
		LCD_WriteReg(0x0000,0x0000);
		LCD_WriteReg(0x0000,0x0000);
		LCD_WriteReg(0x0000,0x0000);
		LCD_WriteReg(0x0000,0x0000);
		
		LCD_WriteReg(0x00a4,0x0001);
		delay_ms(20);		  
		LCD_WriteReg(0x0060,0x2700);
		LCD_WriteReg(0x0008,0x0202);
		
		LCD_WriteReg(0x0030,0x0214);
		LCD_WriteReg(0x0031,0x3715);
		LCD_WriteReg(0x0032,0x0604);
		LCD_WriteReg(0x0033,0x0e16);
		LCD_WriteReg(0x0034,0x2211);
		LCD_WriteReg(0x0035,0x1500);
		LCD_WriteReg(0x0036,0x8507);
		LCD_WriteReg(0x0037,0x1407);
		LCD_WriteReg(0x0038,0x1403);
		LCD_WriteReg(0x0039,0x0020);
		
		LCD_WriteReg(0x0090,0x001a);
		LCD_WriteReg(0x0010,0x0000);
		LCD_WriteReg(0x0011,0x0007);
		LCD_WriteReg(0x0012,0x0000);
		LCD_WriteReg(0x0013,0x0000);
		delay_ms(20);
		
		LCD_WriteReg(0x0010,0x0730);
		LCD_WriteReg(0x0011,0x0137);
		delay_ms(20);
		
		LCD_WriteReg(0x0012,0x01b8);
		delay_ms(20);
		
		LCD_WriteReg(0x0013,0x0f00);
		LCD_WriteReg(0x002a,0x0080);
		LCD_WriteReg(0x0029,0x0048);
		delay_ms(20);
		
		LCD_WriteReg(0x0001,0x0100);
		LCD_WriteReg(0x0002,0x0700);
		LCD_WriteReg(0x0003,0x1230);
		LCD_WriteReg(0x0008,0x0202);
		LCD_WriteReg(0x000a,0x0000);
		LCD_WriteReg(0x000c,0x0000);
		LCD_WriteReg(0x000d,0x0000);
		LCD_WriteReg(0x000e,0x0030);
		LCD_WriteReg(0x0050,0x0000);
		LCD_WriteReg(0x0051,0x00ef);
		LCD_WriteReg(0x0052,0x0000);
		LCD_WriteReg(0x0053,0x013f);
		LCD_WriteReg(0x0060,0x2700);
		LCD_WriteReg(0x0061,0x0001);
		LCD_WriteReg(0x006a,0x0000);
		//LCD_WriteReg(0x0080,0x0000);
		//LCD_WriteReg(0x0081,0x0000);
		LCD_WriteReg(0x0090,0X0011);
		LCD_WriteReg(0x0092,0x0600);
		LCD_WriteReg(0x0093,0x0402);
		LCD_WriteReg(0x0094,0x0002);
		delay_ms(20);
		
		LCD_WriteReg(0x0007,0x0001);
		delay_ms(20);
		LCD_WriteReg(0x0007,0x0061);
		LCD_WriteReg(0x0007,0x0173);
		
		LCD_WriteReg(0x0020,0x0000);
		LCD_WriteReg(0x0021,0x0000);	  
		LCD_WriteReg(0x00,0x22);  
	}else if(DeviceCode==0x8989)
	{	   
		LCD_WriteReg(0x0000,0x0001);//打开晶振
    	LCD_WriteReg(0x0003,0xA8A4);//0xA8A4
    	LCD_WriteReg(0x000C,0x0000);    
    	LCD_WriteReg(0x000D,0x080C);   
    	LCD_WriteReg(0x000E,0x2B00);    
    	LCD_WriteReg(0x001E,0x00B0);    
    	LCD_WriteReg(0x0001,0x2B3F);//驱动输出控制320*240  0x6B3F
    	LCD_WriteReg(0x0002,0x0600);
    	LCD_WriteReg(0x0010,0x0000);  
    	LCD_WriteReg(0x0011,0x6070); //定义数据格式  16位色 		横屏 0x6058
    	LCD_WriteReg(0x0005,0x0000);  
    	LCD_WriteReg(0x0006,0x0000);  
    	LCD_WriteReg(0x0016,0xEF1C);  
    	LCD_WriteReg(0x0017,0x0003);  
    	LCD_WriteReg(0x0007,0x0233); //0x0233       
    	LCD_WriteReg(0x000B,0x0000);  
    	LCD_WriteReg(0x000F,0x0000); //扫描开始地址
    	LCD_WriteReg(0x0041,0x0000);  
    	LCD_WriteReg(0x0042,0x0000);  
    	LCD_WriteReg(0x0048,0x0000);  
    	LCD_WriteReg(0x0049,0x013F);  
    	LCD_WriteReg(0x004A,0x0000);  
    	LCD_WriteReg(0x004B,0x0000);  
    	LCD_WriteReg(0x0044,0xEF00);  
    	LCD_WriteReg(0x0045,0x0000);  
    	LCD_WriteReg(0x0046,0x013F);  
    	LCD_WriteReg(0x0030,0x0707);  
    	LCD_WriteReg(0x0031,0x0204);  
    	LCD_WriteReg(0x0032,0x0204);  
    	LCD_WriteReg(0x0033,0x0502);  
    	LCD_WriteReg(0x0034,0x0507);  
    	LCD_WriteReg(0x0035,0x0204);  
    	LCD_WriteReg(0x0036,0x0204);  
    	LCD_WriteReg(0x0037,0x0502);  
    	LCD_WriteReg(0x003A,0x0302);  
    	LCD_WriteReg(0x003B,0x0302);  
    	LCD_WriteReg(0x0023,0x0000);  
    	LCD_WriteReg(0x0024,0x0000);  
    	LCD_WriteReg(0x0025,0x8000);  
    	LCD_WriteReg(0x004f,0);        //行首址0
    	LCD_WriteReg(0x004e,0);        //列首址0
	}else if(DeviceCode==0x4531)
	{
		LCD_WriteReg(0X00,0X0001);   
		delay_ms(10);   
		LCD_WriteReg(0X10,0X1628);   
		LCD_WriteReg(0X12,0X000e);//0x0006    
		LCD_WriteReg(0X13,0X0A39);   
		delay_ms(10);   
		LCD_WriteReg(0X11,0X0040);   
		LCD_WriteReg(0X15,0X0050);   
		delay_ms(10);   
		LCD_WriteReg(0X12,0X001e);//16    
		delay_ms(10);   
		LCD_WriteReg(0X10,0X1620);   
		LCD_WriteReg(0X13,0X2A39);   
		delay_ms(10);   
		LCD_WriteReg(0X01,0X0100);   
		LCD_WriteReg(0X02,0X0300);   
		LCD_WriteReg(0X03,0X1030);//改变方向的   
		LCD_WriteReg(0X08,0X0202);   
		LCD_WriteReg(0X0A,0X0008);   
		LCD_WriteReg(0X30,0X0000);   
		LCD_WriteReg(0X31,0X0402);   
		LCD_WriteReg(0X32,0X0106);   
		LCD_WriteReg(0X33,0X0503);   
		LCD_WriteReg(0X34,0X0104);   
		LCD_WriteReg(0X35,0X0301);   
		LCD_WriteReg(0X36,0X0707);   
		LCD_WriteReg(0X37,0X0305);   
		LCD_WriteReg(0X38,0X0208);   
		LCD_WriteReg(0X39,0X0F0B);   
		LCD_WriteReg(0X41,0X0002);   
		LCD_WriteReg(0X60,0X2700);   
		LCD_WriteReg(0X61,0X0001);   
		LCD_WriteReg(0X90,0X0210);   
		LCD_WriteReg(0X92,0X010A);   
		LCD_WriteReg(0X93,0X0004);   
		LCD_WriteReg(0XA0,0X0100);   
		LCD_WriteReg(0X07,0X0001);   
		LCD_WriteReg(0X07,0X0021);   
		LCD_WriteReg(0X07,0X0023);   
		LCD_WriteReg(0X07,0X0033);   
		LCD_WriteReg(0X07,0X0133);   
		LCD_WriteReg(0XA0,0X0000); 
	}else if(DeviceCode==0x4535)
	{			      
		LCD_WriteReg(0X15,0X0030);   
		LCD_WriteReg(0X9A,0X0010);   
 		LCD_WriteReg(0X11,0X0020);   
 		LCD_WriteReg(0X10,0X3428);   
		LCD_WriteReg(0X12,0X0002);//16    
 		LCD_WriteReg(0X13,0X1038);   
		delay_ms(40);   
		LCD_WriteReg(0X12,0X0012);//16    
		delay_ms(40);   
  		LCD_WriteReg(0X10,0X3420);   
 		LCD_WriteReg(0X13,0X3038);   
		delay_ms(70);   
		LCD_WriteReg(0X30,0X0000);   
		LCD_WriteReg(0X31,0X0402);   
		LCD_WriteReg(0X32,0X0307);   
		LCD_WriteReg(0X33,0X0304);   
		LCD_WriteReg(0X34,0X0004);   
		LCD_WriteReg(0X35,0X0401);   
		LCD_WriteReg(0X36,0X0707);   
		LCD_WriteReg(0X37,0X0305);   
		LCD_WriteReg(0X38,0X0610);   
		LCD_WriteReg(0X39,0X0610); 
		  
		LCD_WriteReg(0X01,0X0100);   
		LCD_WriteReg(0X02,0X0300);   
		LCD_WriteReg(0X03,0X1030);//改变方向的   
		LCD_WriteReg(0X08,0X0808);   
		LCD_WriteReg(0X0A,0X0008);   
 		LCD_WriteReg(0X60,0X2700);   
		LCD_WriteReg(0X61,0X0001);   
		LCD_WriteReg(0X90,0X013E);   
		LCD_WriteReg(0X92,0X0100);   
		LCD_WriteReg(0X93,0X0100);   
 		LCD_WriteReg(0XA0,0X3000);   
 		LCD_WriteReg(0XA3,0X0010);   
		LCD_WriteReg(0X07,0X0001);   
		LCD_WriteReg(0X07,0X0021);   
		LCD_WriteReg(0X07,0X0023);   
		LCD_WriteReg(0X07,0X0033);   
		LCD_WriteReg(0X07,0X0133);   
	}			 
	LCD_LED=1;//点亮背光	 
	LCD_Clear(WHITE);
}  		  
Exemplo n.º 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 */  
}
void LCD_Init(void)
{ 
  	u32 lcdid=0;
   	LCD_LineConf();
  	LCD_FSMCConf();
  	delay_ms(5); 
  	lcdid=LCD_ReadReg(0x00);  
 	if(lcdid == 0x9328)
  	{
		    LCD_WriteReg(0x00e7,0x0010);      
        LCD_WriteReg(0x0000,0x0001);  			//start internal osc
        LCD_WriteReg(0x0001,0x0100);     
        LCD_WriteReg(0x0002,0x0700); 		    //power on sequence                     
        LCD_WriteReg(0x0003,(1<<12)|(1<<5)|(1<<4) ); 	//65K 
        LCD_WriteReg(0x0004,0x0000);                                   
        LCD_WriteReg(0x0008,0x0207);	           
        LCD_WriteReg(0x0009,0x0000);         
        LCD_WriteReg(0x000a,0x0000); 			//display setting         
        LCD_WriteReg(0x000c,0x0001);			//display setting          
        LCD_WriteReg(0x000d,0x0000); 			//0f3c          
        LCD_WriteReg(0x000f,0x0000);

        //Power On sequence //
        LCD_WriteReg(0x0010,0x0000);   
        LCD_WriteReg(0x0011,0x0007);
        LCD_WriteReg(0x0012,0x0000);                                                                 
        LCD_WriteReg(0x0013,0x0000);                 
        delay_ms(40);
        LCD_WriteReg(0x0010,0x1590);   
        LCD_WriteReg(0x0011,0x0227);
        delay_ms(40);
        LCD_WriteReg(0x0012,0x009c);                  
        delay_ms(40);
        LCD_WriteReg(0x0013,0x1900);   
        LCD_WriteReg(0x0029,0x0023);
        LCD_WriteReg(0x002b,0x000e);
        delay_ms(40);
        LCD_WriteReg(0x0020,0x0000);                                                            
        LCD_WriteReg(0x0021,0x0000);           
///////////////////////////////////////////////////////      
        delay_ms(40);
        LCD_WriteReg(0x0030,0x0007); 
        LCD_WriteReg(0x0031,0x0707);   
        LCD_WriteReg(0x0032,0x0006);
        LCD_WriteReg(0x0035,0x0704);
        LCD_WriteReg(0x0036,0x1f04); 
        LCD_WriteReg(0x0037,0x0004);
        LCD_WriteReg(0x0038,0x0000);        
        LCD_WriteReg(0x0039,0x0706);     
        LCD_WriteReg(0x003c,0x0701);
        LCD_WriteReg(0x003d,0x000f);
        delay_ms(40);
        LCD_WriteReg(0x0050,0x0000);        
        LCD_WriteReg(0x0051,0x00ef);   
        LCD_WriteReg(0x0052,0x0000);     
        LCD_WriteReg(0x0053,0x013f);
        LCD_WriteReg(0x0060,0xa700);        
        LCD_WriteReg(0x0061,0x0001); 
        LCD_WriteReg(0x006a,0x0000);
        LCD_WriteReg(0x0080,0x0000);
        LCD_WriteReg(0x0081,0x0000);
        LCD_WriteReg(0x0082,0x0000);
        LCD_WriteReg(0x0083,0x0000);
        LCD_WriteReg(0x0084,0x0000);
        LCD_WriteReg(0x0085,0x0000);
      
        LCD_WriteReg(0x0090,0x0010);     
        LCD_WriteReg(0x0092,0x0000);  
        LCD_WriteReg(0x0093,0x0003);
        LCD_WriteReg(0x0095,0x0110);
        LCD_WriteReg(0x0097,0x0000);        
        LCD_WriteReg(0x0098,0x0000);  
        //display on sequence     
        LCD_WriteReg(0x0007,0x0133);
    
        LCD_WriteReg(0x0020,0x0000);                                                            
        LCD_WriteReg(0x0021,0x0000); 
  	}
 	else if(lcdid == 0x9325)
  	{
		LCD_WriteReg(0x00,0x0001);
		LCD_WriteReg(0x01,0x0100);
		LCD_WriteReg(0x02,0x0700);
		LCD_WriteReg(0x03,0x1018);
		LCD_WriteReg(0x04,0x0000);
		LCD_WriteReg(0x08,0x0202);
		LCD_WriteReg(0x09,0x0000);
		LCD_WriteReg(0x0A,0x0000);
		LCD_WriteReg(0x0C,0x0000);
		LCD_WriteReg(0x0D,0x0000);
		LCD_WriteReg(0x0F,0x0000);
		LCD_WriteReg(0x10,0x0000);
		LCD_WriteReg(0x11,0x0000);
		LCD_WriteReg(0x12,0x0000);
		LCD_WriteReg(0x13,0x0000);
		delay_ms(20);
		LCD_WriteReg(0x10,0x17B0);
		LCD_WriteReg(0x11,0x0137);
		delay_ms(5);
		LCD_WriteReg(0x12,0x0139);
		delay_ms(5);
		LCD_WriteReg(0x13,0x1d00);
		LCD_WriteReg(0x29,0x0013);
		delay_ms(5);
		LCD_WriteReg(0x20,0x0000);
		LCD_WriteReg(0x21,0x0000);
		LCD_WriteReg(0x30,0x0007);
		LCD_WriteReg(0x31,0x0302);
		LCD_WriteReg(0x32,0x0105);
		LCD_WriteReg(0x35,0x0206);
		LCD_WriteReg(0x36,0x0808);
		LCD_WriteReg(0x37,0x0206);
		LCD_WriteReg(0x38,0x0504);
		LCD_WriteReg(0x39,0x0007);
		LCD_WriteReg(0x3C,0x0105);
		LCD_WriteReg(0x3D,0x0808);
		LCD_WriteReg(0x50,0x0000);
		LCD_WriteReg(0x51,0x00EF);
		LCD_WriteReg(0x52,0x0000);
		LCD_WriteReg(0x53,0x013F);
		LCD_WriteReg(0x60,0xA700);
		LCD_WriteReg(0x61,0x0001);
		LCD_WriteReg(0x6A,0x0000);
		LCD_WriteReg(0x80,0x0000);
		LCD_WriteReg(0x81,0x0000);
		LCD_WriteReg(0x82,0x0000);
		LCD_WriteReg(0x83,0x0000);
		LCD_WriteReg(0x84,0x0000);
		LCD_WriteReg(0x85,0x0000);
		LCD_WriteReg(0x90,0x0010);
		LCD_WriteReg(0x92,0x0000);
		LCD_WriteReg(0x93,0x0003);
		LCD_WriteReg(0x95,0x0110);
		LCD_WriteReg(0x97,0x0000);
		LCD_WriteReg(0x98,0x0000);
		LCD_WriteReg(0x03,0x1018);
		LCD_WriteReg(0x07,0x0133);
  	}
  	else if(lcdid==0x4531)
  	{		
		LCD_WriteReg(0x00,0x0001);
		LCD_WriteReg(0x10,0x0628);
		LCD_WriteReg(0x12,0x0006);
		LCD_WriteReg(0x13,0x0A32);
		LCD_WriteReg(0x11,0x0040);
		LCD_WriteReg(0x15,0x0050);
		LCD_WriteReg(0x12,0x0016);
		delay_ms(15);
		LCD_WriteReg(0x10,0x5660);
		delay_ms(15);
		LCD_WriteReg(0x13,0x2A4E);
		LCD_WriteReg(0x01,0x0100);
		LCD_WriteReg(0x02,0x0300);	
		LCD_WriteReg(0x03,0x1018);
		LCD_WriteReg(0x08,0x0202);
		LCD_WriteReg(0x0A,0x0000);
		LCD_WriteReg(0x30,0x0000);
		LCD_WriteReg(0x31,0x0402);
		LCD_WriteReg(0x32,0x0106);
		LCD_WriteReg(0x33,0x0700);
		LCD_WriteReg(0x34,0x0104);
		LCD_WriteReg(0x35,0x0301);
		LCD_WriteReg(0x36,0x0707);
		LCD_WriteReg(0x37,0x0305);
		LCD_WriteReg(0x38,0x0208);
		LCD_WriteReg(0x39,0x0F0B);
		delay_ms(15);
		LCD_WriteReg(0x41,0x0002);
		LCD_WriteReg(0x60,0x2700);
		LCD_WriteReg(0x61,0x0001);
		LCD_WriteReg(0x90,0x0119);
		LCD_WriteReg(0x92,0x010A);
		LCD_WriteReg(0x93,0x0004);
		LCD_WriteReg(0xA0,0x0100);
		delay_ms(15);
		delay_ms(15);
		LCD_WriteReg(0x07,0x0133);
		delay_ms(15);
		LCD_WriteReg(0xA0,0x0000);
		delay_ms(20);
  	} 
	LCD_Clear(RED);
	LCD_Font(&Font16x24);
	LCD_Mode(4);							 
}
Exemplo n.º 14
0
void MyLCD_Init(void)
{ 
   	LCD_LineConf();
  	LCD_FSMCConf();
  	delay_ms(5); 
  	lcdid=LCD_ReadReg(0x00);  
		lcdid = 0x9341;
		if(lcdid == 0x9341)
		{
		LCD_WR_REG(0xEF);
		LCD_WR_Data (0x03);
		LCD_WR_Data(0x80);
		LCD_WR_Data (0X02);

		LCD_WR_REG(0xCF);
		LCD_WR_Data (0x00);
		LCD_WR_Data (0xBA);
		LCD_WR_Data (0XB0);

		LCD_WR_REG(0xED);
		LCD_WR_Data (0x67);
		LCD_WR_Data(0x03);
		LCD_WR_Data(0X12);
		LCD_WR_Data (0X81);

		LCD_WR_REG(0xE8);
		LCD_WR_Data (0x85);
		LCD_WR_Data (0x11);
		LCD_WR_Data (0x79);

		LCD_WR_REG(0xCB);
		LCD_WR_Data (0x39);
		LCD_WR_Data (0x2C);
		LCD_WR_Data (0x00);
		LCD_WR_Data (0x34);
		LCD_WR_Data (0x06);

		LCD_WR_REG(0xF7);
		LCD_WR_Data (0x20);

		LCD_WR_REG(0xEA);
		LCD_WR_Data (0x00);
		LCD_WR_Data (0x00);

		LCD_WR_REG(0xC0); //Power control
		LCD_WR_Data (0x1D); //VRH[5:0]

		LCD_WR_REG(0xC1); //Power control
		LCD_WR_Data (0x12); //SAP[2:0];BT[3:0]

		LCD_WR_REG(0xC5); //VCM control
		LCD_WR_Data (0x44);
		LCD_WR_Data(0x3c);

		LCD_WR_REG(0xC7); //VCM control
		LCD_WR_Data (0x9E);

		LCD_WR_REG(0x3A); // Memory Access Control
		LCD_WR_Data (0x55);

		LCD_WR_REG(0x36); // Memory Access Control
		LCD_WR_Data (0x48);

		LCD_WR_REG(0xB1);
		LCD_WR_Data (0x00);
		LCD_WR_Data (0x17);

		LCD_WR_REG(0xB6); // Display Function Control
		LCD_WR_Data (0x0A);
		LCD_WR_Data(0x82);//A2	

		LCD_WR_REG(0xF2); // 3Gamma Function Disable
		LCD_WR_Data (0x00);

		LCD_WR_REG(0x26); //Gamma curve selected
		LCD_WR_Data (0x01);

		LCD_WR_REG(0xE0); //Set Gamma
		LCD_WR_Data (0x0F);
		LCD_WR_Data (0x22);
		LCD_WR_Data(0x1C);
		LCD_WR_Data (0x1B);
		LCD_WR_Data(0x08);
		LCD_WR_Data(0x0F);
		LCD_WR_Data (0x48);
		LCD_WR_Data(0xB8);
		LCD_WR_Data (0x34);
		LCD_WR_Data(0x05);
		LCD_WR_Data (0x0C);
		LCD_WR_Data(0x09);
		LCD_WR_Data(0x0F);
		LCD_WR_Data (0x07);
		LCD_WR_Data(0x00);

		LCD_WR_REG(0XE1); //Set Gamma
		LCD_WR_Data (0x00);
		LCD_WR_Data (0x23);
		LCD_WR_Data (0x24);
		LCD_WR_Data (0x07);
		LCD_WR_Data (0x10);
		LCD_WR_Data (0x07);
		LCD_WR_Data (0x38);
		LCD_WR_Data (0x47);
		LCD_WR_Data (0x4B);
		LCD_WR_Data (0x0A);
		LCD_WR_Data (0x13);
		LCD_WR_Data (0x06);
		LCD_WR_Data (0x30);
		LCD_WR_Data (0x38);
		LCD_WR_Data (0x0F);
		LCD_WR_REG(0x11); //Exit Sleep
		delay_ms(500);
		LCD_WR_REG(0x29); //Display on
		LCD_Mode(0);	
		LCD_WR_REG(0x2c);
		}					 
}
Exemplo n.º 15
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 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);
}