//------------------------------------------------- // Shenzhen TOPWAY Technology Co.,Ltd. // System: W78E516D(12MHz, 6T) // LCD Module: LMT032DNAFWD-NCA // Display Size: 240RGBx320 // Driver/Controller: ILI9341 // Interface: generic mode 1bit_Add 8bit_data // // rev 01: guodinglang 2015-04-22 //------------------------------------------------- #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 =P1^5; sbit _TP_CS = P2^1; // TP.CS sbit TP_DCLK = P2^0; // 10k pull up is necessary sbit TP_DIN = P2^2; // sbit TP_BUSY = P1^2; // no use this signal sbit TP_DOUT = P2^3; sbit _TP_PENQ= P2^4; // 0 = touched 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;//背光初始参数 uchar TP_x; // TP data after touch uchar TP_y; #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 uchar code monoLOGO[]={ /*-- 240x24, 1bpp --*/ 0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0x80,0x01,0xFF,0xFF,0xFF,0xE0,0x7F,0xF0, 0x07,0xFF,0xC0,0x1F,0xFC,0x00,0xFF,0xFF,0x81,0xFF,0xFC,0x00,0x7F,0xFF,0xFF,0xFF, 0xFF,0xFF,0xF0,0x07,0xFF,0xFF,0xF0,0x01,0xFF,0xFF,0xFF,0xF8,0x7F,0xF0,0x0F,0xFF, 0xE0,0x1F,0xFC,0x01,0xFF,0xFF,0xC0,0xFF,0xFE,0x00,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF, 0xF0,0x1F,0xFF,0xFF,0xFC,0x01,0xFF,0xFF,0xFF,0xFC,0x3F,0xF8,0x0F,0xFF,0xE0,0x3F, 0xF8,0x01,0xFF,0xFF,0xC0,0x7F,0xFF,0x01,0xFF,0xFC,0xFF,0xFF,0xFF,0xFF,0xF0,0x7F, 0xFF,0xFF,0xFF,0x01,0xFF,0xFF,0xFF,0xFE,0x3F,0xF8,0x1F,0xFF,0xF0,0x3F,0xF8,0x03, 0xFF,0xFF,0xE0,0x3F,0xFF,0x83,0xFF,0xF8,0xFF,0xFF,0xFF,0xFF,0xF0,0xFF,0xFF,0xFF, 0xFF,0x81,0xFF,0xFF,0xFF,0xFF,0x3F,0xF8,0x1F,0xFF,0xF0,0x3F,0xF8,0x03,0xFF,0xFF, 0xE0,0x1F,0xFF,0xC7,0xFF,0xF0,0xFF,0xFF,0xFF,0xFF,0xF1,0xFF,0xFF,0xFF,0xFF,0x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,0x01,0xFF,0xFE,0x00,0xFF,0xFF,0x03,0xFF, 0xFF,0xFF,0xFF,0xE0,0x07,0xFF,0xC0,0x00,0x00,0x0F,0xFF,0x00,0x00,0x7F,0xFF,0xFF, 0xFF,0x01,0xFF,0xF0,0x00,0x00,0x00,0xFF,0xFE,0x00,0xFF,0xFE,0x03,0xFF,0xE0,0x03, 0xFF,0xE0,0x07,0xFF,0xC0,0x00,0x00,0x0F,0xFF,0x00,0x00,0x1F,0xFF,0xFF,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 --*/ 0xF8,0x00,0xF8,0x3E,0xFF,0xFE,0x3F,0xF8,0x3F,0xF8,0x3F,0xF8,0xFF,0xF0,0xF0,0x3E, 0x03,0x80,0xFF,0xFE,0xF8,0x3E,0xFF,0xF0,0x00,0x00,0x7F,0xFC,0x01,0xC0,0x88,0x00, 0x84,0x42,0x80,0x02,0x40,0x04,0x40,0x04,0x40,0x04,0x80,0x08,0x88,0x22,0x04,0x40, 0x80,0x02,0x88,0x22,0x80,0x08,0x00,0x00,0x40,0x02,0x02,0x20,0x88,0x00,0x82,0x82, 0x80,0x02,0x80,0x02,0x80,0x02,0x80,0x02,0x80,0x04,0x84,0x22,0x08,0x20,0x80,0x02, 0x88,0x22,0x80,0x04,0x00,0x00,0x40,0x01,0x04,0x10,0x88,0x00,0x81,0x02,0x8C,0x62, 0x87,0xC2,0x8F,0xC2,0x8F,0xC2,0x8F,0x82,0x82,0x22,0x10,0x10,0x8F,0xE2,0x88,0x22, 0x8F,0x82,0x00,0x00,0x47,0xE1,0x08,0x08,0x88,0x00,0x80,0x02,0xF4,0x5E,0x88,0x82, 0xF0,0x22,0xF0,0x22,0x88,0x42,0x81,0x22,0x21,0x08,0x88,0x3E,0x88,0x22,0x88,0x42, 0x00,0x00,0x44,0x11,0x10,0x84,0x88,0x00,0x88,0x22,0x04,0x40,0x89,0x02,0x00,0x22, 0x00,0x22,0x88,0x22,0x80,0xA2,0x42,0x84,0x88,0x00,0x88,0x22,0x88,0x22,0xFF,0xC0, 0x44,0x11,0x21,0x42,0x88,0x00,0x8C,0x62,0x04,0x40,0x8A,0x22,0x00,0xC4,0x0F,0xC2, 0x88,0x22,0x80,0x62,0x84,0x42,0x8F,0xC0,0x89,0x22,0x88,0x22,0x80,0x40,0x47,0xE1, 0x42,0x21,0x88,0x00,0x8A,0xA2,0x04,0x40,0x8C,0x62,0x01,0x08,0x10,0x02,0x88,0x22, 0x88,0x22,0x88,0x22,0x80,0x40,0x8A,0xA2,0x88,0x22,0x80,0x40,0x40,0x02,0x44,0x11, 0x88,0x00,0x89,0x22,0x04,0x40,0x88,0xA2,0x00,0xC4,0x20,0x04,0x88,0x22,0x8C,0x02, 0x8F,0xE2,0x80,0x40,0x8C,0x62,0x88,0x22,0x80,0x40,0x47,0xE1,0x47,0xF1,0x88,0x00, 0x88,0x22,0x04,0x40,0x81,0x22,0x00,0x22,0x47,0xF8,0x88,0x22,0x8A,0x02,0x80,0x02, 0x8F,0xC0,0x88,0x22,0x88,0x22,0xFF,0xC0,0x44,0x11,0x40,0x01,0x88,0x3E,0x88,0x22, 0x04,0x40,0x82,0x22,0xF0,0x22,0x88,0x00,0x88,0x42,0x89,0x02,0x80,0x02,0x88,0x00, 0x80,0x02,0x88,0x42,0x00,0x1F,0x44,0x11,0x40,0x01,0x8F,0xE2,0x88,0x22,0x1C,0x70, 0x87,0xC2,0x8F,0xC2,0x8F,0xFE,0x8F,0x82,0x88,0x82,0x8F,0xE2,0x88,0x00,0x81,0x02, 0x8F,0x82,0x00,0x11,0x47,0xE1,0x47,0xF1,0x80,0x02,0x88,0x22,0x10,0x10,0x80,0x02, 0x80,0x02,0x80,0x02,0x80,0x04,0x88,0x42,0x88,0x22,0x88,0x00,0x82,0x82,0x80,0x04, 0x00,0x11,0x40,0x01,0x44,0x11,0x80,0x02,0x88,0x22,0x10,0x10,0x40,0x04,0x40,0x04, 0x80,0x02,0x80,0x08,0x88,0x22,0x88,0x22,0x88,0x00,0x84,0x42,0x80,0x08,0x00,0x11, 0x40,0x02,0x44,0x11,0xFF,0xFE,0xF8,0x3E,0x1F,0xF0,0x3F,0xF8,0x3F,0xF8,0xFF,0xFE, 0xFF,0xF0,0xF8,0x1E,0xF8,0x3E,0xF8,0x00,0xF8,0x3E,0xFF,0xF0,0x00,0x1F,0x7F,0xFC, 0x7C,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x0E,0x38,0xE0,0x0E,0x08,0xE0,0x00,0x20,0x00,0x18,0x00,0x00, 0x01,0x80,0x00,0x07,0xDF,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x11,0x45,0x10,0x11,0x19,0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x80, 0x00,0x01,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0x05,0x14,0x41,0x29,0x10,0x3C,0x62,0x27,0x08,0xE0,0x1E,0x70,0x87,0x16,0x01, 0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x09, 0x12,0x82,0x49,0x10,0x22,0x21,0x48,0x89,0x00,0x20,0x88,0x88,0x98,0x01,0x1E,0x10, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x11,0x11,0x04, 0x7D,0x10,0x3C,0x20,0x8F,0x88,0xE0,0x20,0x88,0x88,0x90,0x01,0x10,0x10,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x21,0x12,0x88,0x09,0x10, 0x20,0x21,0x48,0x08,0x10,0x20,0x88,0x88,0x90,0x01,0x10,0x10,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x7C,0xE4,0x5F,0x08,0xE0,0x20,0x72, 0x27,0x1D,0xE0,0x1E,0x71,0xC7,0x10,0x01,0x10,0x10,0x00,0x00,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--; BL_EN=0; delayms(3); BL_EN=1; // recount count form full-on for(t=0;t>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); XX=X+4+3; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2);// set_column_address SdCmd(0x2b); // set_page_address YY=Y+1; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); YY=Y+1+3; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2c); for (i=0; i<16; i++) {SdData(Col_hi); SdData(Col_lo);} // write_memory_start // top right block SdCmd(0x2a); // set_column_address XX=X+32; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); XX=X+32+3; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address YY=Y+1; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); YY=Y+1+3; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2c); for (i=0; i<16; i++) {SdData(Col_hi); SdData(Col_lo);} // write_memory_start // mid block SdCmd(0x2a); // set_column_address XX=X+16; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); XX=X+16+7; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address YY=Y+13; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); YY=Y+13+3; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2c); for (i=0; i<32; i++) {SdData(Col_hi); SdData(Col_lo);} // write_memory_start // bottom left block SdCmd(0x2a); // set_column_address XX=X+4; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); XX=X+4+3; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address YY=Y+25; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); YY=Y+25+3; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2c); for (i=0; i<16; i++) {SdData(Col_hi); SdData(Col_lo);} // write_memory_start // bottom right block SdCmd(0x2a); // set_column_address XX=X+32; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); XX=X+32+3; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address YY=Y+25; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); YY=Y+25+3; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdCmd(0x2c); for (i=0; i<16; i++) {SdData(Col_hi); SdData(Col_lo);} // write_memory_start for (i=0; i<8; i++) { SdCmd(0x2a); // set_column_address XX=X+8+i; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address YY=Y+5+i; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdData(temp1); SdData(temp2); SdCmd(0x2c); SdData(Col_hi); SdData(Col_lo); // write_memory_start } for (i=0; i<8; i++) { SdCmd(0x2a); // set_column_address XX=X+8+i; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address YY=Y+24-i; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdData(temp1); SdData(temp2); SdCmd(0x2c); SdData(Col_hi); SdData(Col_lo); // write_memory_start } for (i=0; i<8; i++) { SdCmd(0x2a); // set_column_address XX=X+24+i; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address YY=Y+12-i; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdData(temp1); SdData(temp2); SdCmd(0x2c); SdData(Col_hi); SdData(Col_lo); // write_memory_start } for (i=0; i<8; i++) { SdCmd(0x2a); // set_column_address XX=X+24+i; temp1=XX>>8; temp2=XX&0x00ff; SdData(temp1); SdData(temp2); SdData(temp1); SdData(temp2); SdCmd(0x2b); // set_page_address YY=Y+17+i; temp1=YY>>8; temp2=YY&0x00ff; SdData(temp1); SdData(temp2); SdData(temp1); SdData(temp2); SdCmd(0x2c); SdData(Col_hi); SdData(Col_lo); // write_memory_start } } void GetTouchResponse(void) // give out a 5 bit result in TP_x & TP_y // also sense the button { uchar x, y; uchar last_x, last_y ; uchar Verified_AD; // flag for verified AD uchar touched; // while(!_TP_PENQ) {} // ensure it not touched and wait for touch last_x=16; // just init as middle value last_y=16; // just init as middle value Verified_AD=0; touched=0; while (Verified_AD==0) { if (_TP_PENQ==0) // ensure it is touched then start AD { x = TP_IO8(0xd8)>>3; // X-Ch, 8bit, LoPw, with PenInt delayms(1); y = TP_IO8(0x98)>>3; // Y-Ch, 8bit, LoPw, with PenInt touched=1; } if ((last_x==x) && (last_y==y)) // ensure two results are the same { Verified_AD=1; } delayms(100); // de-bouncing if (touched) {last_x=x; last_y=y;} } TP_x=x; TP_y=y; } //=================================================================== // 初始化 //=================================================================== void init(void) { _RST=1; delayms(10); // wait for all power stable _RST=0; delayms(1); // reset pulse _RST=1; delayms(10); // wait till internal reset routine finish VCOMH=0x18; VCOML=0x54; VCOMOFFSET=0x20; //40 SdCmd(0xcf); SdData(0x00); SdData(0xc1); SdData(0x30); SdCmd(0xed); SdData(0x64); SdData(0x03); SdData(0x12); SdData(0x81); SdCmd(0xcb); SdData(0x39); SdData(0x2c); SdData(0x00); SdData(0x34); SdData(0x02); SdCmd(0xea); SdData(0x00); SdData(0x00); SdCmd(0xe8); SdData(0x85); SdData(0x00); SdData(0x7a); SdCmd(0xc0); SdData(0x21); //电源控制 SdCmd(0xc1); SdData(0x12); //倍压设置 SdCmd(0xc5); SdData(VCOMH); SdData(VCOML); // VCOM设置1 SdCmd(0xc7); SdData(VCOMOFFSET|0x80); // VCOM设置2 SdCmd(0x3a); SdData(0x55); // RGB=16bit/pixel, MCU=16bit/pixel SdCmd(0x36); SdData(0xa8); // 横屏显示 BGR=1 SdCmd(0xb1); SdData(0x00); SdData(0x18); // 刷屏设置 18 SdCmd(0xb6); SdData(0x0a); SdData(0xa2); // 功能设定 SdCmd(0x11); //唤醒 delayms(150); SdCmd(0x29); //开显示 } //----------------------------------- // Main Program主程序 //----------------------------------- void main() { bit update_screen; EA=0; // no interrupt _CS = 1; _RST = 1; BL_EN = 0; _TP_CS = 1; // TP.CS TP_DCLK = 0; TP_DIN = 0; TP_DOUT = 1; _TP_PENQ= 1; // 0 = touched BL_Level=8; //初始背光亮度70% init(); BL_inc(); // use this routine to set the backlight bightness update_screen=1; // need update while(1) { if (update_screen) { 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); } GetTouchResponse(); // ressult store in TP_x and TP_y update_screen=0; if(TP_y<=3 ) {BL_inc(); delayms(50);} if(TP_y>=28) {BL_dec(); delayms(50);} RadColor_icon_40x30(TP_x, TP_y); delayms(100); } }