//------------------------------------------------- // Shenzhen TOPWAY Technology Co.,Ltd. // LCD Module: LMT043DNFFWD-NCA/TCB043M // System: W78E516D(12MHz, 6T) // Display Size: 480(RGB)x272 // Driver/Controller: S1D13L01 // Interface: I/O 80mode // Version: V01 // Date: 2015-12-24 // by Bill // note: PLL mode 10M CLKI 54M MCLK 9M PCLK // Base on T0104201 modify //------------------------------------------------- #include #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 I/O //----------------------------------- #define LCDBUS P1 sbit A0 = P3^3; sbit _CS = P3^1; sbit _RST = P3^2; sbit _RD = P3^4; sbit _WR = P3^5; sbit BL_ADJ = P3^6; //----------------------------------- // define 16bit colors //----------------------------------- #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 0x8008 // #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 // //----------------------------------------------------------------------------- // 240W*24H*16bit_TOPWAY(mono).bmp code //----------------------------------------------------------------------------- uchar code monoLOGO[]={ 0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0x80,0x01,0xFF,0xFF,0xFF,0xE0,0x7F,0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0x07,0xFF,0xC0,0x01,0xFF,0xF0, 0x07,0xFF,0xC0,0x00,0x00,0x0F,0xFF,0x00,0x00,0x07,0xFF,0xFF,0xF0,0x01,0xFF,0xF0, 0x00,0x00,0x00,0xFF,0xFC,0x00,0x7F,0xFE,0x07,0xFF,0xC0,0x01,0xFF,0xF0,0x07,0xFF, 0xC0,0x00,0x00,0x0F,0xFF,0x00,0x00,0x00,0xFF,0xFF,0x80,0x01,0xFF,0xF0,0x00,0x00, 0x00,0x7F,0xF8,0x00,0x3F,0xFC,0x0F,0xFF,0x80,0x00,0xFF,0xF8,0x07,0xFF,0xC0,0x00}; // //----------------------------------------------------------------------------- // 240W*24H*16bit_LMT043DNFFWU-NCA / TCB043M(mono).bmp code //----------------------------------------------------------------------------- uchar code monoModule[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00, 0x04,0x00,0x00,0x00,0x38,0x38,0xEF,0xE1,0xC0,0x20,0xF1,0xF8,0xE7,0x7F,0x3F,0x9B, 0xBF,0xC0,0x03,0x9C,0x3E,0x08,0x00,0x00,0x80,0x07,0xF0,0xFB,0xF0,0x38,0x04,0x1E, 0x38,0xE0,0x10,0x18,0xC9,0x22,0x20,0x61,0x08,0x84,0x62,0x20,0x90,0x49,0x24,0x20, 0x01,0x88,0x42,0x08,0x00,0x01,0x80,0x04,0x91,0x09,0x08,0x44,0x0C,0x21,0x18,0xC0, 0x10,0x18,0xC9,0x24,0x10,0xA1,0x08,0x82,0x62,0x22,0x11,0x09,0x24,0x10,0x01,0x88, 0x42,0x14,0x00,0x01,0x00,0x04,0x91,0x09,0x08,0x82,0x14,0x21,0x18,0xC0,0x10,0x18, 0xC1,0x04,0x11,0x20,0x10,0x82,0x52,0x22,0x11,0x09,0x24,0x10,0x01,0x48,0x80,0x14, 0x00,0x01,0x00,0x00,0x82,0x01,0x08,0x82,0x24,0x02,0x18,0xC0,0x10,0x15,0x41,0x04, 0x11,0x20,0x60,0x82,0x52,0x3E,0x1F,0x09,0x24,0x13,0xF9,0x48,0x80,0x14,0x00,0x02, 0x00,0x00,0x82,0x01,0xF0,0x82,0x24,0x0C,0x15,0x40,0x10,0x15,0x41,0x04,0x12,0x20, 0x10,0x82,0x4A,0x22,0x11,0x0A,0xA4,0x10,0x01,0x28,0x80,0x22,0x00,0x02,0x00,0x00, 0x82,0x01,0x08,0x82,0x44,0x02,0x15,0x40,0x10,0x15,0x41,0x04,0x12,0x20,0x08,0x82, 0x4A,0x22,0x11,0x0A,0xA4,0x10,0x01,0x28,0x80,0x3E,0x00,0x04,0x00,0x00,0x82,0x01, 0x04,0x82,0x44,0x01,0x15,0x40,0x10,0x12,0x41,0x04,0x11,0xF0,0x08,0x82,0x4A,0x20, 0x10,0x0A,0xA4,0x10,0x01,0x28,0x80,0x22,0x00,0x04,0x00,0x00,0x82,0x01,0x04,0x82, 0x3E,0x01,0x12,0x40,0x10,0x12,0x41,0x04,0x10,0x21,0x08,0x82,0x46,0x20,0x10,0x04, 0x44,0x10,0x01,0x18,0x82,0x41,0x00,0x0C,0x00,0x00,0x82,0x09,0x04,0x82,0x04,0x21, 0x12,0x40,0x10,0x92,0x41,0x02,0x20,0x21,0x08,0x84,0x46,0x20,0x10,0x04,0x44,0x20, 0x01,0x18,0x44,0x41,0x00,0x08,0x00,0x00,0x81,0x11,0x04,0x44,0x04,0x21,0x12,0x40, 0x3F,0xBA,0xE3,0x81,0xC0,0xF8,0xF1,0xF8,0xE2,0x70,0x38,0x04,0x4F,0xC0,0x03,0x88, 0x38,0xE3,0x80,0x08,0x00,0x01,0xC0,0xE3,0xF8,0x38,0x1F,0x1E,0x3A,0xE0,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; // //----------------------------------------------------------------------------- // delayms routine // Parameter:m = time in ms //----------------------------------------------------------------------------- void delayms(uint m) // 12MHz Crystal, close to ms value { uint j; uint i; for(i=0; i>8; Ddata18=Command>>16; A0 = 0; _CS = 0; LCDBUS = Command; // Write the 1st lower 8bit(A7-0) _WR = 0; _WR = 1; LCDBUS = Ddata15; // Write the 2nd lower 8bit(A15-8) _WR = 0; _WR = 1; LCDBUS = Ddata18; // Write the highest 3bit(A18-16) _WR = 0; _WR = 1; _CS=1; } // //----------------------------------------------------------------------------- // Write 16bit Data Command routine // Parameter:Write Data // 1. Write the low 8bit // 2. Write the high 8bit //----------------------------------------------------------------------------- void SdData(uint DData) { A0 = 1; _CS = 0; LCDBUS = DData; // Write the low 8bit(D7-0) _WR = 0; _WR = 1; LCDBUS = DData>>8; // Write the high 8bit(D15-8) _WR = 0; _WR = 1; _CS=1; } // //----------------------------------------------------------------------------- // Fill Box routine // Parameter:fill color,start position of X,start position of Y, width of Box, High of Box // 1. Write the start Address // 2. Write the Horizontal Data // 3. Change the next Horizontal Address // 4. Write next Horizontal Data //----------------------------------------------------------------------------- void FillBox(uint color,x,y,w,h) { ulong addr; uint i,j; addr=960; addr=addr*y; addr=addr+x*2; for(i=0;i CLKI = 10 MHz / 5 => 2MHz SdCmd(0x60814); SdData(0x0018); // L = 0x18 => POCLK = 2MHz * 27 = 54 MHz SdCmd(0x60810); SdData(0x0001); // Don't Enable PLL, Bypass delayms(100); SdCmd(0x60816); SdData(0x0006); // With PLL: PCLK := 54MHz / 6 = 9MHz SdCmd(0x60804); SdData(0x0001); // Enable Memory Power / Clock delayms(100); // Panel setting SdCmd(0x60820); SdData(0x008F); // DE is low, Data ready on PCLK rising edge, 24bit enabled SdCmd(0x60822); SdData(0x0001); // TE is off, Inverted Data SdCmd(0x60824); SdData(0x003C); // The display period of HS = 480/8 = 60 SdCmd(0x60826); SdData(0x002D); // The empty period of HS = 525-480=45 SdCmd(0x6082c); SdData(0x0002); // HS Polarity = 0, Pulse width = 2 SdCmd(0x6082e); SdData(0x0002); // The start position of HS = 2 SdCmd(0x60828); SdData(0x0110); // The display period of VS = 272 SdCmd(0x6082a); SdData(0x000E); // The empty period of VS = 286-272=14 //new TFT is set to 0x000D, old TFT is set to 0x000E SdCmd(0x60830); SdData(0x0002); // VS Polarity = 0, Pulse width = 2 SdCmd(0x60832); SdData(0x0002); // The start position of VS = 2 // Main Panel RAM setting SdCmd(0x60840); SdData(0x0001); // Main Panel&PIP enable, and Main Panel display data is RGB=5:6:5 SdCmd(0x60842); SdData(0x0000); // The start Address of Main Panel = 00000h SdCmd(0x60844); SdData(0x0000); // // PIP RAM setting SdCmd(0x60850); SdData(0x0001); // PIP display data is RGB=565 SdCmd(0x60852); SdData(0xFF70); // The start Address of PIP Panel = 3FF70h SdCmd(0x60854); SdData(0x0003); // SdCmd(0x60856); SdData(0x0064); // Display width of PIP = 100 SdCmd(0x60858); SdData(0x0039); // Display width of PIP = 57 SdCmd(0x6085a); SdData(0x0000); // The start position of X of PIP = 0 SdCmd(0x6085c); SdData(0x0000); // The start position of Y of PIP = 0 SdCmd(0x60860); SdData(0x0000); // No PIP SdCmd(0x60862); SdData(0x0000); // SdCmd(0x60864); SdData(0x0000); // Transparency disable SdCmd(0x60866); SdData(0x0000); // Transparency Key Color setting SdCmd(0x60868); SdData(0x0000); // Transparency Key Color setting //GPIO setting SdCmd(0x608D0); SdData(0x0007); // GPIO3 is input, GPIO[2:0] are output SdCmd(0x608D2); SdData(0x0007); // GPIO[2:0] output high,TFT display normal mode SdCmd(0x60804); SdData(0x0002); // PSM1 Mode, Enable Mem and Panel Clock delayms(100); } // //----------------------------------------------------------------------------- // Main program // 1. I/O initialization // 2. Reset MCU // 3. LCD initialization // 4. Loop Fill Picture //----------------------------------------------------------------------------- void main() { EA=0; // no interrupt _WR=1; _RD=1; _CS = 1; BL_ADJ=0; // Close the Backlight of TFT _RST=1; delayms(100); // wait for all power stable _RST=0; delayms(100); // reset pulse _RST=1; delayms(800); // wait till internal reset routine finish initLCM(); // LCD initialization FillBox(BLACK, 0, 0, 480,272); FillBox(mid_re, 19, 18, 103,53); FillBox(mid_or, 132, 18, 103,53); FillBox(mid_ye, 245, 18, 103,53); FillBox(mid_yg, 358, 18, 103,53); FillBox(mid_gr, 358, 79, 103,53); FillBox(mid_gc, 358, 140, 103,53); FillBox(mid_cy, 358, 201, 103,53); FillBox(mid_cb, 245, 201, 103,53); FillBox(mid_bl, 132, 201, 103,53); FillBox(mid_bm, 19, 201, 103,53); FillBox(mid_ma, 19, 140, 103,53); FillBox(mid_mr, 19, 79, 103,53); monoFill(24, 30, 120, 114, GRAY04, BLACK, monoLOGO); monoFill(24, 30, 120, 140, GRAY04, BLACK, monoModule); BL_ADJ=1; // Open the Backlight of TFT while(1); } // //----------------------------------------------------------------------------- // End off //-----------------------------------------------------------------------------