Driver of ST7735STFT screen

Introduction to ST7735S

Please add image description

Click image to buy

ST7735S is a single-chip controller/driver for 262K color graphic TFT-LCD. It consists of 396 source lines and 162 gate line driver circuits. The chip can be directly connected to an external microprocessor and accepts Serial Peripheral Interface (SPI), 8-bit/9-bit/16-bit/18-bit parallel interface. Display data can be stored in 132 x 162 x 18 bits of on-chip display data RAM. It can perform display data RAM reads and writes without an external operating clock to minimize power consumption. Additionally, display systems can be fabricated with fewer components due to the integrated power circuits required to drive the liquid crystals.

Introduction to TFT

The one below is a 1.44-inch TFT color screen. The driver IC uses the ST7735S chip. The SPI interface of the LCD driver IC has been drawn out of the outer side of the board so that it can be connected by Dupont lines. It is very friendly for those who do not want to solder. The MCU used in this driver is enhanced Type 51 single-chip microcomputer STC12 series MCU, as shown in the following figure:
insert image description here

Click image to buy

Pin Description

PIN Parameter
VCC 5V/3.3V power supply access
GND ground
CS LCD chip select signal, low level enable
RESET LCD reset signal, low level reset
A0 LCD screen register/data selection signal, high level: register, low level: data
SDA SPI bus write data signal
SCK SPI bus clock signal
LED Backlight control, high-level lighting, if no control is required, connect to 3.3V and keep on

program driven

The process framework is as follows

Created with Raphaël 2.3.0 初始化 编写显示函数 显示 结束 yes

main command control

insert image description here
In the above picture, we can see that if you want to soft restart the LCD screen, you can directly look at the line in my circle. D/CX is 0, which means you need to select the write command. Personally, it is recommended to transmit the data code when writing the SPI code. Select the high order first, so that the data in the HEX column can be used directly, that is, MCU_write_TFT_Byte (0x01) can be used directly to complete the soft restart.
insert image description here
The three commands 2A, 2B.2C in the above figure are respectively the configuration address selection area and the color filling command. After selecting the address and writing the corresponding data function, the screen address fetching and color filling process can be completed.

Part of the code framework

The initialization code is taken from the driver configured by the official screen documentation.

*配置好屏幕退出睡眠模式,配置帧速率等操作,如果有需求进行屏幕镜像的可以去参考文档中的36命令那里着重看下*
void TFT_init()
{
    
    
	TFT_BL=0;//背光关闭
	
	TFT_RESET=0;
    TFT_delay500ms();
    TFT_RESET=1;
    TFT_delay500ms();
	
	MCU_write_TFT_Byte(0x11,TFT_COMMAND);//睡眠退出
	TFT_delay500ms();
	
	//ST7735R 帧速率
	MCU_write_TFT_Byte(0xB1,TFT_COMMAND); 
	MCU_write_TFT_Byte(0x01,TFT_DATA); 
	MCU_write_TFT_Byte(0x2C,TFT_DATA); 
	MCU_write_TFT_Byte(0x2D,TFT_DATA); 

	MCU_write_TFT_Byte(0xB2,TFT_COMMAND); 
	MCU_write_TFT_Byte(0x01,TFT_DATA); 
	MCU_write_TFT_Byte(0x2C,TFT_DATA); 
	MCU_write_TFT_Byte(0x2D,TFT_DATA); 

	MCU_write_TFT_Byte(0xB3,TFT_COMMAND); 
	MCU_write_TFT_Byte(0x01,TFT_DATA); 
	MCU_write_TFT_Byte(0x2C,TFT_DATA); 
	MCU_write_TFT_Byte(0x2D,TFT_DATA); 
	MCU_write_TFT_Byte(0x01,TFT_DATA); 
	MCU_write_TFT_Byte(0x2C,TFT_DATA); 
	MCU_write_TFT_Byte(0x2D,TFT_DATA); 
	
	MCU_write_TFT_Byte(0xB4,TFT_COMMAND);//列反转
	MCU_write_TFT_Byte(0x07,TFT_DATA); 
	
	//ST7735R Power Sequence
	MCU_write_TFT_Byte(0xC0,TFT_COMMAND); 
	MCU_write_TFT_Byte(0xA2,TFT_DATA); 
	MCU_write_TFT_Byte(0x02,TFT_DATA); 
	MCU_write_TFT_Byte(0x84,TFT_DATA); 
	MCU_write_TFT_Byte(0xC1,TFT_COMMAND); 
	MCU_write_TFT_Byte(0xC5,TFT_DATA); 

	MCU_write_TFT_Byte(0xC2,TFT_COMMAND); 
	MCU_write_TFT_Byte(0x0A,TFT_DATA); 
	MCU_write_TFT_Byte(0x00,TFT_DATA); 

	MCU_write_TFT_Byte(0xC3,TFT_COMMAND); 
	MCU_write_TFT_Byte(0x8A,TFT_DATA); 
	MCU_write_TFT_Byte(0x2A,TFT_DATA); 
	MCU_write_TFT_Byte(0xC4,TFT_COMMAND); 
	MCU_write_TFT_Byte(0x8A,TFT_DATA); 
	MCU_write_TFT_Byte(0xEE,TFT_DATA); 
	
	MCU_write_TFT_Byte(0xC5,TFT_COMMAND);//VCOM 
	MCU_write_TFT_Byte(0x0E,TFT_DATA); 
	
	MCU_write_TFT_Byte(0x36,TFT_COMMAND);//MX,MY,RGB mode 
	
	switch (DISPLAY_DIRECTION)//显示的方向(竖屏:0,横屏:1,竖屏旋转180度:2,横屏旋转180度:3)
	{
    
    
		case	0: MCU_write_TFT_Byte(0xC8,TFT_DATA);break;//竖屏
		case	1: MCU_write_TFT_Byte(0xA8,TFT_DATA);break;//横屏
		case    2: MCU_write_TFT_Byte(0x08,TFT_DATA);break;//竖屏翻转180度
		default	 : MCU_write_TFT_Byte(0x68,TFT_DATA);break;//横屏翻转180度
	}

	//ST7735R Gamma Sequence
	MCU_write_TFT_Byte(0xE0,TFT_COMMAND); 
	MCU_write_TFT_Byte(0x0F,TFT_DATA); 
	MCU_write_TFT_Byte(0x1A,TFT_DATA); 
	MCU_write_TFT_Byte(0x0F,TFT_DATA); 
	MCU_write_TFT_Byte(0x18,TFT_DATA); 
	MCU_write_TFT_Byte(0x2F,TFT_DATA); 
	MCU_write_TFT_Byte(0x28,TFT_DATA); 
	MCU_write_TFT_Byte(0x20,TFT_DATA); 
	MCU_write_TFT_Byte(0x22,TFT_DATA); 
	MCU_write_TFT_Byte(0x1F,TFT_DATA); 
	MCU_write_TFT_Byte(0x1B,TFT_DATA); 
	MCU_write_TFT_Byte(0x23,TFT_DATA); 
	MCU_write_TFT_Byte(0x37,TFT_DATA); 
	MCU_write_TFT_Byte(0x00,TFT_DATA); 	
	MCU_write_TFT_Byte(0x07,TFT_DATA); 
	MCU_write_TFT_Byte(0x02,TFT_DATA); 
	MCU_write_TFT_Byte(0x10,TFT_DATA); 

	MCU_write_TFT_Byte(0xE1,TFT_COMMAND); 
	MCU_write_TFT_Byte(0x0F,TFT_DATA); 
	MCU_write_TFT_Byte(0x1B,TFT_DATA); 
	MCU_write_TFT_Byte(0x0F,TFT_DATA); 
	MCU_write_TFT_Byte(0x17,TFT_DATA); 
	MCU_write_TFT_Byte(0x33,TFT_DATA); 
	MCU_write_TFT_Byte(0x2C,TFT_DATA); 
	MCU_write_TFT_Byte(0x29,TFT_DATA); 
	MCU_write_TFT_Byte(0x2E,TFT_DATA); 
	MCU_write_TFT_Byte(0x30,TFT_DATA); 
	MCU_write_TFT_Byte(0x30,TFT_DATA); 
	MCU_write_TFT_Byte(0x39,TFT_DATA); 
	MCU_write_TFT_Byte(0x3F,TFT_DATA); 
	MCU_write_TFT_Byte(0x00,TFT_DATA); 
	MCU_write_TFT_Byte(0x07,TFT_DATA); 
	MCU_write_TFT_Byte(0x03,TFT_DATA); 
	MCU_write_TFT_Byte(0x10,TFT_DATA);  
	
	MCU_write_TFT_Byte(0xF0,TFT_COMMAND);//启动测试命令
	MCU_write_TFT_Byte(0x01,TFT_DATA); 
	MCU_write_TFT_Byte(0xF6,TFT_COMMAND);//禁用ram省电模式
	MCU_write_TFT_Byte(0x00,TFT_DATA); 
	
	MCU_write_TFT_Byte(0x3A,TFT_COMMAND);//65k mode 
	MCU_write_TFT_Byte(0x05,TFT_DATA); 
	MCU_write_TFT_Byte(0x29,TFT_COMMAND);//开启显示
	
	//设置显示区域(行起始,行终止,列起始,列终止)
	TFT_set_region(0,127,0,127);
	
	TFT_clear(BLACK);//清屏(屏幕为黑色)
	TFT_BL=1;//背光开启
}

drive show

insert image description here

Summarize

The key initialization framework is given, which is convenient for direct configuration and use. Some functional functions can be obtained from the message mailbox below, sent online, and published similar articles for a long time. Welcome to pay attention, and welcome to leave a message at any time.

Guess you like

Origin blog.csdn.net/qq_42250136/article/details/119909394