#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(0x0000, 0x0000); seng_cmd_dat(0x0001, 0x0100); // set SS and SM bit seng_cmd_dat(0x0002, 0x0900); // set 1 line inversion seng_cmd_dat(0x0003, 0x1020); // set GRAM write direction and BGR=1. seng_cmd_dat(0x0008, 0x0808); seng_cmd_dat(0x0009, 0x0001); // Resize register seng_cmd_dat(0x000A, 0x0008); // set the back porch and front porch seng_cmd_dat(0x000C, 0x0000); // set non-display area refresh cycle ISC[3:0] seng_cmd_dat(0x000D, 0xD000); // FMARK function seng_cmd_dat(0x000E, 0x0030); // RGB interface setting seng_cmd_dat(0x000F, 0x0000); // Frame marker Position seng_cmd_dat(0x00A4, 0x0001); // RGB interface polarity seng_cmd_dat(0x0060, 0xA700); //*************Power On sequence ****************// seng_cmd_dat(0x0090, 0x001a); seng_cmd_dat(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB seng_cmd_dat(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0] seng_cmd_dat(0x0012, 0x0000); // VREG1OUT voltage seng_cmd_dat(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude seng_cmd_dat(0x0007, 0x0001); delayms(50); // Dis-charge capacitor power voltage seng_cmd_dat(0x0010, 0x0530); // SAP, BT[3:0], AP, DSTB, SLP, STB seng_cmd_dat(0x0011, 0x0237); // DC1[2:0], DC0[2:0], VC[2:0] 0237 delayms(200); // Delay 50ms seng_cmd_dat(0x0012, 0x01Bf); // Internal reference voltage= Vci; //1bc delayms(250); // Delay 50ms seng_cmd_dat(0x0013, 0x1100); // Set VDV[4:0] for VCOM amplitude seng_cmd_dat(0x0029, 0x0029); // Set VCM[5:0] for VCOMH 005FH seng_cmd_dat(0x002B, 0x000a); // Set Frame Rate 0d delayms(50); // Delay 50ms seng_cmd_dat(0x0020, 0x00ef); // GRAM horizontal Address seng_cmd_dat(0x0021, 0x0000); // GRAM Vertical Address //************* Adjust the Gamma Curve *************// seng_cmd_dat(0x0030, 0x0105); seng_cmd_dat(0x0031, 0x0412);//5B0A seng_cmd_dat(0x0032, 0x0401); seng_cmd_dat(0x0033, 0x050d); seng_cmd_dat(0x0034, 0x2103); seng_cmd_dat(0x0035, 0x0d05); seng_cmd_dat(0x0036, 0x0104);//6309 seng_cmd_dat(0x0037, 0x1204); seng_cmd_dat(0x0038, 0x0501);//100C seng_cmd_dat(0x0039, 0x0321); //************* 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(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, 0x005F); //************* Panel Control *************// seng_cmd_dat(0x0093, 0x0701); seng_cmd_dat(0x0007, 0x0100); // 262K color and display ON LCD_WRITE_CMD(0x0022); } void LCD_SET_WIN(unsigned int xs,unsigned int ys,unsigned int xe,unsigned int ye) { LCD_WRITE_CMD(0x0050);LCD_WRITE_DATA(xs); LCD_WRITE_CMD(0x0051);LCD_WRITE_DATA(xe); LCD_WRITE_CMD(0x0052);LCD_WRITE_DATA(ys); LCD_WRITE_CMD(0x0053);LCD_WRITE_DATA(ye); LCD_WRITE_CMD(0x0020);LCD_WRITE_DATA(ys); LCD_WRITE_CMD(0x0021);LCD_WRITE_DATA(xs); LCD_WRITE_CMD(0x0022);//LCD_WriteCMD(GRAMWR); } void GUI_Point(unsigned int x, unsigned int y, unsigned int color) { LCD_WRITE_CMD(0x0020);LCD_WRITE_DATA(y); LCD_WRITE_CMD(0x0021);LCD_WRITE_DATA(319-x); LCD_WRITE_CMD(0x0022);//LCD_WriteCMD(GRAMWR); LCD_WRITE_DATA(color); } //================================================================================================ // 实现功能: 显示字符串 // 输入参数: //================================================================================================ void GUI_sprintf_char(unsigned char x, unsigned int y,unsigned char c, unsigned int color,unsigned int b_color) { unsigned char s_x ,s_y, temp ; unsigned int j; c -= 32; for( s_y=0 ; s_y < 16 ; s_y++ ) { if(s_y+y<320) { j=c; j=j*16+s_y; temp=font16x8[j]; //temp = font16x8[c*16+s_y] ; for( s_x=0 ; s_x<8 ; s_x++ ) { if(x+s_x<240) { if((temp&(0x80>>(s_x))) == (0x80>>(s_x)) ) { GUI_Point(x+s_x, y+s_y,color) ; } else { GUI_Point(x+s_x, y+s_y,b_color) ; } } } } } } //================================================================================================ // 实现功能: 显示字符串 // 输入参数: //================================================================================================ void GUI_sprintf_string(unsigned char x, unsigned int y,char code *s, unsigned int color,unsigned int b_color) { for(;*s!='\0';s++) { GUI_sprintf_char(x, y,*s, color,b_color); x=x+8; } } void LCD_BRUSH(int color) { int i,j; LCD_WRITE_CMD(0x0022); 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);//delayms(5); // GUI_Point(i, j, color); } } } unsigned char LCD_ID_7781(unsigned int dat) { unsigned int temp,DH,DL; LCD_WRITE_CMD(dat); temp=0; P0=0xff; P2=0xff; RS=1; TFT_CS=0; RDB=1; delayms(5); DH=P2; RDB=0; RDB=1; DL=P2; RDB=0; 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 ; LCD_WRITE_CMD(0x0050);LCD_WRITE_DATA(0x0000); LCD_WRITE_CMD(0x0051);LCD_WRITE_DATA(0x00ef); LCD_WRITE_CMD(0x0052);LCD_WRITE_DATA(0x0080); LCD_WRITE_CMD(0x0053);LCD_WRITE_DATA(0x013f); LCD_WRITE_CMD(0x0022);//LCD_WriteCMD(GRAMWR); for(m=0;m<240;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_7781(0x00); lcd_init(); // LCD_SET_WIN(20,50,220,250); LCD_SET_WIN(0,0,239,319); while(1) { LCD_BRUSH(0xf800); delayms(1000); LCD_BRUSH(0xffff); delayms(1000); LCD_BRUSH(0x0000); delayms(1000); // draw_pic(); GUI_sprintf_string(20,60,"777888999",0xffff,0x0); 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); } }