void Address_set(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) { Lcd_Write_Com(0x2a); // Set_column_address Lcd_Write_Data(x1>>8); // MSB Lcd_Write_Data(x1); // LSB Lcd_Write_Data(x2>>8); // MSB Lcd_Write_Data(x2); // LSB Lcd_Write_Com(0x2b); // Set_page_address Lcd_Write_Data(y1>>8); // MSB Lcd_Write_Data(y1); // LSB Lcd_Write_Data(y2>>8); // MSB Lcd_Write_Data(y2); // LSB Lcd_Write_Com(0x2e); // Write_memory_start Lcd_Write_Com(0x2c); // Write_memory_start }
//设置坐标范围 与tft驱动IC有关 void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2) { Lcd_Write_Com(0x0050);Lcd_Write_Data(x1);//0x0050~0x0053 windows control Lcd_Write_Com(0x0051);Lcd_Write_Data(x2); Lcd_Write_Com(0x0052);Lcd_Write_Data(y1); Lcd_Write_Com(0x0053);Lcd_Write_Data(y2); Lcd_Write_Com(0x0020);Lcd_Write_Data(x1); Lcd_Write_Com(0x0021);Lcd_Write_Data(y1); Lcd_Write_Com(0x0022); }
void tftDeviceCodeRead(uint8_t result[4]) { CS_LOW; Lcd_Write_Com(0xbf); Lcd_Read_Data(); // dummy read result[0] = Lcd_Read_Data(); // MIPI Alliance code result[1] = Lcd_Read_Data(); // MIPI Alliance code result[2] = Lcd_Read_Data(); // Device ID code result[3] = Lcd_Read_Data(); // Device ID code Lcd_Read_Data(); // Exit code (0xff) CS_HIGH; }
void Lcd_Init(void) { LCD_REST_1; delay_us(5); LCD_REST_0; delay_us(5); LCD_REST_1; LCD_CS_1; LCD_RD_1; LCD_WR_1; delay_us(5); LCD_CS_0; //打开片选使能 Lcd_Write_Com_Data(0x00,0x0000); Lcd_Write_Com_Data(0x00,0x0000); Lcd_Write_Com_Data(0x00,0x0000); Lcd_Write_Com_Data(0x00,0x0001); Lcd_Write_Com_Data(0xA4,0x0001); delay_us(10); Lcd_Write_Com_Data(0x60,0x2700); Lcd_Write_Com_Data(0x08,0x0808); Lcd_Write_Com_Data(0x30,0x0214); Lcd_Write_Com_Data(0x31,0x3715); Lcd_Write_Com_Data(0x32,0x0604); Lcd_Write_Com_Data(0x33,0x0E16); Lcd_Write_Com_Data(0x34,0x2211); Lcd_Write_Com_Data(0x35,0x1500); Lcd_Write_Com_Data(0x36,0x8507); Lcd_Write_Com_Data(0x37,0x1407); Lcd_Write_Com_Data(0x38,0x1403); Lcd_Write_Com_Data(0x39,0x0020); Lcd_Write_Com_Data(0x90,0x0015); Lcd_Write_Com_Data(0x10,0x0410); Lcd_Write_Com_Data(0x11,0x0237); Lcd_Write_Com_Data(0x29,0x0046); Lcd_Write_Com_Data(0x2A,0x0046); Lcd_Write_Com_Data(0x07,0x0000); Lcd_Write_Com_Data(0x12,0x0189); Lcd_Write_Com_Data(0x13,0x1100); delay_us(150); Lcd_Write_Com_Data(0x12,0x01B9); Lcd_Write_Com_Data(0x01,0x0100); Lcd_Write_Com_Data(0x02,0x0200); Lcd_Write_Com_Data(0x03,0x1030); Lcd_Write_Com_Data(0x09,0x0001); Lcd_Write_Com_Data(0x0A,0x0000); Lcd_Write_Com_Data(0x0D,0x0000); Lcd_Write_Com_Data(0x0E,0x0030); Lcd_Write_Com_Data(0x50,0x0000); Lcd_Write_Com_Data(0x51,0x00EF); Lcd_Write_Com_Data(0x52,0x0000); Lcd_Write_Com_Data(0x53,0x013F); Lcd_Write_Com_Data(0x61,0x0001); Lcd_Write_Com_Data(0x6A,0x0000); Lcd_Write_Com_Data(0x80,0x0000); Lcd_Write_Com_Data(0x81,0x0000); Lcd_Write_Com_Data(0x82,0x005F); Lcd_Write_Com_Data(0x92,0x0100); Lcd_Write_Com_Data(0x93,0x0701); delay_us(80); Lcd_Write_Com_Data(0x07,0x0100); Lcd_Write_Com_Data(0x20,0x0000); Lcd_Write_Com_Data(0x21,0x0000); Lcd_Write_Com(0x0022); LCD_CS_1; //关闭片选使能 }
void Lcd_Write_Com_Data(int com,int val) //发送数据命令 { Lcd_Write_Com(com); Lcd_Write_Data(val); }
void tftInit() { configurePorts(); RST_HIGH; _delay_ms(5); RST_LOW; _delay_ms(15); RST_HIGH; _delay_ms(15); CS_HIGH; WR_HIGH; CS_LOW; Lcd_Write_Com(0x11); // Exit_sleep_mode _delay_ms(20); Lcd_Write_Com(0xD0); // Power_Setting Lcd_Write_Data(0x07); // 0000 0111 - Vci1 = 1.0 * Vci Lcd_Write_Data(0x42); // 0100 0010 - PON (generate VLOUT3), VGL=3*Vci1 Lcd_Write_Data(0x18); // 0001 1000 - VREG1OUT=Vci*1.95 Lcd_Write_Com(0xD1); // VCOM_Control Lcd_Write_Data(0x00); // 0000 0000 - select D1h for VCM setting Lcd_Write_Data(0x07); // 0000 0111 - VCOMH=0.72*VREG1OUT Lcd_Write_Data(0x10); // 0001 0000 - VCOM_ampl=VREGOUT1*1.02 Lcd_Write_Com(0xD2); // Power_Setting_for_normal_mode Lcd_Write_Data(0x01); // 0000 0001 - Gamma driver ampl. = Source driver ampl. = 1.0 Lcd_Write_Data(0x02); // 0000 0010 - fDCDC2=Fosc/16 ; fDCDC1=Fosc/4 Lcd_Write_Com(0xC0); // Panel_driving_setting Lcd_Write_Data(0x10); // 0001 0000 - Grayscale inversion, gate driver pin arrangement Lcd_Write_Data(0x3B); // 0011 1011 - (value+1)*8 = number of lines to drive (59+1=60, 60*8=480) Lcd_Write_Data(0x00); // 0000 0000 - Scanning start position // Missing parameter????? The following // parameters are not consistent with the manual! Lcd_Write_Data(0x02); // 0000 0010 - ?????? Lcd_Write_Data(0x11); // 0001 0001 - source output level in non-display area; Lcd_Write_Com(0xC5); // Frame_rate_and_inversion_control Lcd_Write_Data(0x03); // 0000 0011 - Frame rate 72 Hz // This is the most important register, since it sets the // way how the frame memory is set when it is written, // and how the frame memory is mapped to the display panel Lcd_Write_Com(0x36); // Set_address_mode Lcd_Write_Data(0b00101000); // |||||||+-- Vertical flip // ||||||+--- Horizontal flip // |||||+---- 0 // ||||+----- Pixels sent in RGB order // |||+------ LCD refresh top to bottom // ||+------- Page/Column order // |+-------- Column address order left to right // +--------- Page address order top to bottom Lcd_Write_Com(0x3A); // Set_pixel_format Lcd_Write_Data(0x55); // x101 x101 - 16 bit per pixel (65536 colors) Lcd_Write_Com(0x2A); // Set_column_address Lcd_Write_Data(0x00); // 0000 0000 Lcd_Write_Data(0x00); // 0000 0000 - Start column = 0 Lcd_Write_Data(0x01); // 0000 0001 Lcd_Write_Data(0x3F); // 0011 1111 - End column = 0x13F = 319 Lcd_Write_Com(0x2B); // Set_page_address Lcd_Write_Data(0x00); // 0000 0000 Lcd_Write_Data(0x00); // 0000 0000 - Start page = 0 Lcd_Write_Data(0x01); // 0000 0001 Lcd_Write_Data(0xE0); // 1110 0000 - End page = 320 (???) (should be 1DF?) _delay_ms(120); Lcd_Write_Com(0x29); // Set_display_on Lcd_Write_Com(0x2c); // Write_memory_start }