//VCI=3.3V //***********************寄存器指令***************************************** void write_command (unsigned char y) // (uchar y,uchar x) { unsigned char i; csb=0; sclb=0; sdi=0; sclb=1; for(i=0;i<8;i++) { sclb=0; if (y&0x80) { sdi=1; } else { sdi=0; } sclb=1; y=y<<1; } csb=1; } //**************************寄存器数据************************************* void write_data(unsigned char w) // (uchar w, uchar v) { unsigned char i; csb=0; sclb=0; sdi=1; sclb=1; for(i=0;i<8;i++) { sclb=0; if (w&0x80) { sdi=1; } else { sdi=0; } sclb=1; w=w<<1; } csb=1; } //********************送显示数据********************************* void write_data2(unsigned char data_l,data_h) { unsigned char a,i,b; csb=0; sclb=0; sdi=1; sclb=1; a=data_l; for(i=0;i<8;i++) { sclb=0; if (a&0x80) { sdi=1; } else { sdi=0; } sclb=1; a=a<<1; } csb=0; sclb=0; sdi=1; sclb=1; b=data_h; for(i=0;i<8;i++) { sclb=0; if (b&0x80) { sdi=1; } else { sdi=0; } sclb=1; b=b<<1; } csb=1; } /*************************************************/ void initi(void) { res=1; delay(1); res=0; delay(10); res=1; delay(120); //************************************************ write_command(0x11); delay(120); //Delay 120ms write_command(0x3A); write_data(0x05); write_command(0x36); write_data(0x00); //--------------------------------ST7789S Frame rate setting----------------------------------// write_command(0xb2); write_data(0x00); write_data(0x00); write_data(0x00); write_data(0x33); write_data(0x33); write_command(0xb7); write_data(0x35); //---------------------------------ST7789S Power setting--------------------------------------// write_command(0xb8); write_data(0x2f); write_data(0x2b); write_data(0x2f); write_command(0xbb); write_data(0x24);//vcom write_command(0xc0); write_data(0x2C); write_command(0xc3); write_data(0x10);//17调深浅 write_command(0xc4); write_data(0x20); write_command(0xc6); write_data(0x11); write_command(0xd0); write_data(0xa4); write_data(0xa1); write_command(0xe8); write_data(0x03); write_command(0xe9); write_data(0x0d); write_data(0x12); write_data(0x00); //--------------------------------ST7789S gamma setting---------------------------------------// write_command(0xe0); write_data(0xd0); write_data(0x00); write_data(0x00); write_data(0x08); write_data(0x11); write_data(0x1a); write_data(0x2b); write_data(0x33); write_data(0x42); write_data(0x26); write_data(0x12); write_data(0x21); write_data(0x2f); write_data(0x11); write_command(0xe1); write_data(0xd0); write_data(0x02); write_data(0x09); write_data(0x0d); write_data(0x0d); write_data(0x27); write_data(0x2b); write_data(0x33); write_data(0x42); write_data(0x17); write_data(0x12); write_data(0x11); write_data(0x2f); write_data(0x31); write_command(0x21); //反显 write_command(0x2A); //Frame rate control write_data(0x00); write_data(0x00); write_data(0x00); write_data(0xEF); write_command(0x2B); //Display function control write_data(0x00); write_data(0x00); write_data(0x01); write_data(0x3F); write_command(0x29); //display on write_command(0x2c); } //********************************************************************************************* void EnterSleep (void) { write_command(0x28); delay(20); write_command(0x10); } //********************************************************* void ExitSleep (void) { write_command(0x11); delay(120); write_command(0x29); }