//------------------------------------------------- // Shenzhen TOPWAY Technology Co.,Ltd. // System: AT89S52(12MHz) // LCD Module: LMT056DIDFWD-xAx // Display Size: 640(x3)x480 (16bit color) // Driver/Controller: RA8875 // Interface: 80 mode (8bit) // by: dong // rev 01: 2016-12-15 //------------------------------------------------- #include #include #include #include #define uchar unsigned char // 8bit, 0 ~ 255 #define uint unsigned int // 16bit, 0 ~ 65,535 #define ulong unsigned long // 32bit, 0 ~ 4,294,967,295 #define RED 0xf800 #define GREEN 0x07e0 #define BLUE 0x001f #define YELLOW 0xffe0 #define CYAN 0x07ff #define MAGENTA 0xf81f #define BLACK 0x0000 #define WHITE 0xffff #define mid_re 0x8000 #define mid_or 0x8200 #define mid_ye 0x8400 #define mid_yg 0x4400 #define mid_gr 0x0400 #define mid_gc 0x0408 #define mid_cy 0x0410 #define mid_cb 0x0210 #define mid_bl 0x0010 #define mid_bm 0x4010 #define mid_ma 0x8010 #define mid_mr 0x8010 #define GRAY00 0x0000 #define GRAY01 0x1082 #define GRAY02 0x2104 #define GRAY03 0x3186 #define GRAY04 0x4208 #define GRAY05 0x528a #define GRAY06 0x630c #define GRAY07 0x738e #define GRAY08 0x8410 #define GRAY09 0x9492 #define GRAY10 0xa514 #define GRAY11 0xb596 #define GRAY12 0xc618 #define GRAY13 0xd69a #define GRAY14 0xe71c #define GRAY15 0xffff uchar xdata CmdPort _at_ 0x8000;//0x8000 uchar xdata DataPort _at_ 0x0000; // using 8051 RAM bus as // LCD.RS connect 8051.A15 // LCD.CS connect 8051.P3.2 // LCD.WR connect 8051.WR // LCD.RD connect 8051.RD // i.e. // pointer 0x0xxx for RS=0 // pointer 0x8xxx for RS=1 sbit _CS = P3^2; // TP.CS sbit RST = P3^4; uchar bdata btemp; // create a bit accessable byte sbit btemp_b0 = btemp^0; sbit btemp_b3 = btemp^3; sbit btemp_b7 = btemp^7; uchar BL_Brightness; // 0~255 value (0%~100%) uchar PAG_NO; sbit _KeySel = P3^0; // _KeySel=0, key scanning active sbit _KeyAuto = P1^0; // _KeyAuto=0, key pressed sbit _KeyDarker = P1^1; // _KeyDarker=0, key pressed sbit _KeyLighter = P1^2; // _KeyLighter=0,key pressed sbit _KeyStep = P1^3; // _KeyStep=0, key pressed bit AutoRun; //----------------------------------- // delayms routine //----------------------------------- void delayms(uint m) // 12MHz Xtal, close to ms value { uint j; uint i; for(i=0; i>8; DataPort = DData; // write the low byte (toggle /WR) _CS=1; } uchar RdCmd() { uchar DData; _CS=0; DData=DataPort; // write the low byte (toggle /WR) _CS=1; return(DData); } //============================================================= // ????????????? //============================================================= void initLCM() { BL_Brightness=0x4C; //------------------------------------------------------------------------------- //??????趨?30MHz???????640x480??71Hz??? SdReg(0x88);SdCmd(0x0B);delayms(5);//???PLL=20*(11+1) = 240MHz SdReg(0x89);SdCmd(0x03);delayms(5);//???????????=240/8=30MHz SdReg(0x04);SdCmd(0x80);//??????????30MHz?????????? //------------------------------------------------------------------------------- //System Configuration Register (SYSR) //7~4 3~2 1~0 //N/A Color Depth Setting MCUIF SdReg(0x10);SdCmd(0x0c); //[3:2]=00: 256, 1x:65K, [1~0]=00: 8bit, 1x:16bit //------------------------------------------------------------------------------- //LCD Horizontal Display Width Register (HDWR) SdReg(0x14);SdCmd(0x4F); //(HDWR + 1)*8 ==> 640 SdReg(0x15);SdCmd(0x06); //Horizontal Non-Display Period Fine Tuning Option Register (HNDFTR) ===>default SdReg(0x16);SdCmd(0x12); //LCD Horizontal Non-Display Period Register (HNDR) SdReg(0x17);SdCmd(0x01); //HSYNC Start Position Register (HSTR+1)*8 ===>LCM Parameter 16 SdReg(0x18);SdCmd(0x00); //HSYNC Pulse Width Register (HPW+1)*8 ==> LCM Parameter 8 //------------------------------------------------------------------------------- //Vertical Display Height Register (VDHR0) SdReg(0x19);SdCmd(0xdf); //VDHR0 //Vertical Display Height Bit [7:0],7~0bit SdReg(0x1a);SdCmd(0x01); //8bit ===>8~0bit+1 ==>480 SdReg(0x1b);SdCmd(0x2c); //VNDR0 //Vertical Non-Display Period Bit [7:0],Vertical Non-Display area=(VNDR+1) 44 SdReg(0x1c);SdCmd(0x00); SdReg(0x1d);SdCmd(0x00); //VSTR0 //VSYNC Start Position[7:0],/VSYNC Start Position(PCLK) = (VSTR+1)6 SdReg(0x1f);SdCmd(0x01); //VPWR:VSYNC Polarity ,VSYNC Pulse Width[6:0],VSYNC Pulse Width(PCLK)=(VPWR+1) //------------------------------------------------------------------------------- //be in a poor light set SdReg(0x8a);SdCmd(0x85); //3.6kHz SdReg(0x8b);SdCmd(BL_Brightness); //------------------------------------------------------------------------------- //font selection==>CGRAM_Font + External_Font, GT23L24T3Y SdReg(0x20);SdCmd(0x00); // signal layer SdReg(0x21);SdCmd(0x20); //external font SdReg(0x29);SdCmd(0x01); //font line distance SdReg(0x05);SdCmd(0x08); //1 byte none wait SdReg(0x2e);SdCmd(0x00); //default font_type==>16X16 SdReg(0x2f);SdCmd(0x41); //font-lib SdReg(0x44);SdCmd(0x1a); //?????????? SdReg(0x4e);SdCmd(0x01); //???????С SdReg(0x4f);SdCmd(0x0f); //??????С SdReg(0x01);SdCmd(0x80); } //----------------------------------- // Backlight Brightness //----------------------------------- void BL_INC() { uchar i; for(i=0;i<0x10;i++) { if(BL_Brightness>0x00) { BL_Brightness=BL_Brightness-1; } } SdReg(0x8b); SdCmd(BL_Brightness); } void BL_DEC() { uchar i; for(i=0;i<0x10;i++) { if(BL_Brightness<0xFF) { BL_Brightness=BL_Brightness+1; } } SdReg(0x8b); SdCmd(BL_Brightness); } //------------------------------------------------------------- //=============================================== // ??????? // ???????????????x??y??????????????1~4??????? //=============================================== void PrintGB2(uint x, uint y, uint GBcolor, uchar size, uchar *GBcode) { uint temp; switch(size) { case 1: size=0x60; break; case 2: size=0x65; break; case 3: size=0x6a; break; case 4: size=0x6f; break; default: break; } SdReg(0x40);SdCmd(0x80); //????趨 SdReg(0x21);SdCmd(0x20); //?????? SdReg(0x06);SdCmd(0x00); //???????? SdReg(0x05);SdCmd(0x00); //??????????? SdReg(0x22);SdCmd(size); //???屳?????????????趨 SdReg(0x2e);SdCmd(0x00); //???????????С16x16 SdReg(0x2f);SdCmd(0x41); //?????????????????? 41 SdReg(0x30);SdCmd(0);//??????????? SdReg(0x31);SdCmd(0); SdReg(0x32);SdCmd(0);//??????????? SdReg(0x33);SdCmd(0); SdReg(0x34);SdCmd(0x1f);//???????????? SdReg(0x35);SdCmd(0x03); SdReg(0x36);SdCmd(0xdf);//???????????? SdReg(0x37);SdCmd(0x01); SdReg(0x63);SdCmd(GBcolor>>11);//?趨???????? SdReg(0x64);SdCmd(GBcolor>>5);//?趨???????? SdReg(0x65);SdCmd(GBcolor);//?趨????????? SdReg(0x2a);SdCmd(x);//?????λ?? SdReg(0x2b);SdCmd(x>>8); SdReg(0x2c);SdCmd(y);//???????趨 SdReg(0x2d);SdCmd(y>>8); SdReg(0x02); while(*GBcode>0) { temp=*GBcode++; // temp=temp+*pstr++; SdCmd(temp);delayms(1); } } //=============================================== // ?趨???д????????????? //=============================================== void Window_adr_set(uint x1,x2,y1,y2) { SdReg(0x30);SdCmd(x1);// ??????? SdReg(0x31);SdCmd(x1>>8); SdReg(0x32);SdCmd(y1); //???????? SdReg(0x33);SdCmd(y1>>8); SdReg(0x34);SdCmd(x2); //???????? SdReg(0x35);SdCmd(x2>>8); SdReg(0x36);SdCmd(y2); //????????? SdReg(0x37);SdCmd(y2>>8); SdReg(0x46);SdCmd(x1);// ??????λ?? SdReg(0x47);SdCmd(x1>>8); SdReg(0x48);SdCmd(y1); SdReg(0x49);SdCmd(y1>>8); SdReg(0x02); //???д?? } void ShowBMP(uint x,uint y,uint width,uint high,uint *pstr) { uint i,j; SdReg(0x40);SdCmd(0x00); SdReg(0x30);SdCmd(x);// SdReg(0x31);SdCmd(x>>8);// SdReg(0x32);SdCmd(y);// SdReg(0x33);SdCmd(y>>8);// SdReg(0x34);SdCmd(x+width-1);// SdReg(0x35);SdCmd((x+width-1)>>8);// SdReg(0x36);SdCmd(y+high-1);// SdReg(0x37);SdCmd((y+high-1)>>8);// SdReg(0x46);SdCmd(x);// SdReg(0x47);SdCmd(x>>8);// SdReg(0x48);SdCmd(y);// SdReg(0x49);SdCmd(y>>8);// SdReg(0x02); for(i=0;i>8); SdReg(0x93);SdCmd(y1); //???????? SdReg(0x94);SdCmd(y1>>8); SdReg(0x95);SdCmd(x2); //???????? SdReg(0x96);SdCmd(x2>>8); SdReg(0x97);SdCmd(y2); //????????? SdReg(0x98);SdCmd(y2>>8); SdReg(0x63);SdCmd(Color>>11);//?趨???????? SdReg(0x64);SdCmd(Color>>5);//?趨???????? SdReg(0x65);SdCmd(Color);//?趨????????? SdReg(0x90);SdCmd(0x80);//??????? 0x80 delayms(5); SdReg(0x90);SdCmd(0x00);//???????? } //======================================================= // ?????? //======================================================= void Draw_box(uint x1,x2,y1,y2,Color) { //?趨??????????????? SdReg(0x30);SdCmd(0);// ??????? SdReg(0x31);SdCmd(0); SdReg(0x32);SdCmd(0); //???????? SdReg(0x33);SdCmd(0); SdReg(0x34);SdCmd(0xff); //???????? SdReg(0x35);SdCmd(0xff); SdReg(0x36);SdCmd(0xff); //????????? SdReg(0x37);SdCmd(0xff); //?趨???? SdReg(0x91);SdCmd(x1);// ??????? SdReg(0x92);SdCmd(x1>>8); SdReg(0x93);SdCmd(y1); //???????? SdReg(0x94);SdCmd(y1>>8); SdReg(0x95);SdCmd(x2); //???????? SdReg(0x96);SdCmd(x2>>8); SdReg(0x97);SdCmd(y2); //????????? SdReg(0x98);SdCmd(y2>>8); SdReg(0x63);SdCmd(Color>>11);//?趨???????? SdReg(0x64);SdCmd(Color>>5);//?趨???????? SdReg(0x65);SdCmd(Color);//?趨????????? SdReg(0x90);SdCmd(0xb0);//????????? delayms(100); SdReg(0x90);SdCmd(0x00);//?????????? } //----------------------------------- // Main Program?????? //----------------------------------- void main() { SP=0x60; EA=0; // no interrupt _CS=1; RST=1; RST=0; delayms(10); RST=1; delayms(50); initLCM(); delayms(800); SdReg(0x8c);SdCmd(0x40); //?????? // SdReg(0x8c);SdCmd(0x00); //????? Draw_box(0,639,0,479,RED); delayms(1000); Draw_box(0,639,0,479,GREEN); delayms(1000); Draw_box(0,639,0,479,BLUE); delayms(1000); Draw_box(0,639,0,479,WHITE); delayms(1000); Draw_box(0,639,0,479,BLACK); delayms(1000); Draw_box(0,639,0,479,GRAY10); PrintGB2(50,10,BLUE,3,"??????????????????"); PrintGB2(50,80,BLUE,1,"SHENZHEN TOPWAY TECHNOLOGY CO.,LTD"); PrintGB2(150,130,YELLOW,2,"????LMT056DIFWD-xGx"); PrintGB2(150,170,YELLOW,2,"??????640x480"); PrintGB2(150,210,YELLOW,2,"?????????5.0V"); PrintGB2(150,250,YELLOW,2,"???????8080"); PrintGB2(150,290,YELLOW,2,"??????GB2312?????"); PrintGB2(50,340,BLACK,1,"?????????й????????????????·??????????5??20??"); PrintGB2(50,360,BLACK,1,"???????????й??????и??????????·????????????磬3?????1??A431"); PrintGB2(50,380,BLACK,1,"?????????????й??????и??????к?·???????????3?C509??"); PrintGB2(50,400,BLACK,1,"???????????й????????????·?·1500???????????????51??"); PrintGB2(50,420,BLACK,1,"?????????+86(755)81795700 +86(755)81795988"); PrintGB2(50,440,RED,2,"????????www.topwaydisplay.com"); while(1); }