#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; unsigned int tempid = 0x9325; 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); delayms(3) ; //delayms 3ms seng_cmd_dat(0x0000, 0x0001); delayms(3) ; //delayms 3ms seng_cmd_dat(0x0063, 0x0003); delayms(3) ; //delayms 3ms /*----------- pump------------------ */ seng_cmd_dat(0x0011, 0x011d); delayms(3) ; //delayms 3ms seng_cmd_dat(0x0060, 0x101e); delayms(3) ; //delayms 3ms seng_cmd_dat(0x0060, 0x171e); delayms(30) ; //delayms 30ms /*------------Gamma--------------- */ seng_cmd_dat(0x0012, 0x0019); seng_cmd_dat(0x0061, 0x0002); delayms(30) ; //delayms 30ms seng_cmd_dat(0x0030, 0x0000); seng_cmd_dat(0x0031, 0x0404); seng_cmd_dat(0x0032, 0x0304); seng_cmd_dat(0x0033, 0x0006); seng_cmd_dat(0x0034, 0x0707); seng_cmd_dat(0x0035, 0x0303); seng_cmd_dat(0x0036, 0x0403); seng_cmd_dat(0x0037, 0x0600); seng_cmd_dat(0x0038, 0x1600); seng_cmd_dat(0x0039, 0x0016); delayms(3) ; //delayms 3ms seng_cmd_dat(0x0013, 0x070d); //VCOM,VCOMH seng_cmd_dat(0x0061, 0x000b); delayms(3) ; //delayms 3ms seng_cmd_dat(0x0061, 0x002b); delayms(3) ; //delayms 3ms seng_cmd_dat(0x0061, 0x003f); delayms(30) ; //delayms 30ms /*-----------Memory Control-------- */ seng_cmd_dat(0x0010, 0x4000); seng_cmd_dat(0x0002, 0x0300); seng_cmd_dat(0x0090, 0x0012); seng_cmd_dat(0x0091, 0x0100); seng_cmd_dat(0x0092, 0x0001); seng_cmd_dat(0x0007, 0x023b); delayms(3) ; //delayms 3ms seng_cmd_dat(0x002f, 0x0008); seng_cmd_dat(0x0003, 0x1031); seng_cmd_dat(0x000c, 0x0000); seng_cmd_dat(0x000f, 0x0000); seng_cmd_dat(0x0023, 0xffff); seng_cmd_dat(0x0024, 0xffff); seng_cmd_dat(0x0004, 0x0000); seng_cmd_dat(0x0005, 0x0000); seng_cmd_dat(0x0001, 0x0100); seng_cmd_dat(0x0070, 0xa700); seng_cmd_dat(0x0071, 0x0001); seng_cmd_dat(0x0008, 0x0202); seng_cmd_dat(0x0050, 0x0000); seng_cmd_dat(0x0051, 0x00ef); seng_cmd_dat(0x0052, 0x0000); seng_cmd_dat(0x0053, 0x013f); seng_cmd_dat(0x0020, 0x0000); seng_cmd_dat(0x0021, 0x0000); LCD_WRITE_CMD(0x0022); } 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,i; for(i=0;i<256;i++) { seng_cmd_dat(i, 0x8000); //This code is necessary } LCD_WRITE_CMD(0); temp=0; P0=0xff; P2=0xff; RS=1; TFT_CS=0; RDB=0; delayms(5); DH=P2; RDB=0; RDB=1; //读关闭 DL=P0; 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 ; 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 set_point_9325(unsigned int x,unsigned int y) { seng_cmd_dat(0x0020,y);//设置Xx 坐标位置 seng_cmd_dat(0x0021,x);//设置Y坐标位置 LCD_WRITE_CMD(0x0022);//LCD_WriteCMD(GRAMWR); } //================================================================================================ // 实现功能: 设置坐标 // 输入参数: //================================================================================================ void set_point(unsigned int x,unsigned int y) { set_point_9325(x,y); } //================================================================================================ // 实现功能: 显示字符串 // 输入参数: //================================================================================================ void GUI_Point(unsigned char x, unsigned int y, unsigned int color) { set_point(x,y); 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<240) { 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<320) { 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 main(void) { unsigned char id,i; UART_init(); reset(); id = LCD_ID_9325(0x00); lcd_init(); LCD_SET_WIN(); while(1) { LCD_BRUSH(0x0); // for(i=0;i<100;i++) // { // GUI_Point(30,i,0xffff); // } GUI_sprintf_string(200,30,"ILI9325",0xffff,0); delayms(3000); set_point(0,0); LCD_BRUSH(0xf800); delayms(1000); LCD_BRUSH(0x07e0); delayms(1000); LCD_BRUSH(0x01f0); delayms(1000); seng_cmd_dat(0x0050,0x0000);//水平起始位置 seng_cmd_dat(0x0051,0x00EF);//水平终止位置 seng_cmd_dat(0x0052,0x0000);//垂直起始位置 seng_cmd_dat(0x0053,0x00EF);//垂直终止位置 LCD_WRITE_CMD(0x0022);//LCD_WriteCMD(GRAMWR); 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); } }