Example #1
0
/*********************************************************************
* Function:  void ResetDevice()
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: none
*
* Overview: resets LCD, initializes PMP
*
* Note: none
*
********************************************************************/
void ResetDevice(void)
{
    WORD counter;
    
    // Initialize the device
    DriverInterfaceInit();
    
    // Enable LCD
    DisplayEnable();

    DelayMs(10);

    // Clear text layer
    SetAddress(0);
    for(counter = 0; counter < 0x4b0; counter++)
    {
        DeviceWrite(0x07);
		DeviceWrite(0x07);
    }

    // Disable LCD
    DisplayDisable();

    DelayMs(20);
}
Example #2
0
/*********************************************************************
* Function:  void ResetDevice()
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: none
*
* Overview: resets LCD, initializes PMP
*
* Note: none
*
********************************************************************/
void ResetDevice(void)
{
    // Set FLASH CS pin as output
    DisplayFlashConfig();

    // Initialize the device
	DriverInterfaceInit();

    DelayMs(5);

    // Power on LCD
    DisplayPowerOn();
    DisplayPowerConfig();

    DelayMs(2);

    #if defined (GFX_USE_DISPLAY_CONTROLLER_LGDP4531)

    /////////////////////////////////////////////////////////
    // Synchronization after reset
    DisplayEnable();
    DeviceWrite(0);
    DeviceWrite(0);
    DisplayDisable();

    // Setup display
    SetReg(0x0010, 0x0628);
    SetReg(0x0012, 0x0006);
    SetReg(0x0013, 0x0A32);
    SetReg(0x0011, 0x0040);
    SetReg(0x0015, 0x0050);
    SetReg(0x0012, 0x0016);
    DelayMs(15);
    SetReg(0x0010, 0x5660);
    DelayMs(15);
    SetReg(0x0013, 0x2A4E);
    SetReg(0x0001, 0x0100);
    SetReg(0x0002, 0x0300);

        #if (DISP_ORIENTATION == 0)
    SetReg(0x0003, 0x1030);
        #else
    SetReg(0x0003, 0x1038);
        #endif
    SetReg(0x0008, 0x0202);
    SetReg(0x000A, 0x0000);
    SetReg(0x0030, 0x0000);
    SetReg(0x0031, 0x0402);
    SetReg(0x0032, 0x0106);
    SetReg(0x0033, 0x0700);
    SetReg(0x0034, 0x0104);
    SetReg(0x0035, 0x0301);
    SetReg(0x0036, 0x0707);
    SetReg(0x0037, 0x0305);
    SetReg(0x0038, 0x0208);
    SetReg(0x0039, 0x0F0B);
    DelayMs(15);
    SetReg(0x0041, 0x0002);
    SetReg(0x0060, 0x2700);
    SetReg(0x0061, 0x0001);
    SetReg(0x0090, 0x0119);
    SetReg(0x0092, 0x010A);
    SetReg(0x0093, 0x0004);
    SetReg(0x00A0, 0x0100);
    SetReg(0x0007, 0x0001);
    DelayMs(15);
    SetReg(0x0007, 0x0021);
    DelayMs(15);
    SetReg(0x0007, 0x0023);
    DelayMs(15);
    SetReg(0x0007, 0x0033);
    DelayMs(15);
    SetReg(0x0007, 0x0133);
    DelayMs(15);
    SetReg(0x00A0, 0x0000);
    DelayMs(20);

    /////////////////////////////////////////////////////////
    #elif defined (GFX_USE_DISPLAY_CONTROLLER_R61505)

    // Setup display
    SetReg(0x0000, 0x0000);
    SetReg(0x0007, 0x0001);
    DelayMs(5);
    SetReg(0x0017, 0x0001);
    DelayMs(5);
    SetReg(0x0010, 0x17b0);
    SetReg(0x0011, 0x0007);
    SetReg(0x0012, 0x011a);
    SetReg(0x0013, 0x0f00);
    SetReg(0x0015, 0x0000);
    SetReg(0x0029, 0x0009);
    SetReg(0x00fd, 0x0000);
    DelayMs(5);
    SetReg(0x0012, 0x013a);
    DelayMs(50);
    SetReg(0x0001, 0x0100);
    SetReg(0x0002, 0x0700);

        #if (DISP_ORIENTATION == 0)
    SetReg(0x0003, 0x1030);
        #else
    SetReg(0x0003, 0x1038);
        #endif
    SetReg(0x0008, 0x0808);
    SetReg(0x0009, 0x0000);
    SetReg(0x000a, 0x0000);
    SetReg(0x000c, 0x0000);
    SetReg(0x000d, 0x0000);
    SetReg(0x0030, 0x0000);
    SetReg(0x0031, 0x0000);
    SetReg(0x0032, 0x0000);
    SetReg(0x0033, 0x0000);
    SetReg(0x0034, 0x0000);
    SetReg(0x0035, 0x0000);
    SetReg(0x0036, 0x0000);
    SetReg(0x0037, 0x0707);
    SetReg(0x0038, 0x0707);
    SetReg(0x0039, 0x0707);
    SetReg(0x003a, 0x0303);
    SetReg(0x003b, 0x0303);
    SetReg(0x003c, 0x0707);
    SetReg(0x003d, 0x0808);
    SetReg(0x0050, 0x0000);
    SetReg(0x0051, 0x00ef);
    SetReg(0x0052, 0x0000);
    SetReg(0x0053, 0x013f);
    SetReg(0x0060, 0x2700);
    SetReg(0x0061, 0x0001);
    SetReg(0x006a, 0x0000);
    SetReg(0x0090, 0x0010);
    SetReg(0x0092, 0x0000);
    SetReg(0x0093, 0x0000);
    SetReg(0x0007, 0x0021);
    DelayMs(1);
    SetReg(0x0007, 0x0061);
    DelayMs(50);
    SetReg(0x0007, 0x0173);
    SetReg(0x0020, 0x0000);
    SetReg(0x0021, 0x0000);
    SetReg(0x0022, 0x0000);
    SetReg(0x0030, 0x0707);
    SetReg(0x0031, 0x0407);
    SetReg(0x0032, 0x0203);
    SetReg(0x0033, 0x0303);
    SetReg(0x0034, 0x0303);
    SetReg(0x0035, 0x0202);
    SetReg(0x0036, 0x001f);
    SetReg(0x0037, 0x0707);
    SetReg(0x0038, 0x0407);
    SetReg(0x0039, 0x0203);
    SetReg(0x003a, 0x0303);
    SetReg(0x003b, 0x0303);
    SetReg(0x003c, 0x0202);
    SetReg(0x003d, 0x001f);
    SetReg(0x0020, 0x0000);
    SetReg(0x0021, 0x0000);

    /////////////////////////////////////////////////////////
    #elif defined (GFX_USE_DISPLAY_CONTROLLER_S6D0129) || defined (GFX_USE_DISPLAY_CONTROLLER_S6D0139)

    // Setup display
    SetReg(0x0000, 0x0001);
    SetReg(0x0011, 0x1a00);
    SetReg(0x0014, 0x2020);
    SetReg(0x0010, 0x0900);
    SetReg(0x0013, 0x0040);
    SetReg(0x0013, 0x0060);
    SetReg(0x0013, 0x0070);
    SetReg(0x0011, 0x1a04);
    SetReg(0x0010, 0x2f00);
    SetReg(0x0001, 0x0127);
    SetReg(0x0002, 0x0700);

        #if (DISP_ORIENTATION == 0)
    SetReg(0x0003, 0x1030);
        #else
    SetReg(0x0003, 0x1038);
        #endif
    SetReg(0x0007, 0x0000);
    SetReg(0x0008, 0x0808);
    SetReg(0x0009, 0x0000);
    SetReg(0x000b, 0x0000);
    SetReg(0x000c, 0x0000);
    SetReg(0x0040, 0x0000);
    SetReg(0x0041, 0x0000);
    SetReg(0x0042, 0x013f);
    SetReg(0x0043, 0x0000);
    SetReg(0x0044, 0x00ef);
    SetReg(0x0045, 0x0000);
    SetReg(0x0046, 0xef00);
    SetReg(0x0047, 0x013f);
    SetReg(0x0048, 0x0000);
    SetReg(0x0007, 0x0014);
    SetReg(0x0007, 0x0016);
    SetReg(0x0007, 0x0017);
    SetReg(0x0020, 0x0000);
    SetReg(0x0021, 0x0000);
    SetReg(0x0022, 0x0000);

    /////////////////////////////////////////////////////////
    #elif defined (GFX_USE_DISPLAY_CONTROLLER_SPFD5408)

    // Setup display
    SetReg(0x0000, 0x0000);
    SetReg(0x0001, 0x0000);
    SetReg(0x0002, 0x0700);

        #if (DISP_ORIENTATION == 0)
    SetReg(0x0003, 0x1010);
        #else
    SetReg(0x0003, 0x1028);
        #endif
    SetReg(0x0004, 0x0000);
    SetReg(0x0008, 0x0207);
    SetReg(0x0009, 0x0000);
    SetReg(0x000a, 0x0000);
    SetReg(0x000c, 0x0000);
    SetReg(0x000d, 0x0000);
    SetReg(0x000f, 0x0000);
    SetReg(0x0007, 0x0101);
    SetReg(0x0010, 0x12b0);
    SetReg(0x0011, 0x0007);
    SetReg(0x0017, 0x0001);
    SetReg(0x0012, 0x01bb);
    SetReg(0x0013, 0x1300);
    SetReg(0x0029, 0x0010);

    SetReg(0x0030, 0x0100);
    SetReg(0x0031, 0x0c19);
    SetReg(0x0032, 0x111e);
    SetReg(0x0033, 0x3819);
    SetReg(0x0034, 0x350b);
    SetReg(0x0035, 0x0e08);
    SetReg(0x0036, 0x0d07);
    SetReg(0x0037, 0x0318);
    SetReg(0x0038, 0x0705);
    SetReg(0x0039, 0x0303);
    SetReg(0x003a, 0x0905);
    SetReg(0x003b, 0x0801);
    SetReg(0x003c, 0x030e);
    SetReg(0x003d, 0x050d);
    SetReg(0x003e, 0x0106);
    SetReg(0x003f, 0x0408);

    SetReg(0x0050, 0x0000);
    SetReg(0x0051, 0x00ef);
    SetReg(0x0052, 0x0000);
    SetReg(0x0053, 0x013f);
    SetReg(0x0060, 0xa700);
    SetReg(0x0061, 0x0001);
    SetReg(0x006a, 0x0000);
    SetReg(0x0080, 0x0000);
    SetReg(0x0081, 0x0000);
    SetReg(0x0082, 0x0000);
    SetReg(0x0083, 0x0000);
    SetReg(0x0084, 0x0000);
    SetReg(0x0085, 0x0000);
    SetReg(0x0090, 0x0010);
    SetReg(0x0092, 0x0000);
    SetReg(0x0093, 0x0103);
    SetReg(0x0095, 0x0110);
    SetReg(0x0097, 0x0000);
    SetReg(0x0098, 0x0000);
    SetReg(0x00f0, 0x5408);
    SetReg(0x00f3, 0x0010);
    SetReg(0x00f4, 0x001f);
    SetReg(0x00f0, 0x0000);
    SetReg(0x0007, 0x0133);

    /////////////////////////////////////////////////////////
    #elif defined (GFX_USE_DISPLAY_CONTROLLER_ILI9320)
    SetReg(0x0000, 0x0001); //start Int. osc
    DelayMs(15);
    SetReg(0x0001, 0x0100); //Set SS bit (shift direction of outputs is from S720 to S1)
    SetReg(0x0002, 0x0700); //select  the line inversion
        #if (DISP_ORIENTATION == 0)
    SetReg(0x0003, 0x1030); //Entry mode(Horizontal : increment,Vertical : increment, AM=0)
        #else
    SetReg(0x0003, 0x1038); //Entry mode(Horizontal : increment,Vertical : increment, AM=1)
        #endif
    SetReg(0x0004, 0x0000); //Resize control(No resizing)
    SetReg(0x0008, 0x0202); //front and back porch 2 lines
    SetReg(0x0009, 0x0000); //select normal scan
    SetReg(0x000A, 0x0000); //display control 4
    SetReg(0x000C, 0x0000); //system interface(2 transfer /pixel), internal sys clock,  	
    SetReg(0x000D, 0x0000); //Frame marker position
    SetReg(0x000F, 0x0000); //selects clk, enable and sync signal polarity,
    SetReg(0x0010, 0x0000); //	
    SetReg(0x0011, 0x0000); //power control 2 reference voltages = 1:1,
    SetReg(0x0012, 0x0000); //power control 3 VRH
    SetReg(0x0013, 0x0000); //power control 4 VCOM amplitude
    DelayMs(20);
    SetReg(0x0010, 0x17B0); //power control 1 BT,AP
    SetReg(0x0011, 0x0137); //power control 2 DC,VC
    DelayMs(50);
    SetReg(0x0012, 0x0139); //power control 3 VRH
    DelayMs(50);
    SetReg(0x0013, 0x1d00); //power control 4 vcom amplitude
    SetReg(0x0029, 0x0011); //power control 7 VCOMH
    DelayMs(50);
    SetReg(0x0030, 0x0007);
    SetReg(0x0031, 0x0403);
    SetReg(0x0032, 0x0404);
    SetReg(0x0035, 0x0002);
    SetReg(0x0036, 0x0707);
    SetReg(0x0037, 0x0606);
    SetReg(0x0038, 0x0106);
    SetReg(0x0039, 0x0007);
    SetReg(0x003c, 0x0700);
    SetReg(0x003d, 0x0707);
    SetReg(0x0020, 0x0000); //starting Horizontal GRAM Address
    SetReg(0x0021, 0x0000); //starting Vertical GRAM Address
    SetReg(0x0050, 0x0000); //Horizontal GRAM Start Position
    SetReg(0x0051, 0x00EF); //Horizontal GRAM end Position
    SetReg(0x0052, 0x0000); //Vertical GRAM Start Position
    SetReg(0x0053, 0x013F); //Vertical GRAM end Position
    SetReg(0x0060, 0x2700); //starts scanning from G1, and 320 drive lines
    SetReg(0x0061, 0x0001); //fixed base display
    SetReg(0x006a, 0x0000); //no scroll
    SetReg(0x0090, 0x0010); //set Clocks/Line =16, Internal Operation Clock Frequency=fosc/1,
    SetReg(0x0092, 0x0000); //set gate output non-overlap period=0
    SetReg(0x0093, 0x0003); //set Source Output Position=3
    SetReg(0x0095, 0x0110); //RGB interface(Clocks per line period=16 clocks)
    SetReg(0x0097, 0x0110); //set Gate Non-overlap Period 0 locksc
    SetReg(0x0098, 0x0110); //
    SetReg(0x0007, 0x0173); //display On
    /////////////////////////////////////////////////////////
    #elif defined (GFX_USE_DISPLAY_CONTROLLER_R61580)

    // Synchronization after reset
    DelayMs(2);
    SetReg(0x0000, 0x0000);
    SetReg(0x0000, 0x0000);
    SetReg(0x0000, 0x0000);
    SetReg(0x0000, 0x0000);

    // Setup display
    SetReg(0x00A4, 0x0001); // CALB=1
    DelayMs(2);
    SetReg(0x0060, 0xA700); // Driver Output Control
    SetReg(0x0008, 0x0808); // Display Control BP=8, FP=8
    SetReg(0x0030, 0x0111); // y control
    SetReg(0x0031, 0x2410); // y control
    SetReg(0x0032, 0x0501); // y control
    SetReg(0x0033, 0x050C); // y control
    SetReg(0x0034, 0x2211); // y control
    SetReg(0x0035, 0x0C05); // y control
    SetReg(0x0036, 0x2105); // y control
    SetReg(0x0037, 0x1004); // y control
    SetReg(0x0038, 0x1101); // y control
    SetReg(0x0039, 0x1122); // y control
    SetReg(0x0090, 0x0019); // 80Hz
    SetReg(0x0010, 0x0530); // Power Control
    SetReg(0x0011, 0x0237);
    SetReg(0x0012, 0x01BF);
    SetReg(0x0013, 0x1300);
    DelayMs(100);

    SetReg(0x0001, 0x0100);
    SetReg(0x0002, 0x0200);
        #if (DISP_ORIENTATION == 0)
    SetReg(0x0003, 0x1030);
        #else
    SetReg(0x0003, 0x1038);
        #endif
    SetReg(0x0009, 0x0001);
    SetReg(0x000A, 0x0008);
    SetReg(0x000C, 0x0001);
    SetReg(0x000D, 0xD000);
    SetReg(0x000E, 0x0030);
    SetReg(0x000F, 0x0000);
    SetReg(0x0020, 0x0000);
    SetReg(0x0021, 0x0000);
    SetReg(0x0029, 0x0077);
    SetReg(0x0050, 0x0000);
    SetReg(0x0051, 0xD0EF);
    SetReg(0x0052, 0x0000);
    SetReg(0x0053, 0x013F);
    SetReg(0x0061, 0x0001);
    SetReg(0x006A, 0x0000);
    SetReg(0x0080, 0x0000);
    SetReg(0x0081, 0x0000);
    SetReg(0x0082, 0x005F);
    SetReg(0x0093, 0x0701);
    SetReg(0x0007, 0x0100);
    SetReg(0x0022, 0x0000);
    #else
        #error Graphics controller is not supported.
    #endif
    DelayMs(20);
}
Example #3
0
/*********************************************************************
* Function:  void ResetDevice()
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: none
*
* Overview: resets LCD, initializes PMP
*
* Note: none
*
********************************************************************/
void ResetDevice(void)
{
	// Initialize device
	DriverInterfaceInit();

    DelayMs(20);
    DisplayEnable();
	
	DisplaySetCommand();
    DeviceWrite(EXTIN);        //Ext = 0
    DeviceWrite(SLPOUT);       //Sleep Out
    DeviceWrite(OSCON);        //OSC On
    DeviceWrite(PWRCTRL);      //Power Control Set
	DisplaySetData();
    DeviceWrite(0x08);        //Booster Must Be On First
    DelayMs(2);
	DisplaySetCommand();
    DeviceWrite(0x20);         //Power Control Set
	DisplaySetData();
    DeviceWrite(0x0B);        //Booster, Regulator, Follower ON
	DisplaySetCommand();
    DeviceWrite(VOLCTRL);      //Electronic Control
	DisplaySetData();
    DeviceWrite(0x3f);        //Vop=18.0V
    DeviceWrite(0x04);
	DisplaySetCommand();
    DeviceWrite(DISCTRL);      //Display Control
	DisplaySetData();
    DeviceWrite(0x00);        //CL=X1
    DeviceWrite(0x27);        //Duty=160
    DeviceWrite(0x00);        //FR Inverse-Set Value
	DisplaySetCommand();
    DeviceWrite(DISNOR);       // Normal Display
    DeviceWrite(COMSCN);       //COM Scan Direction
	DisplaySetData();
    DeviceWrite(0x01);        // 0->79 159->80
	DisplaySetCommand();
    DeviceWrite(DATSDR);       //Data Scan Direction
	DisplaySetData();
    #if (DISP_ORIENTATION == 180)
    DeviceWrite(0x01);        //Row Reverse
    DeviceWrite(0x00);        //Derect 3 Pixels Arrangement
    #else
    DeviceWrite(0x02);        //Column Reverse
    DeviceWrite(0x01);        //Inverse 3 Pixels Arrangement
    #endif
    DeviceWrite(0x02);        //3Byte 3Pixel mode
	DisplaySetCommand();
    DeviceWrite(LASET);        //Line Address Set(lines from 16 to 144 are used)
	DisplaySetData();
    DeviceWrite(0x10);        //Start Line=16
    DeviceWrite(0x8f);        //End Line =144-1
	DisplaySetCommand();
    DeviceWrite(CASET);        //Column Address Set
	DisplaySetData();
    DeviceWrite(0x00);        //Start Column=0
    DeviceWrite(0x54);        //End Column =84 ((84+1)*3 == 255)
	DisplaySetCommand();
    DeviceWrite(EXTOUT);       //Ext = 1
    DeviceWrite(ANASET);       //Analog Circuit Set
	DisplaySetData();
    DeviceWrite(0x00);        //OSC Frequency =000 (Default)
    DeviceWrite(0x01);        //Booster Efficiency=01(Default)
    DeviceWrite(0x00);        //Bias=1/14
	DisplaySetCommand();
    DeviceWrite(SWINT);        //Software Initial
    DeviceWrite(EXTIN);        //Ext = 0
    DeviceWrite(DISON);        //Display On
    DisplayDisable();
	DisplaySetData();
    DelayMs(100);
}
Example #4
0
/*********************************************************************
* Function:  void ResetDevice()
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: none
*
* Overview: resets LCD, initializes PMP
*
* Note: none
*
********************************************************************/
void ResetDevice(void)
{

    // Initialize the device
	DriverInterfaceInit();


    // Setup display
    #if defined (GFX_USE_DISPLAY_CONTROLLER_SSD1289)
    
    /////////////////////////////////////////////////////////
    SetReg(0x00, 0x0001);
    SetReg(0x03, 0xAAAC);
    SetReg(0x0C, 0x0002);
    DelayMs(15);
    SetReg(0x0D, 0x000A);
    SetReg(0x0E, 0x2D00);
    SetReg(0x1E, 0x00BC);

    SetReg(0x01, 0x1A0C);

    DelayMs(15);
        #if (DISP_ORIENTATION == 0)
    SetReg(0x01, 0x2B3F);
        #else
    SetReg(0x01, 0x293F);
        #endif
    SetReg(0x02, 0x0600);
    SetReg(0x10, 0x0000);

        #if (DISP_ORIENTATION == 0)
    SetReg(0x11, 0x60B0);
        #else
    SetReg(0x11, 0x60B8);
        #endif
    SetReg(0x05, 0x0000);
    SetReg(0x06, 0x0000);
    DelayMs(100);
    SetReg(0x16, 0xEF1C);
    SetReg(0x17, 0x0003);
    SetReg(0x07, 0x0233);
    SetReg(0x0B, 0x0000);
    SetReg(0x0F, 0x0000);
    SetReg(0x41, 0x0000);
    SetReg(0x42, 0x0000);
    SetReg(0x48, 0x0000);
    SetReg(0x49, 0x013F);
    SetReg(0x44, 0xEF00);
    SetReg(0x45, 0x0000);
    SetReg(0x46, 0x013F);
    SetReg(0x4A, 0x0000);
    SetReg(0x4B, 0x0000);
    SetReg(0x30, 0x0707);
    SetReg(0x31, 0x0704);
    SetReg(0x32, 0x0204);
    SetReg(0x33, 0x0502);
    SetReg(0x34, 0x0507);
    SetReg(0x35, 0x0204);
    SetReg(0x36, 0x0204);
    SetReg(0x37, 0x0502);
    SetReg(0x3A, 0x0302);
    SetReg(0x3B, 0x1f00);
    SetReg(0x23, 0x0000);
    SetReg(0x24, 0x0000);

    #elif defined (GFX_USE_DISPLAY_CONTROLLER_SSD2119)
    
    SetReg(0x0028, 0x0006); // VCOM OTP, page 55-56 of datasheet
    SetReg(0x0000, 0x0001); // start Oscillator, page 36 of datasheet
    SetReg(0x0010, 0x0000); // Sleep mode, page 49 of datasheet
        #if (DISP_ORIENTATION == 0)
    SetReg(0x0001, 0x72EF); // Driver Output Control, page 36-39 of datasheet
        #else
    SetReg(0x0001, 0x32EF); // Driver Output Control, page 36-39 of datasheet
        #endif
    SetReg(0x0002, 0x0600); // LCD Driving Waveform Control, page 40-42 of datasheet
    SetReg(0x0003, 0x6A38); // Power Control 1, page 43-44 of datasheet
        #if (DISP_ORIENTATION == 0)
    SetReg(0x0011, 0x6870); // Entry Mode, page 50-52 of datasheet
        #else
    SetReg(0x0011, 0x6878); // Entry Mode, page 50-52 of datasheet
        #endif
    SetReg(0x000F, 0x0000); // Gate Scan Position, page 49 of datasheet
    SetReg(0x000B, 0x5308); // Frame Cycle Control, page 45 of datasheet
    SetReg(0x000C, 0x0003); // Power Control 2, page 47 of datasheet
    SetReg(0x000D, 0x000A); // Power Control 3, page 48 of datasheet
    SetReg(0x000E, 0x2E00); // Power Control 4, page 48 of datasheet
    SetReg(0x001E, 0x00BE); // Power Control 5, page 53 of datasheet
    SetReg(0x0025, 0x8000); // Frame Frequency Control, page 53 of datasheet
    SetReg(0x0026, 0x7800); // Analog setting, page 54 of datasheet
    SetReg(0x004E, 0x0000); // Ram Address Set, page 58 of datasheet
    SetReg(0x004F, 0x0000); // Ram Address Set, page 58 of datasheet
    SetReg(0x0012, 0x08D9); // Sleep mode, page 49 of datasheet

    // Gamma Control (R30h to R3Bh) -- page 56 of datasheet
    SetReg(0x0030, 0x0000);
    SetReg(0x0031, 0x0104);
    SetReg(0x0032, 0x0100);
    SetReg(0x0033, 0x0305);
    SetReg(0x0034, 0x0505);
    SetReg(0x0035, 0x0305);
    SetReg(0x0036, 0x0707);
    SetReg(0x0037, 0x0300);
    SetReg(0x003A, 0x1200);
    SetReg(0x003B, 0x0800);

    SetReg(0x0007, 0x0033); // Display Control, page 45 of datasheet
    #endif
    DelayMs(50);
}
void ResetDevice()
{
/*  SetLCDPorts();
  Init_MCU();*/
	// Initialize the device
	DriverInterfaceInit();
	DelayMs(1);				// Delay to let controller ready for next SetReg command

/*  LCD_nRESET = 1;
DelayMs(1); // Delay 1ms
LCD_nRESET = 0;
DelayMs(10); // Delay 10ms // This delay time is necessary
LCD_nRESET = 1;
DelayMs(120); // Delay 120 ms*/

  ResetLCD();

LCD_ILI9341_CMD(PowerControlB);        //Power control B (CFh)
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x81);
LCD_ILI9341_Parameter(0X30);

LCD_ILI9341_CMD(PowerOnSequenceControl);
LCD_ILI9341_Parameter(0x64);
LCD_ILI9341_Parameter(0x03);
LCD_ILI9341_Parameter(0X12);
LCD_ILI9341_Parameter(0X81);

LCD_ILI9341_CMD(DriverTimingControlA);
LCD_ILI9341_Parameter(0x85);
LCD_ILI9341_Parameter(0x10);
LCD_ILI9341_Parameter(0x78);

LCD_ILI9341_CMD(PowerControlA);
LCD_ILI9341_Parameter(0x39);
LCD_ILI9341_Parameter(0x2C);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x34);
LCD_ILI9341_Parameter(0x02);

LCD_ILI9341_CMD(PumpRatioControl);
LCD_ILI9341_Parameter(0x20);

LCD_ILI9341_CMD(DriverTimingControlB);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x00);

LCD_ILI9341_CMD(FrameRateControlInNormalModeFullColors);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x1B);

LCD_ILI9341_CMD(DisplayFunctionControl);        // Display Function Control
LCD_ILI9341_Parameter(0x0A);
LCD_ILI9341_Parameter(0xA2);

LCD_ILI9341_CMD(PowerControl1);         //Power control
LCD_ILI9341_Parameter(0x21);            //VRH[5:0]

LCD_ILI9341_CMD(PowerControl2);         //Power control
LCD_ILI9341_Parameter(0x11);            //SAP[2:0];BT[3:0]

LCD_ILI9341_CMD(VCOMControl1);          //VCM control
LCD_ILI9341_Parameter(0x3F);
LCD_ILI9341_Parameter(0x3C);

LCD_ILI9341_CMD(VCOMControl2);          //VCM control2
LCD_ILI9341_Parameter(0Xb5);

LCD_ILI9341_CMD(PixelFormatSet);

#if defined (_64K_COLOR_MODE)
LCD_ILI9341_Parameter(BITPERPIXEL16);
#elif defined (_256K_COLOR_MODE)
LCD_ILI9341_Parameter(BITPERPIXEL18);
#endif

LCD_ILI9341_CMD(MemoryAccessControl);        // Memory Access Control
LCD_ILI9341_Parameter(RGBSET | MVSET | MXSET);

LCD_ILI9341_CMD(InterfaceControl);        // Memory Access Control
LCD_ILI9341_Parameter(0x01);
#if defined (_MDT00)
LCD_ILI9341_Parameter(MDT00);
#elif defined (_MDT01)
LCD_ILI9341_Parameter(MDT01);
#else
#error "You must define the MDT parameter !"
#endif

LCD_ILI9341_Parameter(0x00);

LCD_ILI9341_CMD(Enable3G);              // 3Gamma Function Disable
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_CMD(GammaSet);              //Gamma curve selected
LCD_ILI9341_Parameter(0x01);

LCD_ILI9341_CMD(PositiveGammaCorrection);        //Set Gamma
LCD_ILI9341_Parameter(0x0F);
LCD_ILI9341_Parameter(0x26);
LCD_ILI9341_Parameter(0x24);
LCD_ILI9341_Parameter(0x0B);
LCD_ILI9341_Parameter(0x0E);
LCD_ILI9341_Parameter(0x09);
LCD_ILI9341_Parameter(0x54);
LCD_ILI9341_Parameter(0XA8);
LCD_ILI9341_Parameter(0x46);
LCD_ILI9341_Parameter(0x0C);
LCD_ILI9341_Parameter(0x17);
LCD_ILI9341_Parameter(0x09);
LCD_ILI9341_Parameter(0x0F);
LCD_ILI9341_Parameter(0x07);
LCD_ILI9341_Parameter(0x00);

LCD_ILI9341_CMD(NegativeGammaCorrection);        //Set Gamma
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x19);
LCD_ILI9341_Parameter(0x1B);
LCD_ILI9341_Parameter(0x04);
LCD_ILI9341_Parameter(0x10);
LCD_ILI9341_Parameter(0x07);
LCD_ILI9341_Parameter(0x2A);
LCD_ILI9341_Parameter(0x47);
LCD_ILI9341_Parameter(0x39);
LCD_ILI9341_Parameter(0x03);
LCD_ILI9341_Parameter(0x06);
LCD_ILI9341_Parameter(0x06);
LCD_ILI9341_Parameter(0x30);
LCD_ILI9341_Parameter(0x38);
LCD_ILI9341_Parameter(0x0F);

//lcdSetWindow(10, 230 - 1, 10, 310 - 1);

LCD_ILI9341_CMD(SleepOut);        //Exit Sleep
DelayMs(120);
//delayms(120);
LCD_ILI9341_CMD(0x29);        //Display on

DisplayBacklightOn();

}