#include #include<16x8.h> #define DataH P2 #define DataL P0 sbit TFT_CS = P1^0; sbit RES = P1^4; sbit RS = P1^1; sbit WRB = P1^2; sbit RDB = P1^3; void UART_init(void) { SCON=0x40; TMOD=0x20; TH1=0xF3; //波特率计算256-11059200/(12*32*9600) TL1=0xF3; TR1=1; } void UART_send_data(unsigned char str) { SBUF=str; while(!TI); TI=0; } void delayms(int value) { int i,j; for(i=0;i<=value;i++) {for(j=0;j<=500;j++);} } void LCD_WRITE_CMD(unsigned int cmd) { RS = 0; RDB = 1; WRB = 1; TFT_CS = 0; DataH = cmd>>8; WRB = 0; WRB = 1; DataH = cmd; WRB = 0; WRB = 1; TFT_CS = 1; } void LCD_WRITE_DATA(unsigned int dat) { RS = 1; RDB = 1; WRB = 1; TFT_CS = 0; DataH = dat>>8; WRB = 0; WRB = 1; DataH = dat; WRB = 0; WRB = 1; TFT_CS = 1; } void LCD_WRITE_DATA2(unsigned char dat1,unsigned char dat2) { RS = 1; RDB = 1; WRB = 1; TFT_CS = 0; DataH = dat1; WRB = 0; WRB = 1; DataH = dat2; WRB = 0; WRB = 1; TFT_CS = 1; } void seng_cmd_dat(int cmd,int dataa) { LCD_WRITE_CMD(cmd); LCD_WRITE_DATA(dataa); } void reset(void) { RES = 1; delayms(50); RES = 0; delayms(200); RES = 1; delayms(500); } void lcd_init(void) { reset(); //效果不错的初始化代码 // seng_cmd_dat(0x0072, 0x0000); // set 1 line inversion // seng_cmd_dat(0x0000,0x0001);//65K // delayms(10); // Dis-charge capacitor power voltage // seng_cmd_dat(0x00B4, 0x000); // seng_cmd_dat(0x0012, 0x0051); // set SS and SM bit // seng_cmd_dat(0x0013, 0x0800); // set the back porch and front porch // seng_cmd_dat(0x0014, 0x72ec); // set non-display area refresh cycle ISC[3:0] // seng_cmd_dat(0x0010, 0x240c); // FMARK function // // delayms(80); // Dis-charge capacitor power voltage // seng_cmd_dat(0x0013, 0x0810); // RGB interface setting // seng_cmd_dat(0x0012, 0x0092); // Frame marker Position // seng_cmd_dat(0x0001, 0x0114); // RGB interface polarity // // // seng_cmd_dat(0x0002, 0x0100); // SAP, BT[3:0], AP, DSTB, SLP, STB // seng_cmd_dat(0x0003, 0x1030); // DC1[2:0], DC0[2:0], VC[2:0] // seng_cmd_dat(0x0008, 0x0202); // VREG1OUT voltage // seng_cmd_dat(0x000b, 0x0000); // VDV[4:0] for VCOM amplitude // delayms(200); // Dis-charge capacitor power voltage // seng_cmd_dat(0x000c, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB // seng_cmd_dat(0x0061, 0x001b); // DC1[2:0], DC0[2:0], VC[2:0] // delayms(50); // Delay 50ms // seng_cmd_dat(0x0069, 0x0000); // Internal reference voltage= Vci; // delayms(50); // Delay 50ms // seng_cmd_dat(0x0070, 0x0003); // Set VDV[4:0] for VCOM amplitude // seng_cmd_dat(0x0071, 0x0000); // Set VCM[5:0] for VCOMH // seng_cmd_dat(0x0011, 0x0004); // Set Frame Rate // delayms(50); // Delay 50ms // seng_cmd_dat(0x0030, 0x0000); // GRAM horizontal Address // seng_cmd_dat(0x0031, 0x0207); // GRAM Vertical Address // seng_cmd_dat(0x0032, 0x0101); // seng_cmd_dat(0x0033, 0x0000); // seng_cmd_dat(0x0034, 0x0504); // seng_cmd_dat(0x0035, 0x0002); // seng_cmd_dat(0x0036, 0x0706); // seng_cmd_dat(0x0037, 0x0200); // seng_cmd_dat(0x0038, 0x0400); // seng_cmd_dat(0x0040, 0x0000); // seng_cmd_dat(0x0042, 0x9f00); // seng_cmd_dat(0x0043, 0x0000); // seng_cmd_dat(0x0044, 0x7f00); // seng_cmd_dat(0x0045, 0x9f00); // seng_cmd_dat(0x00BF, 0x1000); ////------------------ Set GRAM area ---------------// // seng_cmd_dat(0x0050, 0x0000); // Horizontal GRAM Start Address // seng_cmd_dat(0x0051, 0x0080); // Horizontal GRAM End Address // seng_cmd_dat(0x0052, 0x0000); // Vertical GRAM Start Address // seng_cmd_dat(0x0053, 0x00A0); // Vertical GRAM Start Address // // // seng_cmd_dat(0x0007, 0x0005); // 262K color and display ON // delayms(10); // seng_cmd_dat(0x0007, 0x0025); // 262K color and display ON // seng_cmd_dat(0x0007, 0x0027); // 262K color and display ON // delayms(10); // seng_cmd_dat(0x0007, 0x0037); // 262K color and display ON // delayms(80); // // // seng_cmd_dat(0x00,0x0022);// // // delayms(10); // seng_cmd_dat(0x0007, 0x0020); // seng_cmd_dat(0x00b6, 0x753f); // seng_cmd_dat(0x00b4, 0x0110); // seng_cmd_dat(0x0012, 0x0000); // seng_cmd_dat(0x0013, 0x080e); // seng_cmd_dat(0x0014, 0x004c); // seng_cmd_dat(0x0061, 0x0018); // seng_cmd_dat(0x0010, 0x120c); // delayms(30); // seng_cmd_dat(0x00b6, 0x7d3f); // seng_cmd_dat(0x0014, 0x6Dea); ///7EEB//6FEB // seng_cmd_dat(0x0010, 0x1d14); //1D14 // seng_cmd_dat(0x0013, 0x081e); //081e // seng_cmd_dat(0x0012, 0x0071); // delayms(20); // seng_cmd_dat(0x0001, 0x0114); // seng_cmd_dat(0x0002, 0x0100); // seng_cmd_dat(0x0003, 0x1030); // seng_cmd_dat(0x0008, 0x0808); // seng_cmd_dat(0x000b, 0x0008);///// // seng_cmd_dat(0x000c, 0x0000); // seng_cmd_dat(0x0061, 0x0018); // seng_cmd_dat(0x0069, 0x0000); // seng_cmd_dat(0x0070, 0x0003); // seng_cmd_dat(0x0071, 0x0000); // seng_cmd_dat(0x0011, 0x0000); // seng_cmd_dat(0x0030, 0x0000); // seng_cmd_dat(0x0031, 0x0707); // seng_cmd_dat(0x0032, 0x0307); // seng_cmd_dat(0x0033, 0x0704); // seng_cmd_dat(0x0034, 0x0007); // seng_cmd_dat(0x0035, 0x0101); // seng_cmd_dat(0x0036, 0x0707); // seng_cmd_dat(0x0037, 0x0001); // seng_cmd_dat(0x0038, 0x0604); // seng_cmd_dat(0x0040, 0x0000); // seng_cmd_dat(0x0042, 0x9f00); // seng_cmd_dat(0x0043, 0x0000); // seng_cmd_dat(0x0044, 0x7f00); // seng_cmd_dat(0x0045, 0x9f00); // seng_cmd_dat(0x0007, 0x0020); // delayms(20); // seng_cmd_dat(0x0007, 0x0021); // seng_cmd_dat(0x0007, 0x0027); // delayms(20); // seng_cmd_dat(0x0007, 0x0037); // delayms(20); // LCD_WRITE_CMD(0x0022);//LCD_WriteCMD(GRAMWR); // seng_cmd_dat(0x0007,0x0020); seng_cmd_dat(0x00b6,0x013f);//Module Vendor seng_cmd_dat(0x00B4,0x0010);//MTP Control //power control setting seng_cmd_dat(0x0012,0x00b1);//Power control 2 delayms(10); seng_cmd_dat(0x0013,0x080e);// Power control 3 (R13h) delayms(10); seng_cmd_dat(0x0014,0x5BC9); //Power control 4 (R14h) delayms(10); seng_cmd_dat(0x0061,0x0018);//Oscillator control seng_cmd_dat(0x0010,0x190C);//Power Control 1 delayms(80); seng_cmd_dat(0x0013,0x081e); delayms(50); seng_cmd_dat(0x0001,0x0114); //Driver Output Control seng_cmd_dat(0x0002,0x0100);//LCD Inversion Control seng_cmd_dat(0x0003,0x1030);//Entry Mode seng_cmd_dat(0x0008,0x0202);//Blank period control 1 seng_cmd_dat(0x000b,0x0000);//Frame cycle control seng_cmd_dat(0x000C,0x0000);//External Display Interface Control seng_cmd_dat(0x0061,0x0018);//Oscillator control seng_cmd_dat(0x0069,0x0000);//DC/DC convert low power mode seng_cmd_dat(0x0070,0x0000);//Source Driver pre-driving period setting seng_cmd_dat(0x0071,0x0000);//Gate Output Period Control seng_cmd_dat(0x0011,0x0000);//Gamma control 1 //r CONTROL seng_cmd_dat(0x0030,0x0303);//Gamma control 2 (R30h to R37h) seng_cmd_dat(0x0031,0x0303); seng_cmd_dat(0x0032,0x0303); seng_cmd_dat(0x0033,0x0000); seng_cmd_dat(0x0034,0x0404); seng_cmd_dat(0x0035,0x0404); seng_cmd_dat(0x0036,0x0404); seng_cmd_dat(0x0037,0x0000); seng_cmd_dat(0x0038,0x0707); delayms(5); // Position setting seng_cmd_dat(0x0040,0x0000);//Gate scan position seng_cmd_dat(0x0042,0x9F00);//Screen driving position seng_cmd_dat(0x0043,0x0000);//Screen driving position seng_cmd_dat(0x0044,0x7F00);//Horizontal address position seng_cmd_dat(0x0045,0x9F00);//Vertical RAM address position seng_cmd_dat(0x0021,0x0000);//GRAM address set delayms(20); seng_cmd_dat(0x0069,0x0000);//DC/DC convert low power mode seng_cmd_dat(0x0070,0x0000);//Source Driver pre-driving period setting seng_cmd_dat(0x0071,0x0000);//Gate Output Period Control seng_cmd_dat(0x0073,0x0000);//Test_Key seng_cmd_dat(0x00B3,0x0000);//DC/DC converter Clock Source Selection seng_cmd_dat(0x00BD,0x0000);//MTP Data Read seng_cmd_dat(0x00BE,0x0000);//Interface Mode Selection seng_cmd_dat(0x0007,0x0020);//Display control delayms(5); seng_cmd_dat(0x0007,0x0021); seng_cmd_dat(0x0007,0x0027); delayms(50); seng_cmd_dat(0x0007,0x0037); seng_cmd_dat(0x0021,0x0000);//RAM address set seng_cmd_dat(0x0044,0x7F00);//Horizontal RAM Address Position//HEA=0x7f, HSA=0 seng_cmd_dat(0x0045,0x9F00);//Vertical RAM Address Position//VEA=0x9f, VSA=0 seng_cmd_dat(0x0022); delayms(100); } void LCD_SET_WIN(void) { seng_cmd_dat(0x0021,0x0000);//RAM address set seng_cmd_dat(0x0044,0x7F00);//Horizontal RAM Address Position//HEA=0x7f, HSA=0 seng_cmd_dat(0x0045,0x9F00);//Vertical RAM Address Position//VEA=0x9f, VSA=0 LCD_WRITE_CMD(0x0022);//LCD_WriteCMD(GRAMWR); } void LCD_BRUSH(int color) { int i,j; // LCD_SET_WIN(); for(i=0;i<128;i++) { for(j=0;j<160;j++) { // LCD_WRITE_DATA(color>>8); // LCD_WRITE_DATA(color); LCD_WRITE_DATA(color); } } } unsigned char LCD_ID_9331(unsigned int dat) { unsigned int temp,DH,DL; LCD_WRITE_CMD(dat); temp=0; P0=0xff; P2=0xff; RS=1; TFT_CS=0; RDB=0; delayms(5); DH=P2; //8位读 RDB=1; //读关闭 RDB=0; DL=P2; //8位读 RDB=1; //读关闭 TFT_CS=1; //片选关闭 UART_send_data(DH); UART_send_data(DL); return temp; } //void draw_pic() //{ // int i=0,m=0,n=0 ; // for(m=0;m<320;m++) //刷图片 // { // for(n=0;n<240;n++) // { // if(i == 16800) // i = 0; // LCD_WRITE_DATA2(image[i*2+1],image[i*2]); // // i++; // // } // } // // //} void main(void) { unsigned char id; UART_init(); reset(); id = LCD_ID_9331(0x00); lcd_init(); LCD_SET_WIN(); while(1) { LCD_BRUSH(0x0000); delayms(1000); LCD_BRUSH(0xf800); delayms(1000); LCD_BRUSH(0x07e0); delayms(1000); LCD_BRUSH(0x001f); delayms(1000); LCD_BRUSH(0xffff); delayms(1000); // draw_pic(); delayms(1000000); // LCD_BRUSH(0xf7de); // delay(1000); ////// LCD_BRUSH(0x001f); // delay(1000); //// LCD_BRUSH(0xf81f); //// delay(1000); // LCD_BRUSH(0x07e0); // delay(1000); // LCD_BRUSH(0x001f); // delay(1000); // LCD_BRUSH(0xffe0); // delay(1000); } }