//------------------------------------------------- // Shenzhen TOPWAY Technology Co.,Ltd. // System: W78E516D(12MHz, 6T) // LCD Module: LMT024DNHFWL-XAX // Display Size: 240RGBx320 // Driver/Controller: ILI9341 // Interface: generic mode 1bit_Add 8bit_data // // rev 00: Wang 2017-12-29 // //------------------------------------------------- #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 uchar xdata CmdPort _at_ 0x0000; uchar xdata DataPort _at_ 0x8000; // using 8051 RAM bus as // LCD.RS connect 8051.A15 // LCD.WR connect 8051.WR // LCD.RD connect 8051.RD // i.e. // pointer 0x0nnn for RS=0 // pointer 0x8nnn for RS=1 sbit _CS = P3^4; sbit _RST = P3^5; sbit BL_EN =P3^2; 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 #define KeyStatus P1 uchar bdata btemp; // create a bit accessable byte sbit btemp_b0 = btemp^0; sbit btemp_b1 = btemp^1; sbit btemp_b2 = btemp^2; sbit btemp_b3 = btemp^3; sbit btemp_b4 = btemp^4; sbit btemp_b5 = btemp^5; sbit btemp_b6 = btemp^6; sbit btemp_b7 = btemp^7; uchar VCOMH; uchar VCOML; uchar VCOMOFFSET; uchar BL_Level;//背光初始参数 #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 uint code GRAY_64[]={ 0x0000,0x0020,0x0841,0x0861,0x1082,0x10A2,0x18C3,0x18E3,0x2104,0x2124,0x2945,0x2965,0x3186,0x31A6,0x39C7,0x39E7, 0x4208,0x4228,0x4A49,0x4A69,0x528A,0x52AA,0x5ACB,0x5AEB,0x630C,0x632C,0x6B4D,0x6B6D,0x738E,0x73AE,0x7BCF,0x7BEF, 0x8410,0x8430,0x8C51,0x8C71,0x9492,0x94B2,0x9CD3,0x9CF3,0xA514,0xA534,0xAD55,0xAD75,0xB596,0xB5B6,0xBDD7,0xBDF7, 0xC618,0xC638,0xCE59,0xCE79,0xD69A,0xD6BA,0xDEDB,0xDEFB,0xE71C,0xE73C,0xEF5D,0xEF7D,0xF79E,0xF7BE,0xFFDF,0xFFFF, }; uint code RED_64[]={ 0x0000,0x0000,0x0800,0x0800,0x1000,0x1000,0x1800,0x1800,0x2000,0x2000,0x2800,0x2800,0x3000,0x3000,0x3800,0x3800, 0x4000,0x4000,0x4800,0x4800,0x5000,0x5000,0x5800,0x5800,0x6000,0x6000,0x6800,0x6800,0x7000,0x7000,0x7800,0x7800, 0x8000,0x8000,0x8800,0x8800,0x9000,0x9000,0x9800,0x9800,0xA000,0xA000,0xA800,0xA800,0xB000,0xB000,0xB800,0xB800, 0xC000,0xC000,0xC800,0xC800,0xD000,0xD000,0xD800,0xD800,0xE000,0xE000,0xE800,0xE800,0xF000,0xF000,0xF800,0xF800, }; uint code GREEN_64[]={ 0x0000,0x0020,0x0040,0x0060,0x0080,0x00A0,0x00C0,0x00E0,0x0100,0x0120,0x0140,0x0160,0x0180,0x01A0,0x01C0,0x01E0, 0x0200,0x0220,0x0240,0x0260,0x0280,0x02A0,0x02C0,0x02E0,0x0300,0x0320,0x0340,0x0360,0x0380,0x03A0,0x03C0,0x03E0, 0x0400,0x0420,0x0440,0x0460,0x0480,0x04A0,0x04C0,0x04E0,0x0500,0x0520,0x0540,0x0560,0x0580,0x05A0,0x05C0,0x05E0, 0x0600,0x0620,0x0640,0x0660,0x0680,0x06A0,0x06C0,0x06E0,0x0700,0x0720,0x0740,0x0760,0x0780,0x07A0,0x07C0,0x07E0, }; uint code BLUE_64[]={ 0x0000,0x0000,0x0001,0x0001,0x0002,0x0002,0x0003,0x0003,0x0004,0x0004,0x0005,0x0005,0x0006,0x0006,0x0007,0x0007, 0x0008,0x0008,0x0009,0x0009,0x000A,0x000A,0x000B,0x000B,0x000C,0x000C,0x000D,0x000D,0x000E,0x000E,0x000F,0x000F, 0x0010,0x0010,0x0011,0x0011,0x0012,0x0012,0x0013,0x0013,0x0014,0x0014,0x0015,0x0015,0x0016,0x0016,0x0017,0x0017, 0x0018,0x0018,0x0019,0x0019,0x001A,0x001A,0x001B,0x001B,0x001C,0x001C,0x001D,0x001D,0x001E,0x001E,0x001F,0x001F, }; uint code GRAY_16[]={ 0x0000,0x0000,0x0000,0x0000,0x1082,0x1082,0x1082,0x1082,0x2104,0x2104,0x2104,0x2104,0x3186,0x3186,0x3186,0x3186, 0x4208,0x4208,0x4208,0x4208,0x528a,0x528a,0x528a,0x528a,0x630c,0x630c,0x630c,0x630c,0x738e,0x738e,0x738e,0x738e, 0x8410,0x8410,0x8410,0x8410,0x9492,0x9492,0x9492,0x9492,0xa514,0xa514,0xa514,0xa514,0xb596,0xb596,0xb596,0xb596, 0xc618,0xc618,0xc618,0xc618,0xd69a,0xd69a,0xd69a,0xd69a,0xe71c,0xe71c,0xe71c,0xe71c,0xffff,0xffff,0xffff,0xffff, }; uchar code monoLOGO[]={ /*-- 240x24, 1bpp --*/ 0xFF,0xFF,0xFF,0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,0xFC,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,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}; uchar code monoTITLE[]={ /*-- 240x24, 1bpp --*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00, 0x7C,0x1F,0x7F,0xFF,0x1F,0xFC,0x0F,0xFE,0x00,0x7C,0x7F,0xF8,0x78,0x1F,0x7C,0x1F, 0x7F,0xFF,0x7C,0x1F,0x7C,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x44,0x00,0x42,0x21, 0x40,0x01,0x20,0x02,0x10,0x01,0x00,0x84,0x40,0x04,0x44,0x11,0x44,0x11,0x40,0x01, 0x44,0x11,0x44,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x44,0x00,0x41,0x41,0x40,0x01, 0x40,0x01,0x20,0x00,0x80,0x84,0x40,0x02,0x42,0x11,0x44,0x11,0x40,0x01,0x44,0x11, 0x44,0x00,0x00,0x00,0x00,0x10,0x40,0x00,0x44,0x00,0x40,0x81,0x46,0x31,0x43,0xE1, 0x23,0xF0,0x81,0x04,0x47,0xC1,0x41,0x11,0x44,0x11,0x47,0xF1,0x44,0x11,0x44,0x00, 0x00,0x00,0x00,0x20,0x20,0x00,0x44,0x00,0x40,0x01,0x7A,0x2F,0x44,0x41,0x3C,0x08, 0x82,0x44,0x44,0x21,0x40,0x91,0x44,0x11,0x44,0x1F,0x44,0x11,0x44,0x00,0x00,0x00, 0x00,0x42,0x10,0x00,0x44,0x00,0x44,0x11,0x02,0x20,0x44,0x81,0x00,0x08,0x84,0xC4, 0x44,0x11,0x40,0x51,0x47,0xF1,0x44,0x00,0x44,0x11,0x44,0x00,0x7F,0xF8,0x00,0x85, 0x08,0x00,0x44,0x00,0x46,0x31,0x02,0x20,0x45,0x11,0x03,0xF0,0x85,0x44,0x44,0x11, 0x40,0x31,0x40,0x01,0x47,0xE0,0x44,0x91,0x44,0x00,0x40,0x08,0x01,0x08,0x84,0x00, 0x44,0x00,0x45,0x51,0x02,0x20,0x46,0x31,0x04,0x00,0x89,0x44,0x44,0x11,0x44,0x11, 0x40,0x01,0x40,0x20,0x45,0x51,0x44,0x00,0x40,0x08,0x01,0x10,0x44,0x00,0x44,0x00, 0x44,0x91,0x02,0x20,0x44,0x51,0x08,0x01,0x12,0x44,0x44,0x11,0x46,0x01,0x47,0xF1, 0x40,0x20,0x46,0x31,0x44,0x00,0x40,0x08,0x01,0x1F,0xC4,0x00,0x44,0x00,0x44,0x11, 0x02,0x20,0x40,0x91,0x11,0xFE,0x24,0x44,0x44,0x11,0x45,0x01,0x44,0x11,0x47,0xE0, 0x44,0x11,0x44,0x00,0x7F,0xF8,0x01,0x00,0x04,0x00,0x44,0x1F,0x44,0x11,0x02,0x20, 0x41,0x11,0x22,0x00,0x27,0xC6,0x44,0x21,0x44,0x81,0x44,0x11,0x44,0x00,0x40,0x01, 0x44,0x1F,0x00,0x01,0xF1,0x00,0x04,0x7C,0x47,0xF1,0x44,0x11,0x0E,0x38,0x43,0xE1, 0x23,0xFF,0xA0,0x02,0x47,0xC1,0x44,0x41,0x44,0x11,0x44,0x00,0x40,0x81,0x47,0xF1, 0x00,0x01,0x11,0x1F,0xC4,0x44,0x40,0x01,0x44,0x11,0x08,0x08,0x40,0x01,0x20,0x00, 0xA0,0x02,0x40,0x02,0x44,0x21,0x44,0x11,0x44,0x00,0x41,0x41,0x40,0x01,0x00,0x01, 0x11,0x10,0x44,0x44,0x40,0x01,0x44,0x11,0x08,0x08,0x20,0x02,0x20,0x00,0xBF,0xC6, 0x40,0x04,0x44,0x11,0x44,0x11,0x44,0x00,0x42,0x21,0x40,0x01,0x00,0x01,0x11,0x10, 0x44,0x44,0x7F,0xFF,0x7C,0x1F,0x0F,0xF8,0x1F,0xFC,0x3F,0xFF,0x80,0x7C,0x7F,0xF8, 0x7C,0x0F,0x7C,0x1F,0x7C,0x00,0x7C,0x1F,0x7F,0xFF,0x00,0x01,0xF1,0xF0,0x7C,0x7C, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0xC3,0x0E,0x00,0xE0,0x8E,0x00,0x00,0x00,0x00,0xC0,0x00,0xFB,0xEF,0x80, 0x21,0xC8,0x08,0x20,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01, 0x24,0x91,0x01,0x11,0x91,0x00,0x00,0x00,0x00,0x40,0x00,0x22,0x02,0x00,0x62,0x08, 0x00,0x20,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x91, 0x44,0x12,0x91,0x01,0xE3,0x11,0x38,0x47,0x00,0x22,0x02,0x00,0x22,0x0F,0x18,0xF8, 0x07,0x9C,0x21,0xC5,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x41,0x11,0x28,0x24, 0x91,0x01,0x11,0x0A,0x44,0x48,0x00,0x23,0xC2,0x00,0x23,0xC8,0x88,0x20,0x08,0x22, 0x22,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x11,0x10,0x47,0xD1,0x01, 0xE1,0x04,0x7C,0x47,0x00,0x22,0x02,0x00,0x22,0x28,0x88,0x20,0x08,0x22,0x22,0x24, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x24,0x11,0x28,0x80,0x91,0x01,0x01,0x0A, 0x40,0x40,0x80,0x22,0x02,0x00,0x22,0x28,0x88,0x20,0x08,0x22,0x22,0x24,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xC7,0x8E,0x45,0xF0,0x8E,0x01,0x03,0x91,0x38,0xEF, 0x00,0x22,0x02,0x00,0x71,0xCF,0x1C,0x18,0x07,0x9C,0x71,0xC4,0x00,0x00,0x00,0x00 }; //----------------------------------- // delayms routine //----------------------------------- void delayms(uint m) // 12MHz Xtal, close to ms value { uint j; uint i; for(i=0; i>8; Col_lo=color; SdCmd(0x2a); SdData(0x00); SdData(0x00); SdData(0x01); SdData(0x3f); // 列 SdCmd(0x2b); SdData(0x00); SdData(0x00); SdData(0x00); SdData(0xef); // 行 SdCmd(0x2c);//开始写数据 _CS=0; for(j=0;j<6;j++) for(i=0;i<200;i++) { DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; DataPort=Col_hi;DataPort=Col_lo; } _CS=1; } void FillBox(uint color,x1,y1,w,h) // 起始列x1,起始行y1,宽w,高h { uint x2,y2; uchar i,j; uchar Col_hi,Col_lo; Col_hi=color>>8; Col_lo=color; x2=x1+w-1; y2=y1+h-1; SdCmd(0x2a); SdData(x1>>8); SdData(x1); SdData(x2>>8); SdData(x2);//列 SdCmd(0x2b); SdData(y1>>8); SdData(y1); SdData(y2>>8); SdData(y2);//行 SdCmd(0x2c);//开始写数据 _CS=0; for(j=0;j>8; Col_lo=color; x2=x1+29; y2=y1+29; SdCmd(0x2a); SdData(x1>>8); SdData(x1); SdData(x2>>8); SdData(x2); //列 SdCmd(0x2b); SdData(y1>>8); SdData(y1); SdData(y2>>8); SdData(y2); //行 SdCmd(0x2c);//开始写数据 _CS=0; for(j=0;j<15;j++) { for(i=0;i<15;i++) { DataPort=Col_hi; DataPort=Col_lo; DataPort=0x00; DataPort=0x00; } for(i=0;i<15;i++) { DataPort=0x00; DataPort=0x00; DataPort=Col_hi; DataPort=Col_lo; } } _CS=1; } void monoFill240x24(uint X, uint Y, fg_color, bg_color, uchar *Data ) // show mono data on display with 1=fg_color & 0=bg_color { uchar temp1, temp2; uchar fg_hi, fg_lo; uchar bg_hi, bg_lo; uint i; #define Mbox_w 240 #define Mbox_h 24 SdCmd(0x2a); // set_column_address temp1 = X>>8; temp2 = X; // mask the upper byte SdData(temp1); SdData(temp2); X=X+Mbox_w-1; temp1 = X>>8; // move the upper byte to low byte temp2 = X; // mask the upper byte SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address temp1 = Y>>8; // move the upper byte to low byte temp2 = Y; // mask the upper byte SdData(temp1); SdData(temp2); Y=Y+Mbox_h-1; temp1 = Y>>8; // move the upper byte to low byte temp2 = Y; // mask the upper byte SdData(temp1); SdData(temp2); fg_hi=fg_color>>8; fg_lo=fg_color; bg_hi=bg_color>>8; bg_lo=bg_color; SdCmd(0x2c);// write_memory_start _CS=0; for (i=0; i<(Mbox_w*Mbox_h/8); i++) { btemp=*(Data+i); if (btemp_b7) {DataPort=fg_hi; DataPort=fg_lo;} else {DataPort=bg_hi; DataPort=bg_lo;} if (btemp_b6) {DataPort=fg_hi; DataPort=fg_lo;} else {DataPort=bg_hi; DataPort=bg_lo;} if (btemp_b5) {DataPort=fg_hi; DataPort=fg_lo;} else {DataPort=bg_hi; DataPort=bg_lo;} if (btemp_b4) {DataPort=fg_hi; DataPort=fg_lo;} else {DataPort=bg_hi; DataPort=bg_lo;} if (btemp_b3) {DataPort=fg_hi; DataPort=fg_lo;} else {DataPort=bg_hi; DataPort=bg_lo;} if (btemp_b2) {DataPort=fg_hi; DataPort=fg_lo;} else {DataPort=bg_hi; DataPort=bg_lo;} if (btemp_b1) {DataPort=fg_hi; DataPort=fg_lo;} else {DataPort=bg_hi; DataPort=bg_lo;} if (btemp_b0) {DataPort=fg_hi; DataPort=fg_lo;} else {DataPort=bg_hi; DataPort=bg_lo;} } _CS=1; } //==========背光================ void BL_inc() { uchar t; if(BL_Level>0) BL_Level--; if(BL_Level==0) { BL_EN=0; delayms(3); BL_EN=1; } // recount count form full-on else { for(t=0;t<31;t++) { BL_EN=0; _nop_();//_nop_();_nop_();_nop_();_nop_();_nop_(); BL_EN=1; _nop_();//_nop_();_nop_();_nop_();_nop_();_nop_(); } } } void BL_dec() { // uchar t; if(BL_Level<32) BL_Level++; // total no of levels = 32 + 1 BL_Level=BL_Level+4; if(BL_Level>=32){BL_EN=0;delayms(3);} // LEVEL32=off else { BL_EN=0; _nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); BL_EN=1; _nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); } } void BL_init(void) { uchar t ; for(t=0;t<10;t++) { BL_EN=0; _nop_();//_nop_();_nop_(); BL_EN=1; _nop_();//_nop_();_nop_(); } } //----------------------------------------------- // initial IC //----------------------------------------------- void init(void) { VCOMH=0x28; /* VCOMH = 3.70V */ VCOML=0x25; /* VCOML = -1.575V */ VCOMOFFSET=0xc4; /* offset VCOMH and VCOML -14 steps, details TBD */ _RST=1; delayms(10); // wait for all power stable _RST=0; delayms(1); // reset pulse _RST=1; delayms(800); // wait till internal reset routine finish SdCmd(0xcf); /* undocumented command from IC example */ SdData(0x00); SdData(0xD9); /* Changed from 0x81 to 0xD9 */ SdData(0x30); SdCmd(0xed); /* undocumented command from IC example */ SdData(0x64); SdData(0x03); SdData(0x12); SdData(0x81); SdCmd(0xe8); /* undocumented command from IC example */ SdData(0x85); SdData(0x10);// SdData(0x7a); SdCmd(0xcb); /* AP[2:0], undocumented cmd from IC example */ SdData(0x39); SdData(0x2c); SdData(0x00); SdData(0x34); SdData(0x02); SdCmd(0xf7); /* undocumented cmd from IC example */ SdData(0x20); SdCmd(0xea); /* undocumented cmd from IC example */ SdData(0x00); SdData(0x00); SdCmd(0xc0); /* Power Control 1 */ SdData(0x21); /* VRH[5:0], details TBD */ SdCmd(0xc1); /* Power Control 2 */ SdData(0x11); /* SAP[2:0], BT[3:0] */ SdCmd(0xc5); /* VCOM Control 1 */ SdData(VCOMH); /* VCOMH = 3.70V */ SdData(VCOML); /* VCOML = -1.575V */ /* compromise value for Tianma and EDT */ SdCmd(0xc7); /* VCOM Control 2 */ SdData(VCOMOFFSET); /* offset VCOMH and VCOML -14 steps, details TBD */ SdCmd(0x36); /* Memory Access Control */ SdData(0x68); /* BGR sub-pixel ordering on panel */ SdCmd(0xb1); /* Frame Rate Control */ SdData(0x00); /* fosc/1 */ SdData(0x1f); /* 31 clocks/line (61Hz) */ SdCmd(0xb6); /* Display Function Control */ SdData(0x0a); /* non-display area scan mode */ SdData(0xa2); /* default output scan direction = S1->S270 */ SdCmd(0xf2); /* 3Gamma function disable */ SdData(0x00); SdCmd(0x26); /* gamma curve selected, from IC example */ SdData(0x01); /* details TBD */ SdCmd(0xE0); SdData(0x00); SdData(0x21); SdData(0x1D); SdData(0x0A); SdData(0x10); SdData(0x09); SdData(0x4B); SdData(0xA9); SdData(0x3A); SdData(0x0A); SdData(0x10); SdData(0x04); SdData(0x14); SdData(0x15); SdData(0x00); SdCmd(0xE1); SdData(0x0F); SdData(0x1C); SdData(0x22); SdData(0x05); SdData(0x11); SdData(0x06); SdData(0x34); SdData(0x56); SdData(0x46); SdData(0x05); SdData(0x0F); SdData(0x0B); SdData(0x29); SdData(0x3A); SdData(0x0F); SdCmd(0x3a); /* Pixel format Set */ SdData(0x55); /* BGR = 16 BPP,MCU = 16bit pixel*/ // SdData(0x66); /* BGR = 16 bpp,MCU = 16bit pixel */ SdCmd(0x28); /* Display Off */ SdCmd(0x00); /* NOP */ SdCmd(0x11); /* Sleep Out */ delayms(130); /* spec 120ms min */ SdCmd(0x29); /* Display On */ } //----------------------------------- // Main Program主程序 //----------------------------------- void main() { EA=0; // no interrupt _CS = 1; _RST = 1; BL_EN = 0; BL_Level=10; init(); BL_init(); //初始背光亮度70% FillFullScn(BLACK); FillBox(mid_re, 1, 2,72,53); Checker30x30(RED, 22, 14); FillBox(mid_or, 83, 2,72,53); FillBox(mid_ye,165, 2,72,53); FillBox(mid_yg,247, 2,72,53); FillBox(mid_gr,247, 63,72,53); Checker30x30(GREEN,268, 75); FillBox(mid_gc,247,124,72,53); FillBox(mid_cy,247,185,72,53); FillBox(mid_cb,165,185,72,53); FillBox(mid_bl, 83,185,72,53); Checker30x30(BLUE,104,197); FillBox(mid_bm, 1,185,72,53); FillBox(mid_ma, 1,124,72,53); FillBox(mid_mr, 1, 63,72,53); monoFill240x24(40, 98, GRAY04, BLACK, monoLOGO); monoFill240x24(40, 124, GRAY04, BLACK, monoTITLE); while(1) {} } //end