Code d'initialisation de l'écran LCD TFT

The initialization code of the TFT LCD display is mainly used to set the working parameters and status of the display to ensure that the display can correctly display images and text. The role and principle of the initialization code mainly include the following aspects:

Hardware reset

At the beginning of initialization, a hardware reset operation is usually performed (by pulling the reset pin low and high), which ensures that the LCD starts operating from a known state.

Interface Configuration

The initialization code usually configures the communication interface (e.g. SPI, I2C or parallel interface) between the LCD and the microcontroller. Different LCD modules may support different communication interfaces, which need to be configured correctly during initialization so that subsequent data can be transferred smoothly.

Power Configuration

LCDs usually need to be configured with power parameters such as supply voltage, bias voltage and charge pump. These configurations directly affect the brightness, contrast and stability of the display.

Display Mode Settings

This includes setting the screen resolution, color depth, scanning direction (landscape or portrait), pixel format (RGB565, RGB666, etc.), and other parameters related to image displa

Register Configuration

During the initialization process, specific values need to be written to the various control registers of the LCD, which control the various functions of the display, such as contrast adjustment, gamma correction, brightness adjustment, color format setting, etc.

Clear screen operation

At the end of the initialization, a clear operation is usually performed, i.e., all pixels on the screen are set to black or white to ensure that the screen is clean and free of residual display content.

Turning on the display

After completing the above configuration, the last step is usually to turn on the display function so that the LCD can start receiving and displaying image data.

To summarize

The initialization code is the basis for the LCD display to be able to work properly. By executing the initialization code, various operating parameters of the LCD are set to ensure that the display operates in the correct mode and is able to display content stably and clearly. If the initialization step is incomplete or wrong, it may lead to display abnormalities, such as inability to display images, distortion of display contents, or incorrect colors.

ILI9341V code

//************* Start Initial Sequence **********// 
LCD_CTRL_ILI9341(0xCF);  
LCD_DATA_ILI9341(0x00); 
LCD_DATA_ILI9341(0xC1); 
LCD_DATA_ILI9341(0X30); 

LCD_CTRL_ILI9341(0xED);  
LCD_DATA_ILI9341(0x64); 
LCD_DATA_ILI9341(0x03); 
LCD_DATA_ILI9341(0X12); 
LCD_DATA_ILI9341(0X81); 

LCD_CTRL_ILI9341(0xE8);  
LCD_DATA_ILI9341(0x85); 
LCD_DATA_ILI9341(0x10); 
LCD_DATA_ILI9341(0x78); 

LCD_CTRL_ILI9341(0xCB);  
LCD_DATA_ILI9341(0x39); 
LCD_DATA_ILI9341(0x2C); 
LCD_DATA_ILI9341(0x00); 
LCD_DATA_ILI9341(0x34); 
LCD_DATA_ILI9341(0x02); 

LCD_CTRL_ILI9341(0xF7);  
LCD_DATA_ILI9341(0x20); 

LCD_CTRL_ILI9341(0xEA);  
LCD_DATA_ILI9341(0x00); 
LCD_DATA_ILI9341(0x00); 

LCD_CTRL_ILI9341(0xC0);    //Power control 
LCD_DATA_ILI9341(0x21);   //VRH[5:0] 

LCD_CTRL_ILI9341(0xC1);    //Power control 
LCD_DATA_ILI9341(0x12);   //SAP[2:0];BT[3:0] 

LCD_CTRL_ILI9341(0xC5);    //VCM control 
LCD_DATA_ILI9341(0x40); //32
LCD_DATA_ILI9341(0x3c); //3//3c

LCD_CTRL_ILI9341(0xC7);    //VCM control2 
LCD_DATA_ILI9341(0X94);  //0xb2//0x9c

LCD_CTRL_ILI9341(0x36);    // Memory Access Control 
LCD_DATA_ILI9341(0x08); 

LCD_CTRL_ILI9341(0x3A);   
LCD_DATA_ILI9341(0x55); 

LCD_CTRL_ILI9341(0xB1);   
LCD_DATA_ILI9341(0x00);   
LCD_DATA_ILI9341(0x17); 

LCD_CTRL_ILI9341(0xB6);    // Display Function Control 
LCD_DATA_ILI9341(0x0A); 
LCD_DATA_ILI9341(0xA2); 

LCD_CTRL_ILI9341(0xF6);    
LCD_DATA_ILI9341(0x01); 
LCD_DATA_ILI9341(0x30); 

LCD_CTRL_ILI9341(0xF2);    // 3Gamma Function Disable 
LCD_DATA_ILI9341(0x00); 

LCD_CTRL_ILI9341(0x26);    //Gamma curve selected 
LCD_DATA_ILI9341(0x01); 

LCD_CTRL_ILI9341(0xE0);    //Set Gamma 
LCD_DATA_ILI9341(0x0F); 
LCD_DATA_ILI9341(0x20); 
LCD_DATA_ILI9341(0x1E); 
LCD_DATA_ILI9341(0x07); 
LCD_DATA_ILI9341(0x0A); 
LCD_DATA_ILI9341(0x03); 
LCD_DATA_ILI9341(0x52); 
LCD_DATA_ILI9341(0X63); 
LCD_DATA_ILI9341(0x44); 
LCD_DATA_ILI9341(0x08); 
LCD_DATA_ILI9341(0x17); 
LCD_DATA_ILI9341(0x09); 
LCD_DATA_ILI9341(0x19); 
LCD_DATA_ILI9341(0x13); 
LCD_DATA_ILI9341(0x00); 

LCD_CTRL_ILI9341(0XE1);    //Set Gamma 
LCD_DATA_ILI9341(0x00); 
LCD_DATA_ILI9341(0x16); 
LCD_DATA_ILI9341(0x19); 
LCD_DATA_ILI9341(0x02); 
LCD_DATA_ILI9341(0x0F); 
LCD_DATA_ILI9341(0x03); 
LCD_DATA_ILI9341(0x2F); 
LCD_DATA_ILI9341(0x13); 
LCD_DATA_ILI9341(0x40); 
LCD_DATA_ILI9341(0x01); 
LCD_DATA_ILI9341(0x08); 
LCD_DATA_ILI9341(0x07); 
LCD_DATA_ILI9341(0x2E); 
LCD_DATA_ILI9341(0x3C); 
LCD_DATA_ILI9341(0x0F); 

LCD_CTRL_ILI9341(0x11);    //Exit Sleep 
LCD_Delayms(120); 
LCD_CTRL_ILI9341(0x29);    //Display on 

Retour en haut

LOGO-1.png