//------------------------------------------------- // Shenzhen TOPWAY Technology Co.,Ltd. // System: AT89S52(12MHz) // LCD Module: LMT035KDH03-NFN (TCB8000J 5.0V) // Display Size: 320(x3)x240 (16bit color) // Driver/Controller: NT39016D+T8000 // Interface: 80mode 1bit Addressing mode // by: Kenny // Date: 2012-02-17 // note: ver01 new // with VCOM_DC discription // //------------------------------------------------- #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 LCDBUS P1 sbit _CS = P3^4; sbit _RES = P3^5; sbit A1 = P3^6; sbit _WR = P3^7; sbit _RD = P3^1; // or _RD=VDD; uchar bdata GpioData; // bit addressable byte sbit SDIN = GpioData^3; sbit SCLK = GpioData^2; sbit SENA = GpioData^1; uchar bdata BitData; //bit addressable byte sbit BitData7=BitData^7; #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 GRAY 0x8410 #define hi_re 0xf800 #define hi_or 0xfc00 #define hi_ye 0xffb0 #define hi_yg 0x87e0 #define hi_gr 0x07e0 #define hi_gc 0x07f0 #define hi_cy 0x07ff #define hi_cb 0x041f #define hi_bl 0x001f #define hi_bm 0x801f #define hi_ma 0xf8f1 #define hi_mr 0xf810 //----------------------------------- // delayms routine //----------------------------------- void delayms(uint m) // 12MHz Xtal, close to ms value { uint j; uint i; for(i=0; i>8; WritePKG(Buffer); } void SetFontFgColor(uint color) { uchar Buffer[4]; Buffer[0]=3; Buffer[1]=0x14; Buffer[2]=color; Buffer[3]=color>>8; WritePKG(Buffer); } void SetFontBgColor(uint color) { uchar Buffer[4]; Buffer[0]=3; Buffer[1]=0x15; Buffer[2]=color; Buffer[3]=color>>8; WritePKG(Buffer); } //----------------------------------- // String Routine //----------------------------------- void PrintASCII(uint X, Y, uchar *pstr) // max 64 byte in the string { uchar TempData[3], Buffer[6], NoOfChar; TempData[0]=2; // use internal 8x8 font TempData[1]=0x10; TempData[2]=0x00; WritePKG(TempData); Buffer[0]=5; // set the location Buffer[1]=0x12; Buffer[2]=X; Buffer[3]=X>>8; Buffer[4]=Y; Buffer[5]=Y>>8; WritePKG(Buffer); NoOfChar=strlen(pstr); // send the string SdCmd(0x17); SdCmd(NoOfChar); while(*pstr>0) { SdCmd(*pstr++); } CmdEnd(); } //------------------------------------------------ // Drawing Shape //------------------------------------------------ void Draw_Line(uint x1, y1, x2, y2) { uchar Buffer[10]; Buffer[0]=9; Buffer[1]=0x24; Buffer[2]=x1; Buffer[3]=x1>>8; Buffer[4]=y1; Buffer[5]=y1>>8; Buffer[6]=x2; Buffer[7]=x2>>8; Buffer[8]=y2; Buffer[9]=y2>>8; WritePKG(Buffer); delayms(5); } void Draw_Rect(uint x1, y1, x2, y2) { uchar Buffer[10]; Buffer[0]=9; Buffer[1]=0x26; Buffer[2]=x1; Buffer[3]=x1>>8; Buffer[4]=y1; Buffer[5]=y1>>8; Buffer[6]=x2; Buffer[7]=x2>>8; Buffer[8]=y2; Buffer[9]=y2>>8; WritePKG(Buffer); delayms(20); } void Fill_Rect(uint x1, y1, x2, y2) { uchar Buffer[10]; Buffer[0]=9; Buffer[1]=0x27; Buffer[2]=x1; Buffer[3]=x1>>8; Buffer[4]=y1; Buffer[5]=y1>>8; Buffer[6]=x2; Buffer[7]=x2>>8; Buffer[8]=y2; Buffer[9]=y2>>8; WritePKG(Buffer); delayms(20); } void dwg_pixel(uint x1, y1) { uchar Buffer[6]; Buffer[0]=5; Buffer[1]=0x23; Buffer[2]=x1; Buffer[3]=x1>>8; Buffer[4]=y1; Buffer[5]=y1>>8; WritePKG(Buffer); delayms(20); } //----------------------------------- // Display set //----------------------------------- void CornerMark(void) { dwg_pixel( 0, 0); dwg_pixel( 0, 1); dwg_pixel( 1, 0); // top left cornor dwg_pixel(318, 0); dwg_pixel(319, 0); dwg_pixel(319, 1); // top right cornor dwg_pixel( 0,238); dwg_pixel( 0,239); dwg_pixel( 1,239); // bot left cornor dwg_pixel(318,239); dwg_pixel(319,239); dwg_pixel(319,238); // bot right cornor } //----------------------------------- // TFT driver Reg setting //----------------------------------- void SdRegVal(uchar RegAdd, uchar RegDat) // T8000 and TFT SPI connection // GpioData.1=_SENA, GpioData.2=SCLK, GpioData.3=SDIN // using T8000 GPIO to sent command into TFT SPI port { uchar i, Buffer[5]; BitData=(RegAdd<<2)+3; // move the RegAdd.5 to the D7, and D1=1 for write, D0=1 for dont care for(i=0; i<8; i++) // write the address { SENA=0; SCLK=0; SDIN=BitData7; Buffer[0]=4; Buffer[1]=0x83; Buffer[2]=0x41; Buffer[3]=0xf2; Buffer[4]=GpioData; WritePKG(Buffer); SCLK=1; Buffer[0]=4; Buffer[1]=0x83; Buffer[2]=0x41; Buffer[3]=0xf2; Buffer[4]=GpioData; WritePKG(Buffer); SCLK=0; Buffer[0]=4; Buffer[1]=0x83; Buffer[2]=0x41; Buffer[3]=0xf2; Buffer[4]=GpioData; WritePKG(Buffer); BitData=BitData<<1; } BitData=RegDat; for(i=0; i<8; i++) // write the data { SENA=0; SCLK=0; SDIN=BitData7; Buffer[0]=4; Buffer[1]=0x83; Buffer[2]=0x41; Buffer[3]=0xf2; Buffer[4]=GpioData; WritePKG(Buffer); SCLK=1; Buffer[0]=4; Buffer[1]=0x83; Buffer[2]=0x41; Buffer[3]=0xf2; Buffer[4]=GpioData; WritePKG(Buffer); SCLK=0; Buffer[0]=4; Buffer[1]=0x83; Buffer[2]=0x41; Buffer[3]=0xf2; Buffer[4]=GpioData; WritePKG(Buffer); BitData=BitData<<1; } SENA=1; Buffer[0]=4; Buffer[1]=0x83; Buffer[2]=0x41; Buffer[3]=0xf2; Buffer[4]=GpioData; WritePKG(Buffer); } //----------------------------------- // init routine //----------------------------------- uchar code Set_F500[]={4,0x83,0x00,0xf5,0x00}; // Reg[f500]=00 (internal MCS0 cycle pulse width) uchar code Set_F504[]={4,0x83,0x04,0xf5,0x04}; // Reg[f504]=44 (internal MCS1 pulse sidth) uchar code Set_F505[]={4,0x83,0x05,0xf5,0x80}; // Reg[f505]=80 (internal MCS1 memory accessing setting) uchar code Set_F6C4[]={4,0x83,0xc4,0xf6,0x10}; // Reg[f505]=80 Set Memory Clock Divide uchar code Set_F080[]={4,0x83,0x80,0xf0,0xfc}; // Reg[f080]=fc,bc,b4 (16bpp TFT) ok uchar code Set_F08E[]={4,0x83,0x8e,0xf0,0x32}; // Reg[f08e]=32 (set pixel clock and LCD_ON) 32 uchar code Set_F090[]={4,0x83,0x90,0xf0,0x12}; // HorFP: 0x12(NT39016D) uchar code Set_F091[]={4,0x83,0x91,0xf0,0x26}; // HorBP-HsyncWidth: 0x46(NT39016D)-(0x1f+0x01)= 0x26 uchar code Set_F092[]={4,0x83,0x92,0xf0,0x1f}; // HsyncWidth: close to half of the HorBP, where 0x1f is max uchar code Set_F094[]={4,0x83,0x94,0xf0,0x0a}; // VerFP: 0x10(NT39016D) uchar code Set_F095[]={4,0x83,0x95,0xf0,0x06}; // VerBp-VsyncWidth: 0x0d(NT39016D)-(0x06+0x01)= 0x06 uchar code Set_F096[]={4,0x83,0x96,0xf0,0x06}; // VerPlusWidth: set to half of the VerBp uchar code Set_8F[]={7,0x8f,0x69,0x45,0x61,0x67,0x6c,0x65}; uchar code Set_F240[]={4,0x83,0x40,0xf2,0x00}; // GPIO as output uchar code Set_F241[]={4,0x83,0x41,0xf2,0x3f}; // GPIO set to 1s void initLCDM(void) { _RES=1; delayms(800); _RES=0; delayms(100); _RES=1; delayms(200); // execute all the setting in above WritePKG(Set_F500); WritePKG(Set_F504); WritePKG(Set_F505); WritePKG(Set_F6C4); WritePKG(Set_8F); WritePKG(Set_F240); WritePKG(Set_F241); // config the GPIO WritePKG(Set_F080); WritePKG(Set_F08E); WritePKG(Set_F090); WritePKG(Set_F091); WritePKG(Set_F092); WritePKG(Set_F094); WritePKG(Set_F095); WritePKG(Set_F096); SdRegVal(0x0e,0x2a+0x40); // set VCOM_DC=0x2a // depends on display content // it may need adjustment } //----------------------------------- // Main Program主程序 //----------------------------------- void main() { SP=0x60; EA=0; LCDBUS=0xff; // init all the port _CS=1; _RES=1; A1=0; _WR=1; _RD=1; initLCDM(); SetFgColor(BLACK); Fill_Rect( 0, 0,319,239); SetFgColor(hi_ma); Fill_Rect( 0, 10, 55, 69); SetFgColor(hi_mr); Fill_Rect( 66, 10,121, 69); SetFgColor(hi_re); Fill_Rect(132, 10,187, 69); SetFgColor(hi_or); Fill_Rect(198, 10,253, 69); SetFgColor(hi_ye); Fill_Rect(264, 10,319, 69); SetFgColor(hi_bm); Fill_Rect( 0, 90, 55,149); SetFgColor(hi_yg); Fill_Rect(264,90,319,149); SetFgColor(hi_bl); Fill_Rect( 0,170, 55,229); SetFgColor(hi_cb); Fill_Rect( 66,170,121,229); SetFgColor(hi_cy); Fill_Rect(132,170,187,229); SetFgColor(hi_gc); Fill_Rect(198,170,253,229); SetFgColor(hi_gr); Fill_Rect(264,170,319,229); SetFontBgColor(BLACK); SetFontFgColor(WHITE); PrintASCII(56, 108, " TOPWAY Technology Co.Ltd."); PrintASCII(56, 124, " LMT035KDH03-xFx "); PrintASCII(56, 132, " "); SetFgColor(WHITE); CornerMark(); while(1) { } }