/*
Resolution:360X360
Frame rate:59.88HZ
Power:VCI=3.3V, IOVCC=3.3V
*/
void Init_LCD(void)
{
/********Reset Sequence Start************/
LCD_Reset = 1;
delayms(50);
LCD_Reset = 0;
delayms(50);
LCD_Reset = 1;
delayms(120);
/********Reset Sequence End************/
LCD_CtrlWrite(0xFE);
LCD_CtrlWrite(0xEF);

//////
LCD_CtrlWrite(0x80);
LCD_DataWrite(0x19);
LCD_CtrlWrite(0x82);
LCD_DataWrite(0x09);
LCD_CtrlWrite(0x83);
LCD_DataWrite(0x03);
LCD_CtrlWrite(0x88);
LCD_DataWrite(0x00);
LCD_CtrlWrite(0x89);
LCD_DataWrite(0x38);
LCD_CtrlWrite(0x8A);
LCD_DataWrite(0x40);
LCD_CtrlWrite(0x8B);
LCD_DataWrite(0x0A);
LCD_CtrlWrite(0x8C);
LCD_DataWrite(0x00);
//-------------------------??-------------------------
//OTP???????
LCD_CtrlWrite(0x81);
LCD_DataWrite(0xFF);
LCD_CtrlWrite(0x84);
LCD_DataWrite(0xFF);
LCD_CtrlWrite(0x85);
LCD_DataWrite(0xFF);
LCD_CtrlWrite(0x86);
LCD_DataWrite(0xFF);
LCD_CtrlWrite(0x87);
LCD_DataWrite(0xFF);
LCD_CtrlWrite(0x8E);
LCD_DataWrite(0xFF);
LCD_CtrlWrite(0x8F);
LCD_DataWrite(0xFF);
//BVDDEE????
LCD_CtrlWrite(0x98);
LCD_DataWrite(0x3E);
LCD_CtrlWrite(0x99);
LCD_DataWrite(0x3E);
//VGH??
LCD_CtrlWrite(0x7D);
LCD_DataWrite(0x72);

//CHP CLK??
LCD_CtrlWrite(0x70);
LCD_DataWrite(0x02);
LCD_DataWrite(0x03);
LCD_DataWrite(0x03);
LCD_DataWrite(0x06);
LCD_DataWrite(0x03);
LCD_DataWrite(0x03);
LCD_DataWrite(0x09);
LCD_DataWrite(0x07);
LCD_DataWrite(0x09);
LCD_DataWrite(0x03);
//BVDDEE CLK??
LCD_CtrlWrite(0x90);
LCD_DataWrite(0x06);
LCD_DataWrite(0x06);
LCD_DataWrite(0x01);
LCD_DataWrite(0x01);
LCD_CtrlWrite(0x93);
LCD_DataWrite(0x02);
LCD_DataWrite(0xFF);
LCD_DataWrite(0x00);
LCD_CtrlWrite(0xCB);
LCD_DataWrite(0x02);//

//Source Chop??
LCD_CtrlWrite(0xFB);
LCD_DataWrite(0x00);
LCD_DataWrite(0x00);
//??????
LCD_CtrlWrite(0xF6);
LCD_DataWrite(0xC0);
//Gate????
LCD_CtrlWrite(0x6C);
LCD_DataWrite(0x00);
LCD_DataWrite(0x00);
LCD_DataWrite(0x22);
LCD_DataWrite(0x00);
LCD_DataWrite(0xCC);
LCD_DataWrite(0x04);
LCD_DataWrite(0x58);
LCD_CtrlWrite(0xAA);
LCD_DataWrite(0x0B);
LCD_DataWrite(0x00);
//------------------------------------------------------//

//-------------------------??-------------------------
//??????
LCD_CtrlWrite(0xEC);
LCD_DataWrite(0x07);//fw:07 bw:87
//Source ???????,????????
LCD_CtrlWrite(0xF9);
LCD_DataWrite(0x40);
//Gate ?????
LCD_CtrlWrite(0xEB);
LCD_DataWrite(0x01);
LCD_DataWrite(0x67);
//RTN??
LCD_CtrlWrite(0x74);
LCD_DataWrite(0x01);//160
LCD_DataWrite(0x60);
LCD_DataWrite(0x00);
LCD_DataWrite(0x00);
LCD_DataWrite(0x00);
LCD_DataWrite(0x00);
//??VBP&VFP&HBP??
LCD_CtrlWrite(0xB5);
LCD_DataWrite(0x14);
LCD_DataWrite(0x14);
LCD_DataWrite(0x14);

//GOA??
LCD_CtrlWrite(0x6E);//Mapping
LCD_DataWrite(0x0B);//0B
LCD_DataWrite(0x0B);//0B
LCD_DataWrite(0x09);//09//
LCD_DataWrite(0x09);//09
LCD_DataWrite(0x13);
LCD_DataWrite(0x13);
LCD_DataWrite(0x11);
LCD_DataWrite(0x11);
LCD_DataWrite(0x16);//15 gout9
LCD_DataWrite(0x15);//16 gout10
LCD_DataWrite(0x01);//01
LCD_DataWrite(0x04);//04
LCD_DataWrite(0x00);//00
LCD_DataWrite(0x0D);//
LCD_DataWrite(0x1D);
LCD_DataWrite(0x00);//00
LCD_DataWrite(0x00);
LCD_DataWrite(0x1D);
LCD_DataWrite(0x0D);//
LCD_DataWrite(0x00);
LCD_DataWrite(0x04);
LCD_DataWrite(0x08);
LCD_DataWrite(0x15);//16  gout23
LCD_DataWrite(0x16);//15  gout24
LCD_DataWrite(0x12);
LCD_DataWrite(0x12);
LCD_DataWrite(0x14);
LCD_DataWrite(0x14);
LCD_DataWrite(0x0A);
LCD_DataWrite(0x0A);
LCD_DataWrite(0x0C);
LCD_DataWrite(0x0C);

LCD_CtrlWrite(0x60);//STV1->panel_STV1
LCD_DataWrite(0x38);
LCD_DataWrite(0x1C);
LCD_DataWrite(0x13);
LCD_DataWrite(0x56);

LCD_CtrlWrite(0x61);//STV4->panel_STV0
LCD_DataWrite(0xF8);
LCD_DataWrite(0x0A);
LCD_DataWrite(0x13);
LCD_DataWrite(0x56);

LCD_CtrlWrite(0x62);//STV5->panel_STV0 BW
LCD_DataWrite(0xF8);
LCD_DataWrite(0x0B);
LCD_DataWrite(0x13);
LCD_DataWrite(0x56);

LCD_CtrlWrite(0x63);//STV8->panel_STV2
LCD_DataWrite(0x38);
LCD_DataWrite(0x1C);
LCD_DataWrite(0x13);
LCD_DataWrite(0x56);



LCD_CtrlWrite(0x64);//CLK1->panel_CLK5
LCD_DataWrite(0x38);
LCD_DataWrite(0x20);//1E
LCD_DataWrite(0x72);
LCD_DataWrite(0xF8);
LCD_DataWrite(0x13);
LCD_DataWrite(0x56);

LCD_CtrlWrite(0x65);//CLK5->panel_VDS
LCD_DataWrite(0x78);
LCD_DataWrite(0x1A);
LCD_DataWrite(0x70);
LCD_DataWrite(0x0B);
LCD_DataWrite(0x56);
LCD_DataWrite(0x13);

LCD_CtrlWrite(0x66);//CLK9->panel_CLK1
LCD_DataWrite(0x38);
LCD_DataWrite(0x24);//22
LCD_DataWrite(0x72);
LCD_DataWrite(0xFC);
LCD_DataWrite(0x13);
LCD_DataWrite(0x56);


LCD_CtrlWrite(0x68);//FLC12
LCD_DataWrite(0xB3);
LCD_DataWrite(0x08);//2F0
LCD_DataWrite(0x0E);
LCD_DataWrite(0x08);
LCD_DataWrite(0x0E);
LCD_DataWrite(0x0A);
LCD_DataWrite(0x0A);

LCD_CtrlWrite(0x69);//FLC34
LCD_DataWrite(0xB3);
LCD_DataWrite(0x08);//2F0
LCD_DataWrite(0x0E);
LCD_DataWrite(0x08);
LCD_DataWrite(0x0E);
LCD_DataWrite(0x0A);
LCD_DataWrite(0x0A);

LCD_CtrlWrite(0x6A);
LCD_DataWrite(0x00);
LCD_DataWrite(0x00);
//------------------------------------------------------//


//-------------------------??-------------------------//
//RGB??????
LCD_CtrlWrite(0x3a);
LCD_DataWrite(0x05);
//??????
LCD_CtrlWrite(0x36);
LCD_DataWrite(0x00);////

//LCD_CtrlWrite(0xb6);
//LCD_DataWrite(0x00);//////
//LCD_DataWrite(0x60);//////
//VGH????,????????
LCD_CtrlWrite(0x7C);
LCD_DataWrite(0xB6);
LCD_DataWrite(0x29);
//VGL????,????????
LCD_CtrlWrite(0xAC);
LCD_DataWrite(0x40);
//VREG????,????????
LCD_CtrlWrite(0xC3);
LCD_DataWrite(0x1A);//18
LCD_CtrlWrite(0xC4);
LCD_DataWrite(0x24);//22
LCD_CtrlWrite(0xC9);
LCD_DataWrite(0x2F);
//Gamma??,????????
LCD_CtrlWrite(0xF0);
LCD_DataWrite(0x11);//V62[5:0]
LCD_DataWrite(0x17);//V61[5:0]
LCD_DataWrite(0x08);//V59[4:0]
LCD_DataWrite(0x06);//V57[4:0]
LCD_DataWrite(0x05);//V63[7:4]/V50[3:0]
LCD_DataWrite(0x38);//V43[6:0]
                                       
LCD_CtrlWrite(0xF1); 
LCD_DataWrite(0x4D);//V20[6:0]
LCD_DataWrite(0x72);//V36[7:5]/V6[4:0]
LCD_DataWrite(0x72);//V27[7:5]/V4[4:0]
LCD_DataWrite(0x2D);//V2[5:0]
LCD_DataWrite(0x34);//V1[5:0]
LCD_DataWrite(0x8F);//V13[7:4]/V0[3:0]

LCD_CtrlWrite(0xF2); 
LCD_DataWrite(0x11);//V62[5:0]
LCD_DataWrite(0x17);//V61[5:0]
LCD_DataWrite(0x08);//V59[4:0]
LCD_DataWrite(0x06);//V57[4:0]
LCD_DataWrite(0x05);//V63[7:4]/V50[3:0]
LCD_DataWrite(0x38);//V43[6:0]
                     
LCD_CtrlWrite(0xF3); 
LCD_DataWrite(0x4D);//V20[6:0]
LCD_DataWrite(0x72);//V36[7:5]/V6[4:0]
LCD_DataWrite(0x72);//V27[7:5]/V4[4:0]
LCD_DataWrite(0x2D);//V2[5:0]
LCD_DataWrite(0x34);//V1[5:0]
LCD_DataWrite(0x8F);//V13[7:4]/V0[3:0]


//TE???TE pulse width
LCD_CtrlWrite(0xB4);//TE Width//
LCD_DataWrite(0x0a);
LCD_CtrlWrite(0x35);
LCD_DataWrite(0x00);


//------------------------------------------------------


//??????????,????!!!
LCD_CtrlWrite(0xFE);
LCD_CtrlWrite(0xEE);

LCD_CtrlWrite(0x11);
delayms(20),

LCD_CtrlWrite(0x29);
delayms(20),
}
void Enter_sleep()
{
LCD_CtrlWrite(0x28);
delayms(20),
LCD_CtrlWrite(0x10);
delayms(20),
}
void Exit_sleep()
{
LCD_CtrlWrite(0x11);
delayms(20),
LCD_CtrlWrite(0x29);
delayms(20),
}