TFT-LCD transplant record

1. TFT-LCD driving method and principle

Regarding the screen information, here is a better website for us to check the LCD wiki

In this test, I used two kinds of screens, the effect is normal

The first is this kind of capacitive screen
insert image description here
The second is this kind of resistive screen of punctual atoms
insert image description here
Interface pin diagram
insert image description here
Description of pin resources

  • CS: TFTLCD chip select signal.
  • WR: Write data to TFTLCD.
  • RD: read data from TFTLCD.
  • D[15: 0]: 16-bit bidirectional data line.
  • RST: Hard reset TFTLCD.
  • RS: command/data flag (0, read and write commands; 1, read and write data).

About driving: Here you can see that it has 16 data pins, but you can choose 8-bit or 16-bit for driving. Here, choose 16-bit, and pin resources are not very short. 16-bit theoretically comes It is said to be twice the speed of 8 bits. Generally, the selection of data bits is carried out by hardware, as shown in the following figure:

3.5-inch capacitive screen selection

insert image description here
Punctuality Atomic Elite Screen Selection
insert image description here

In addition, the RST signal line of the TFTLCD module is directly connected to the reset pin of the STM32F1, and is not controlled by software. The process of power-on will reset, which saves a pin.

The following is about the driver chip. It seems that there are many similar chips. The common ones are for example

ILI9341/ILI9325/RM68042/RM68021/ILI9320/ILI9328/LGDP4531/LGDP4535/SPFD5408/SSD1289/1505/B505/C505/NT35310/NT35510

I won't read the manual here. The website I provided above should all be found. This article only records the migration process.

The general process of operating the screen is as follows:

  • screen reset
  • set coordinates
  • write/read command
  • write/read color left
  • LCD display

Here, the driver of the screen is driven by FSMC.

STM32 large-capacity, STM32F103 chips with 100 pins and above all have FSMC interface, FSMC, the flexible static memory controller, can be connected with synchronous or asynchronous memory and 16-bit PC memory card, FSMC interface of STM32F1 Memories including SRAM, NAND FLASH, NOR FLASH and PSRAM are supported.

Here is the use of TFT-LCD as SRAM. Regarding the reasons, the explanation given by the punctual atomic tutorial is as follows:
insert image description here

2. Configure TFT-LCD driver

Pin Description

insert image description here
insert image description here

Configure it in CUBEMX below

Select FSMC
insert image description here
's description of the above parameters:

The easiest is to look at the tutorial manual of punctual atoms, which is very clear and understandable.
insert image description here
Here are some supplementary explanations (in fact, it is also a copy of the manual)

  • RS, RS signal decides whether to transmit data or command, connect RS to A0, then when the FSMC controller writes address 0, it will make A0 become 0. For TFTLCD, it is a write command. When FSMC writes address 1, A0 will become 1, which means writing data to TFTLCD. In this way, data and commands are distinguished, and they are actually two consecutive addresses corresponding to SRAM operations. Of course, RS can also be connected to other address lines. Here, the development board connects RS to A10.
  • Storage block, the FSMC of STM32F1 divides the external memory into four storage blocks with a fixed size of 256M bytes. Each storage block has four areas, which are NE1/2/3/4 in the options, as shown in the following figure:
    insert image description hereinsert image description here

After configuration, you can only see that the pins we need have been automatically generated.
insert image description here
Then according to the schematic diagram, you need to configure a pin for backlighting
insert image description here
, and then generate the code! ! !

3. Porting the driver function

After that, it is transplanted (simply copied)

Copy the content of the punctual atom in the full text. The
insert image description here
FSMC part of the cubemx has already been configured for us, and there is no need to comment out the
insert image description here
backlight pin. There is no such bit operation in the HAL library. After directly replacing it with the pin operation function
insert image description here
, it is the delay function. We use our own The milliseconds, the us delay function can be replaced, you can refer to my article stm32 configuration summary (1) Use Systick tick counter

Then there are some u8, u16 macros like this, which can be replaced globally

After that, you can add the replacement code to the main function, as shown below

insert image description here
The source code is as follows:

		switch(x)
		{
    
    
			case 0:LCD_Clear(WHITE);break;
			case 1:LCD_Clear(BLACK);break;
			case 2:LCD_Clear(BLUE);break;
			case 3:LCD_Clear(RED);break;
			case 4:LCD_Clear(MAGENTA);break;
			case 5:LCD_Clear(GREEN);break;
			case 6:LCD_Clear(CYAN);break;
			case 7:LCD_Clear(YELLOW);break;
			case 8:LCD_Clear(BRRED);break;
			case 9:LCD_Clear(GRAY);break;
			case 10:LCD_Clear(LGRAY);break;
			case 11:LCD_Clear(BROWN);break;
		}
		POINT_COLOR=RED;
		LCD_ShowString(30,40,200,16,16,"liuxing STM32F1 ^_^");
		LCD_ShowString(30,90,200,16,16,"TFTLCD TEST");
		LCD_ShowString(30,110,200,16,16,"ATOM@ALIENTEK");
		LCD_ShowString(30,130,200,16,16,lcd_id);		//显示LCD ID
		LCD_ShowString(30,150,200,12,12,"2015/1/14");
	    x++;
		if(x==12)x=0;
		HAL_Delay(1000);

Download the program to the development board, the effect is as follows: The effect of the
insert image description here
Atomic Elite development board on
insert image description here
time It can be seen that the transplant is still very successful

4. Transplant touch driver

It's the same as the above, copy the file, here I only made some drivers suitable for my screen, not all of them are transplanted.
insert image description here
Some screen reading chips use the IIC interface, in fact, it is very simple. Regarding the IIC transplant, You can see my article stm32 configuration summary - the use of iic

Then put the test function over and
insert image description here
download the program to the development board, the effect is as follows:

insert image description here

Guess you like

Origin blog.csdn.net/m0_51220742/article/details/123584828