#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; DataL = 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; DataL = 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; DataL = 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(0x0001, 0x0100); // set SS and SM bit seng_cmd_dat(0x0002, 0x0700); // set 1 line inversion seng_cmd_dat(0x0003, 0x1030); // set GRAM write direction and BGR=1. seng_cmd_dat(0x0004, 0x0000); // Resize register seng_cmd_dat(0x0008, 0x0202); // set the back porch and front porch seng_cmd_dat(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0] seng_cmd_dat(0x000A, 0x0000); // FMARK function seng_cmd_dat(0x000C, 0x0000); // RGB interface setting seng_cmd_dat(0x000D, 0x0000); // Frame marker Position seng_cmd_dat(0x000F, 0x0000); // RGB interface polarity //*************Power On sequence ****************// seng_cmd_dat(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB seng_cmd_dat(0x0011, 0x0003); // DC1[2:0], DC0[2:0], VC[2:0] seng_cmd_dat(0x0012, 0x0000); // VREG1OUT voltage seng_cmd_dat(0x0013, 0x1300); // VDV[4:0] for VCOM amplitude seng_cmd_dat(0x0007, 0x0001); delayms(200); // Dis-charge capacitor power voltage seng_cmd_dat(0x0010, 0x1690); // SAP, BT[3:0], AP, DSTB, SLP, STB seng_cmd_dat(0x0011, 0x0227); // DC1[2:0], DC0[2:0], VC[2:0] delayms(50); // Delay 50ms seng_cmd_dat(0x0012, 0x009d); // Internal reference voltage= Vci; delayms(50); // Delay 50ms seng_cmd_dat(0x0013, 0x1f00); // Set VDV[4:0] for VCOM amplitude seng_cmd_dat(0x0029, 0x0025); // Set VCM[5:0] for VCOMH seng_cmd_dat(0x002B, 0x000D); // Set Frame Rate delayms(50); // Delay 50ms seng_cmd_dat(0x0020, 0x0000); // GRAM horizontal Address seng_cmd_dat(0x0021, 0x0000); // GRAM Vertical Address // ----------- Adjust the Gamma Curve ----------// seng_cmd_dat(0x0030, 0x0007); seng_cmd_dat(0x0031, 0x0303); seng_cmd_dat(0x0032, 0x0003); seng_cmd_dat(0x0035, 0x0206); seng_cmd_dat(0x0036, 0x0008); seng_cmd_dat(0x0037, 0x0406); seng_cmd_dat(0x0038, 0x0304); seng_cmd_dat(0x0039, 0x0007); seng_cmd_dat(0x003C, 0x0602); seng_cmd_dat(0x003D, 0x0008); //------------------ Set GRAM area ---------------// seng_cmd_dat(0x0050, 0x0000); // Horizontal GRAM Start Address seng_cmd_dat(0x0051, 0x00EF); // Horizontal GRAM End Address seng_cmd_dat(0x0052, 0x0000); // Vertical GRAM Start Address seng_cmd_dat(0x0053, 0x013F); // Vertical GRAM Start Address seng_cmd_dat(0x0060, 0xA700); // Gate Scan Line seng_cmd_dat(0x0061, 0x0001); // NDL,VLE, REV seng_cmd_dat(0x006A, 0x0000); // set scrolling line //-------------- Partial Display Control ---------// seng_cmd_dat(0x0080, 0x0000); seng_cmd_dat(0x0081, 0x0000); seng_cmd_dat(0x0082, 0x0000); seng_cmd_dat(0x0083, 0x0000); seng_cmd_dat(0x0084, 0x0000); seng_cmd_dat(0x0085, 0x0000); //-------------- Panel Control -------------------// seng_cmd_dat(0x0090, 0x0013); seng_cmd_dat(0x0092, 0x0600); seng_cmd_dat(0x0007, 0x0133); // 262K color and display ON } void LCD_SET_WIN(void) { seng_cmd_dat(0x0050,0x0000);//水平起始位置 seng_cmd_dat(0x0051,0x00EF);//水平终止位置 seng_cmd_dat(0x0052,0x0000);//垂直起始位置 seng_cmd_dat(0x0053,0x013F);//垂直终止位置 LCD_WRITE_CMD(0x0022);//LCD_WriteCMD(GRAMWR); } void LCD_BRUSH(int color) { int i,j; LCD_WRITE_CMD(0x0022); for(i=0;i<320;i++) { for(j=0;j<240;j++) { // LCD_WRITE_DATA(color>>8); // LCD_WRITE_DATA(color); LCD_WRITE_DATA(color); } } } unsigned char LCD_ID_9325(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; //十六位读 DL=P0; //十六位读 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_9325(0x00); lcd_init(); LCD_SET_WIN(); while(1) { LCD_BRUSH(0xf800); delayms(1000); LCD_BRUSH(0xffff); delayms(1000); LCD_BRUSH(0x0000); 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); } }