//------------------------------------------------- // Shenzhen TOPWAY Technology Co.,Ltd. // LCD Module: LMT035-NHN // System: W78E516D(12MHz, 6T) // Display Size: 320(RGB)x240 // Driver/Controller: S1D13L01 // Interface: I/O SPImode // Version: V2, add TFT initialization // Date: 2017-10-16 // by Zhong // note: PLL mode 10M CLKI 66M MCLK 6.6M PCLK //------------------------------------------------- #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 //----------------------------------- sbit _CS = P3^1; sbit _RST = P3^2; sbit SCLK = P3^5; sbit BL_ADJ = P3^6; sbit MOSI = P1^0; sbit MISO = P1^1; sbit SPI_EN = P3^7; // //----------------------------------- // 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 // //----------------------------------------------------------------------------- // 160W*53H*16bit_TOPWAY(mono).bmp code //----------------------------------------------------------------------------- uchar code TOPWAY[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0x00,0x3F,0xE0,0x07,0xFF, 0xF8,0x0F,0xC7,0xF3,0xF8,0x03,0xF8,0x03,0xF8,0x00,0xFE,0x00,0x1F,0xFF,0xFF,0x00, 0xFF,0xF8,0x07,0xFF,0xFE,0x0F,0xC7,0xF3,0xF8,0x03,0xF8,0x01,0xFC,0x01,0xFC,0x00, 0x1F,0xFF,0xFF,0x01,0xFF,0xFC,0x07,0xFF,0xFF,0x0F,0xE7,0xF3,0xF8,0x03,0xF8,0x01, 0xFC,0x01,0xF8,0x00,0x00,0x3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FC,0x07,0xF0,0x01,0xFC,0x00,0x00,0x00,0x3F,0x80,0x0F, 0xE0,0x3F,0x87,0xF0,0x00,0x01,0xFE,0x3F,0xC1,0xFC,0x07,0xF0,0x01,0xFC,0x00,0x00, 0x00,0x3F,0x80,0x0F,0xE0,0x3F,0x87,0xF0,0x00,0x01,0xFE,0x3F,0xC1,0xF8,0x03,0xF0, 0x01,0xFC,0x00,0x00,0x00,0x3F,0x80,0x07,0xF0,0x7F,0x07,0xF0,0x00,0x01,0xFE,0x3F, 0x83,0xF8,0x03,0xF8,0x01,0xFC,0x00,0x00,0x00,0x3F,0x80,0x07,0xF0,0x7F,0x07,0xF0, 0x00,0x01,0xFE,0x3F,0x83,0xF8,0x03,0xF8,0x01,0xFC,0x00,0x00,0x00,0x3F,0x80,0x03, 0xFD,0xFE,0x07,0xF0,0x00,0x01,0xFC,0x3F,0x83,0xF8,0x03,0xF8,0x01,0xFC,0x00,0x00, 0x00,0x3F,0x80,0x01,0xFF,0xFC,0x07,0xF0,0x00,0x00,0xFC,0x3F,0x87,0xF0,0x01,0xFC, 0x01,0xFC,0x00,0x00,0x00,0x3F,0x80,0x00,0xFF,0xF8,0x07,0xF0,0x00,0x00,0xFC,0x1F, 0x87,0xF0,0x01,0xFC,0x01,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xE0,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 }; // //----------------------------------------------------------------------------- // 160W*53H*16bit_LMT035KDH03-NHN_320x240pixel(mono).bmp code //----------------------------------------------------------------------------- uchar code Module[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x0C,0x19,0xFE, 0x1F,0x07,0x87,0xF9,0x87,0x7C,0x18,0x61,0xF0,0x78,0x00,0x18,0x66,0x19,0x86,0x00, 0x18,0x0C,0x18,0x30,0x31,0x8C,0xC6,0x01,0x8E,0x67,0x18,0x63,0x18,0xCC,0x00,0x1C, 0x66,0x19,0xC6,0x00,0x18,0x0E,0x38,0x30,0x31,0x98,0x66,0x01,0x9C,0x63,0x18,0x63, 0x19,0x86,0x00,0x1C,0x66,0x19,0xC6,0x00,0x18,0x0E,0x38,0x30,0x60,0xD8,0x66,0x01, 0xB8,0x61,0x98,0x66,0x0D,0x86,0x00,0x1E,0x66,0x19,0xE6,0x00,0x18,0x0E,0x38,0x30, 0x60,0xC0,0x66,0xE1,0xB0,0x61,0x98,0x66,0x0C,0x06,0x00,0x1E,0x66,0x19,0xE6,0x00, 0x18,0x0E,0x38,0x30,0x60,0xC0,0xC7,0x31,0xF0,0x61,0x9F,0xE6,0x0C,0x0C,0xFF,0x9B, 0x67,0xF9,0xB6,0x00,0x18,0x0D,0x58,0x30,0x60,0xC3,0x86,0x19,0xF0,0x61,0x98,0x66, 0x0C,0x38,0x00,0x1B,0x66,0x19,0xB6,0x00,0x18,0x0D,0x58,0x30,0x60,0xC0,0xC0,0x19, 0xD8,0x61,0x98,0x66,0x0C,0x0C,0x00,0x1B,0xE6,0x19,0xBE,0x00,0x18,0x0D,0x58,0x30, 0x60,0xC0,0x60,0x19,0x98,0x61,0x98,0x66,0x0C,0x06,0x00,0x19,0xE6,0x19,0x9E,0x00, 0x18,0x0D,0x58,0x30,0x60,0xD8,0x66,0x19,0x8C,0x61,0x98,0x66,0x0D,0x86,0x00,0x19, 0xE6,0x19,0x9E,0x00,0x18,0x0D,0xD8,0x30,0x31,0x98,0x66,0x19,0x8E,0x63,0x18,0x63, 0x19,0x86,0x00,0x18,0xE6,0x19,0x8E,0x00,0x18,0x0C,0x98,0x30,0x31,0x8C,0xC3,0x31, 0x86,0x63,0x18,0x63,0x18,0xCC,0x00,0x18,0xE6,0x19,0x8E,0x00,0x1F,0xEC,0x98,0x30, 0x1F,0x07,0x81,0xE1,0x87,0x7C,0x18,0x61,0xF0,0x78,0x00,0x18,0x66,0x19,0x86,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x81,0xE0,0x7C, 0x00,0x00,0x00,0x00,0x78,0x03,0x07,0xC0,0x01,0xF8,0x0C,0x00,0x00,0x00,0x30,0x00, 0x0C,0xC3,0x30,0xC6,0x00,0x03,0x00,0x00,0xCC,0x07,0x0C,0x60,0x01,0x8C,0x0C,0x00, 0x00,0x00,0x30,0x00,0x18,0x66,0x18,0xC6,0x00,0x03,0x00,0x01,0x86,0x07,0x0C,0x60, 0x01,0x86,0x00,0x00,0x00,0x00,0x30,0x00,0x18,0x66,0x19,0x83,0x00,0x33,0x30,0x01, 0x86,0x0B,0x18,0x30,0x01,0x86,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x66,0x19,0x83, 0x00,0x1F,0xE0,0x01,0x86,0x13,0x18,0x30,0x01,0x86,0x0C,0x1C,0xE1,0xE0,0x30,0x00, 0x00,0xC0,0x39,0x83,0x00,0x07,0x80,0x00,0x0E,0x13,0x18,0x30,0x01,0x86,0x0C,0x0C, 0xC3,0x30,0x30,0x00,0x03,0x80,0x31,0x83,0x00,0x0F,0xC0,0x00,0x0C,0x23,0x18,0x30, 0x01,0x8C,0x0C,0x07,0x86,0x18,0x30,0x00,0x00,0xC0,0x61,0x83,0x00,0x3B,0x70,0x00, 0x18,0x63,0x18,0x30,0x01,0xF8,0x0C,0x07,0x87,0xF8,0x30,0x00,0x00,0x60,0xC1,0x83, 0x00,0x13,0x20,0x00,0x30,0x7F,0xD8,0x30,0x01,0x80,0x0C,0x03,0x06,0x00,0x30,0x00, 0x18,0x61,0x81,0x83,0x00,0x03,0x00,0x00,0x60,0x03,0x18,0x30,0x01,0x80,0x0C,0x07, 0x86,0x00,0x30,0x00,0x18,0x63,0x00,0xC6,0x00,0x03,0x00,0x00,0xC0,0x03,0x0C,0x60, 0x01,0x80,0x0C,0x07,0x86,0x18,0x30,0x00,0x0C,0xC6,0x00,0xC6,0x00,0x00,0x00,0x01, 0x80,0x03,0x0C,0x60,0x01,0x80,0x0C,0x0C,0xC3,0x30,0x30,0x00,0x07,0x87,0xF8,0x7C, 0x00,0x00,0x00,0x01,0xFE,0x03,0x07,0xC0,0x01,0x80,0x0C,0x1C,0xE1,0xE0,0x30,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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; i0;SPI_count--) { SCLK=0; MOSI=MCU_Writebyte&0x80; SCLK=1; MCU_Writebyte=MCU_Writebyte<<1; } MOSI=1; SCLK=0; return MCU_Writebyte; } // //----------------------------------------------------------------------------- // Write 19bit Address Command routine // Parameter:Write Address // 1. Write the 1st lower 8bit // 2. Write the 2nd lower 8bit // 3. Write the highest 3bit //Mode 0 and Mode 3 latch the data on the rising edge of the clock and shift the data on the falling edge of the clock. //The idle state of SCK is low for Mode 0, and high for Mode 3. //This means that Mode 0 always starts with latching the data and Mode 3 always starts with shifting the data. //For both Mode 0 and Mode 3, the MSB is first. The accessing cycle always starts after the SCS# falling edge. //When the accessing cycle starts, the first byte must be command 8-bit, the second byte must be verbose 5-bit and //upper address 3-bit, the third byte must be middle address 8-bit, the fourth byte must be lower address 8-bit. //From the fifth byte on, it depends on the command in the first byte. //The accessing cycle is broken by SCS# rising edge. //----------------------------------------------------------------------------- void SetAddr(ulong Command) { _CS = 1; SCLK = 0; _CS = 0; HAL_SPI_ReadWrite(0x80); HAL_SPI_ReadWrite(Command>>16); HAL_SPI_ReadWrite(Command>>8); HAL_SPI_ReadWrite(Command); // Write the highest 3bit(A18-16) } // //----------------------------------------------------------------------------- // Write 16bit Data Command routine // Parameter:Write Data // 1. Write the low 8bit // 2. Write the high 8bit //----------------------------------------------------------------------------- void Write_16(uint DData) { HAL_SPI_ReadWrite(DData); HAL_SPI_ReadWrite(DData>>8); _CS=1; } //----------------------------------- // TFT driver Reg setting //----------------------------------- void SPI_Write8(uchar RegAdd, uchar RegDat) // T8000 and TFT SPI connection // GPIO0=_SENA, GPIO1=SCLK, GPIO2=SDIN // using S1D13L01 GPIO to sent command into TFT SPI port { uchar i; SetAddr(0x608D0); Write_16(0x0007); // GPIO3 is input, GPIO[2:0] are output SetAddr(0x608D2); Write_16(0x0007); //SENA=1; SCLK=1;SDIN=1; for(i=0; i<8; i++) // write the address { if(RegAdd&0x80) { SetAddr(0x608D2);Write_16(0x0004); //SENA=0; SCLK=0;SDIN=1; SetAddr(0x608D2);Write_16(0x0006); //SENA=0; SCLK=1;SDIN=1; SetAddr(0x608D2);Write_16(0x0004); //SENA=0; SCLK=0;SDIN=1; } else { SetAddr(0x608D2);Write_16(0x0000); //SENA=0; SCLK=0;SDIN=0; SetAddr(0x608D2);Write_16(0x0002); //SENA=0; SCLK=1;SDIN=0; SetAddr(0x608D2);Write_16(0x0000); //SENA=0; SCLK=0;SDIN=0; } RegAdd=RegAdd<<1; } for(i=0; i<8; i++) // write the data { if(RegDat&0x80) { SetAddr(0x608D2);Write_16(0x0004); //SENA=0; SCLK=0;SDIN=1; SetAddr(0x608D2);Write_16(0x0006); //SENA=0; SCLK=1;SDIN=1; SetAddr(0x608D2);Write_16(0x0004); //SENA=0; SCLK=0;SDIN=1; } else { SetAddr(0x608D2);Write_16(0x0000); //SENA=0; SCLK=0;SDIN=0; SetAddr(0x608D2);Write_16(0x0002); //SENA=0; SCLK=1;SDIN=0; SetAddr(0x608D2);Write_16(0x0000); //SENA=0; SCLK=0;SDIN=0; } RegDat=RegDat<<1; } SetAddr(0x608D2);Write_16(0x0007); //SENA=1; SCLK=1;SDIN=1; } // //----------------------------------- // TFT driver Reg setting //----------------------------------- void TFT_Init(void) { SPI_Write8(0x02,0x07);//R00 SPI_Write8(0x06,0x00);//R01 SPI_Write8(0x0A,0x03);//R02 SPI_Write8(0x0E,0xCC);//R03 SPI_Write8(0x12,0x46);//R04 SPI_Write8(0x16,0x0D);//R05 SPI_Write8(0x1A,0x00);//R06 SPI_Write8(0x1E,0x00);//R07 SPI_Write8(0x22,0x08);//R08 SPI_Write8(0x26,0x40);//R09 SPI_Write8(0x2A,0x88);//R0A SPI_Write8(0x2E,0x88);//R0B SPI_Write8(0x32,0x20);//R0C SPI_Write8(0x36,0x20);//R0D SPI_Write8(0x3A,0x68);//R0E SPI_Write8(0x3E,0xA5);//R0F SPI_Write8(0x42,0x04);//R10 SPI_Write8(0x46,0x24);//R11 SPI_Write8(0x4A,0x24);//R12 SPI_Write8(0x7A,0x05);//R1E SPI_Write8(0x82,0x00);//R20 } void Write_Color(uint color) { HAL_SPI_ReadWrite(color); HAL_SPI_ReadWrite(color>>8); } //----------------------------------------------------------------------------- // Fill full screen routine // Parameter:fill color // 1. Write the start Address // 2. Write the Horizontal Data // 3. Change the next Horizontal Address // 4. Write next Horizontal Data //----------------------------------------------------------------------------- void FillFullScn(uint color) { ulong addr; uint i,j; addr=0; for(i=0;i<240;i++) { SetAddr(addr); // Write the start Address for(j=0;j<320;j++) { Write_Color(color); } _CS=1; addr=addr+640; // Next Horizontal Address } } // //----------------------------------------------------------------------------- // 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=640; addr=addr*y; addr=addr+x*2; for(i=0;i CLKI = 10 MHz / 5 => 2MHz SetAddr(0x060814); Write_16(0x0020); // L = 0x20 => POCLK = 2MHz * 33 = 66 MHz SetAddr(0x060810); Write_16(0x0001); // Don't Enable PLL, Bypass delayms(200); SetAddr(0x60816); Write_16(0x0008); // With PLL: PCLK := 66MHz / 10 = 6.6MHz SetAddr(0x60804); Write_16(0x0001); // Enable Memory Power / Clock delayms(200); // Panel setting SetAddr(0x60820); Write_16(0x008f); // DE is low, Data ready on PCLK rising edge, 24Bit enabled SetAddr(0x60822); Write_16(0x0001); // TE is off, Inverted Data SetAddr(0x60824); Write_16(0x0028); // The display period of HS = 320/8 = 40 SetAddr(0x60826); Write_16(0x0058); // The empty period of HS = 88 SetAddr(0x6082c); Write_16(0x0002); // HS Polarity = 0, Pulse width = 2 SetAddr(0x6082e); Write_16(0x0012); // The start position of HS = 18 SetAddr(0x60828); Write_16(0x00f0); // The display period of VS = 240 SetAddr(0x6082a); Write_16(0x0015); // The empty period of VS = 22 SetAddr(0x60830); Write_16(0x0001); // VS Polarity = 0, Pulse width = 1 SetAddr(0x60832); Write_16(0x0008); // The start position of VS = 8 // Main Panel RAM setting SetAddr(0x60840); Write_16(0x0001); // Main Panel&PIP enable, and Main Panel display data is RGB=565 SetAddr(0x60842); Write_16(0x0000); // The start Address of Main Panel = 00000h SetAddr(0x60844); Write_16(0x0000); // // PIP RAM setting SetAddr(0x60850); Write_16(0x0001); // PIP display data is RGB=565 SetAddr(0x60852); Write_16(0x6000); // The start Address of Main Panel = 26000h SetAddr(0x60854); Write_16(0x0002); // SetAddr(0x60856); Write_16(0x0096); // Display width of PIP = 150 SetAddr(0x60858); Write_16(0x0055); // Display width of PIP = 85 SetAddr(0x6085a); Write_16(0x0000); // The start position of X of PIP = 0 SetAddr(0x6085c); Write_16(0x0000); // The start position of Y of PIP = 0 SetAddr(0x60860); Write_16(0x0000); // No PIP SetAddr(0x60862); Write_16(0x0000); // SetAddr(0x60864); Write_16(0x0000); // Transparency disable SetAddr(0x60866); Write_16(0x0000); // Transparency Key Color setting SetAddr(0x60868); Write_16(0x0000); // Transparency Key Color setting // GPIO setting SetAddr(0x608D0); Write_16(0x0007); // GPIO3 is input, GPIO[2:0] are output SetAddr(0x608D2); Write_16(0x0007); // GPIO[2:0] output high SetAddr(0x60804); Write_16(0x0002); // PSM1 Mode, Enable Mem and Panel Clock delayms(200); } // //----------------------------------------------------------------------------- // Main program // 1. I/O initialization // 2. Reset MCU // 3. LCD initialization // 4. Fill Picture // 5. Loop forever //----------------------------------------------------------------------------- void main() { EA=0; // no interrupt _CS = 1; BL_ADJ=1; // Open the Backlight of TFT MISO=1; MOSI=1; SCLK=0; _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 TFT_Init(); // TFT initialization FillFullScn(BLACK); FillBox(mid_re, 0, 0,72,53); Checker30x30(RED, 22, 14); FillBox(mid_or, 83, 0,72,53); FillBox(mid_ye,165, 0,72,53); FillBox(mid_yg,247, 0,72,53); FillBox(mid_gr,247, 63,72,53); Checker30x30(GREEN,268, 75); FillBox(mid_gc,247,124,72,53); FillBox(mid_cy,247,186,72,53); FillBox(mid_cb,165,186,72,53); FillBox(mid_bl, 83,186,72,53); Checker30x30(BLUE,104,197); FillBox(mid_bm, 0,186,72,53); FillBox(mid_ma, 0,124,72,53); FillBox(mid_mr, 0, 63,72,53); monoFill160x53(83, 63, GRAY04, BLACK, TOPWAY ); monoFill160x53(83, 124, GRAY04, BLACK, Module ); while(1); } // //----------------------------------------------------------------------------- // End off //-----------------------------------------------------------------------------