#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(0x0080, 0x008d); seng_cmd_dat(0x0092, 0x0010); /*避免白屏*/ seng_cmd_dat(0x0011, 0x001f); seng_cmd_dat(0x0012, 0x5000); seng_cmd_dat(0x0013, 0x0070); seng_cmd_dat(0x0014, 0x4068); seng_cmd_dat(0x0010, 0x0c00); seng_cmd_dat(0x0011, 0x011f); delayms(10); seng_cmd_dat(0x0011, 0x011f); delayms(10); seng_cmd_dat(0x0011, 0x031f); delayms(10); seng_cmd_dat(0x0011, 0x071f); delayms(10); seng_cmd_dat(0x0011, 0x0f1f); delayms(20); seng_cmd_dat(0x0011, 0x0f3f); delayms(30); //*************************************Display Control Register Setting****************************// seng_cmd_dat(0x0001, 0x0128); seng_cmd_dat(0x0002, 0x0100); seng_cmd_dat(0x0003, 0x1030); seng_cmd_dat(0x000c, 0x0000); seng_cmd_dat(0x000F, 0x1801); seng_cmd_dat(0x0015, 0x0070); seng_cmd_dat(0x0030, 0x0000); // ----------- Adjust the Gamma Curve ----------// seng_cmd_dat(0x0050, 0x000f); seng_cmd_dat(0x0051, 0x000f); seng_cmd_dat(0x0052, 0x0000); seng_cmd_dat(0x0053, 0x0300); seng_cmd_dat(0x0054, 0x0000); seng_cmd_dat(0x0055, 0x0800); seng_cmd_dat(0x0056, 0x0000); seng_cmd_dat(0x0057, 0x0003); seng_cmd_dat(0x0058, 0x021f); seng_cmd_dat(0x0059, 0x1f02); //------------------ RAM Address control ---------------// seng_cmd_dat(0x0036, 0x00ef); seng_cmd_dat(0x0037, 0x0000); seng_cmd_dat(0x0038, 0x013f); seng_cmd_dat(0x0039, 0x0000); seng_cmd_dat(0x0020, 0x0000); seng_cmd_dat(0x0021, 0x0000); //--------------- Panel interface control---------------// seng_cmd_dat(0x0007, 0x0010); seng_cmd_dat(0x0007, 0x0012); delayms(10); seng_cmd_dat(0x0007, 0x0013); delayms(10); seng_cmd_dat(0x0007, 0x0017); } 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<240;i++) { for(j=0;j<320;j++) { // LCD_WRITE_DATA(color>>8); // LCD_WRITE_DATA(color); LCD_WRITE_DATA(color); } } } unsigned char LCD_ID_0154(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_0154(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); } }