
本文来源:https://kwkr.cn/news/395781
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。
简介1.44寸LCD串口模块ST7735的软硬件全套资料覆盖C51、STM32、Arduino三大嵌入式平台适合正在调试同型号屏幕或准备做小尺寸显示项目的开发者。压缩包为RAR格式约18.05MB内含模块原理图与尺寸图、Altium封装库、芯片PDF以及多平台SPI驱动源码和图片/文字取模软件硬件设计、代码移植、界面制作所需内容基本齐全。目前已有219人学习/下载属于同类资源中较为实用的参考包。尤其值得关注的是其中STM32硬件SPI中英文显示测试源码可以直接借鉴接线说明和测试代码能帮读者快速跑通基础显示功能对于从零开始接触ST7735驱动的朋友也能借助这些资料少走弯路较快完成项目验证。1. 1.44寸ST7735串口屏从原理图到三平台驱动的完整落地方案1.44寸、128x160、ST7735驱动的TFT-LCD串口屏几乎是嵌入式开发板资料里出现频率最高的一块小屏。它的控制引脚极简SPI就
够、自带GRAM、颜色还原尚可所以从C51到STM32到Arduino谁的开发套件都要配一块。但在实际项目中很多人是拿到厂家资料包就开始烧例程真正遇到换主控、改引脚、调亮度、加中文时才开始对着原理图和驱动源码逐行抠。这篇博文把这块屏作为一组硬件加固件的组合来回看原理图哪些器件不能省SPI速率和指令时序怎么配C51/STM32/Arduino三套主流驱动各自的最小可行代码长什么样以及卡屏、花屏、闪屏时从哪里下手。2. ST7735的硬件底子接口协议、原理图关键位与封装库选型2.1 为什么是ST7735同尺寸LCD控制器的选型对比ST7735是一颗单芯片TFT LCD控制器最大支持132x162像素内部带有GRAM和电源电路只需要一颗3.3V电源、四线SPI和几个控制引脚就能驱动。它和常见的SSD1306、ILI9341、ILI9488定位不同SSD1306是OLED单色/双色屏分辨率通常是1
28x64胜在自发光和超低功耗但颜色信息完全没有ILI9341是2.4寸以上真彩屏的常客分辨率240x320适合做仪表或简单的GUIILI9488则是480x320真彩屏色彩深度高但需要更多的GRAM和更快的总线。ST7735卡在两者之间128x160、16位色刚好能显示一块带点信息的彩色画面但数据量又不会大到让8位单片机太吃力。从选型逻辑上看ST7735适合的是「以彩色显示为目标但不追求复杂UI」的项目。如果你的面板只显示几行传感器数据、一个简单曲线或者状态图标用ST7735是最省事的一旦要跑滑屏动画、多级菜单甚至显示图片就要评估帧率能不能接受。一个很容易被忽略的参数是接口速度ST7735支持SPI mode 0和mode 3最大串行时钟因厂家批次而异常见模块标注为15MHz~20MHz实际跑8MHz以上就能有不错的效果。选择模块时优先看厂家是否标出RAM型号和玻璃批次同一颗芯片在不同玻
璃上会有色差和响应速度差异。2.1.1 接口协议SPI还是并口标题里说「串口模块」但串口这个词在ST7735语境下容易产生歧义。这里指的并不是UART串口而是SPI串行接口——模块上的数据线是SCLK、MOSI模块上常标为SDA、CS、DC模块上常标A0或RS、RST、BLK。完整的驱动只需要5根信号线加电源地算上背光控制也不超过8根线。有些1.44寸模块的「40pin LCD接口」是玻璃端子的FPC引出主板上通过一个转接小板把FPC转换成8pin或10pin排针收到货先确认排针定义因为不同批次模块的引脚顺序并不完全一致。从性能上讲ST7735内部数据总线是并行的但外部接口支持串行使用SPI时每次写GRAM都要经过移位寄存器所以同一颗屏在并口下的刷新速度会比SPI下快很多。模块厂之所以普遍做成SPI是因为布线简单、引脚少适合DIY和原型验证。如果你的产品最终方案确定用STM32也可以反过来
看模块是否支持并口模式——ST7735有IM0~IM3引脚决定接口模式但1.44寸模块通常已经把模式固定为SPI想改并口需要飞线甚至放弃模块成品。2.2 模块原理图里的三个关键区域电源、背光、SPI信号拿到原理图先看电源部分。ST7735的电源分为模拟电源VCI、逻辑电源IOVCC和LCD驱动电源由内部charge pump产生。在1.44寸模块上厂家通常已经把VCI和IOVCC合并成一颗3.3V LDO供电你只需要从主控板上引3.3V过来。但有一个坑很多模块上的VCC引脚对电压纹波很敏感特别是背光突然点亮时如果电容容量不足就会出现水波纹或红绿横纹。原理图里VCC附近那两个10uF100nF电容不能省都贴上去再实测。背光控制是第二个关键位。模块上BLK引脚接入背光LED回路常见设计是通过一个三极管或MOS管开关控制串联电阻决定背光电流。直接接3.3V时背光最亮但电流可能达到20~40mA如
果主控板的LDO余量不够会影响ST7735的模拟电压。更常见的做法是把BLK接到主控的一个PWM脚用一个10k电阻做下拉通过调节PWM占空比控制亮度。注意有些模块的BLK引脚内部已经带了限流电阻TFT_eSPI库用户可以在初始化后直接调digitalWrite看屏的亮度变化来确定模块属于哪种背光电路。SPI信号线上需要关注的不是上拉而是电平匹配和信号完整性。C51/STM32的GPIO都是3.3V逻辑Arduino Uno的5V输出建议串一个几百欧的电阻分压或者直接接电平转换后再进模块。SPI走线超过10cm时时钟和数据线之间的相位偏移会让画面出现整屏错位或第一行显示异常解决办法是把SPI时钟降到4MHz以下或者把CS和DC也纳入等长布线考虑。2.3 封装库与PCB布局从模块到自己的板子如果你不是直接把模块飞线到开发板上而是想在自有PCB上贴装1.44寸屏封装库的选取就变得重要。模块常见两
种封装一种是大板排针焊盘间距2.54mm适合原型另一种是邮票孔或Wi-Fi模块式焊盘适合SMT量产。很多模块厂家在资料包中附带Altium/AD的封装库但导出后经常会遇到原点不一致、丝印超出板框的问题。我一般会新建一个原理图器件把引脚名按模块实际排针顺序命名再配一个独立的PCB封装这样画板时不易被厂家库的怪异原点带偏。布局方面的经验值这个屏的FPC排线区域不要走其他大电流线ST7735的电源去耦电容应尽量靠近模块电源引脚如果板上同时有Wi-Fi模块或电机驱动LCD的GND要单独一条线回到电源地避免电机启停的电流噪声窜进SPI信号回路。屏幕背面的金属框如果接地良好还能起到屏蔽作用减少触摸或无线信号的干扰。3. C51驱动ST7735的软件SPI实现最小寄存器级代码C51单片机的处理能力和存储空间都有限尤其经典STC89C52只有8KB程序Flash跑不了Arduino那种重量级图形库。所以C
51驱动的正确姿势是自己写寄存器级SPI只实现画点、画矩形和显示ASCII字符。这一章给出可以完整编译的一套最小驱动芯片以STC89C52RC为例晶振12MHz。3.1 引脚分配与软件SPI的实现思路STC89C52本身不带硬件SPISTC12和STC15系列才有所以用普通GPIO模拟。建议把SCLK、MOSI、CS、DC、RST分到同一组端口方便赋值和宏替换。下面这张引脚表是常用接法你也可以按自己的板子调整只要在驱动头文件里对应修改即可。引脚功能51单片机引脚说明SCLKP1.0SPI时钟空闲低电平MOSI(SDA)P1.1主出从进数据在上升沿有效CSP1.2片选低电平时选中ST7735DC(A0)P1.3低电平写命令高电平写数据RSTP1.4复位低电平有效BLKP1.5背光控制直接输出高电平点亮软件SPI的核心是字节发送函数。ST7735支持SPI mode 0和mode 3C51软件
模拟时建议固定在mode 0空闲时SCLK为低数据在SCLK上升沿被采样。// spi_delay() 由空循环实现视晶振频率微调 void SPI_WriteByte(unsigned char dat) { unsigned char i; for (i 0; i 8; i) { if (dat 0x80) MOSI 1; // 先送最高位 else MOSI 0; SCLK 0; // 空闲电平为低 dat 1; // 移位准备下一位 SCLK 1; // 上升沿锁存数据 } }这段代码的要点是每次把数据最高位移出在SCLK上升沿时让ST7735采样。注意循环里先写MOSI再拉高SCLK是为了满足建立时间要求如果你的单片机速度太快SPI_WriteByte里没延时也会工作但信号线长或模块负载重时容易出现偶发错位这时在SCLK1后面加两个空操作即可。3.2 初始化序列S
T7735的寄存器配置与其中含义ST7735上电后必须发送一串初始化命令否则屏不会正常显示。不同厂家封装的ST7735S序列大同小异下面是一段经过多块屏验证的常用初始化代码包含软件复位、退出睡眠、颜色格式和显存窗口设置。void LCD_Init(void) { RST 0; DelayMs(50); // 复位保持时间至少10us实际放宽 RST 1; DelayMs(120); // 退出复位需要等待内部PLL稳定 WriteCmd(0x01); // SWRESET 软件复位 DelayMs(150); WriteCmd(0x11); // SLPOUT 退出睡眠模式 DelayMs(120); WriteCmd(0x36); // MADCTL 设置扫描方向 WriteData(0xA0); // RGB顺序正常扫描根据面板丝印调整 WriteCmd(0x3A); // COL
MOD 颜色格式 WriteData(0x05); // 16位/pixel5-6-5格式 WriteCmd(0x20); // INVOFF 关闭反色显示 WriteCmd(0x2A); // CASET 设置列地址窗口 WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x7F); WriteCmd(0x2B); // RASET 设置行地址窗口 WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x9F); WriteCmd(0x29); // DISPON 打开显示 DelayMs(20); }这里WriteCmd和WriteData的区别在于DC引脚的电平状态写命令时DC0写数据时DC1。0x36的MADCTL参数A0表示RGB色彩顺序加
上从左到右、从上到下的扫描方向但不同批次的1.44寸屏可能在玻璃装配时旋转了180度画面上下颠倒时把这个值改为0xA0或0x70做对比即可。0x3A设成0x05是16位色这是代码里最统一的一个寄存器设置不要改成0x06否则后续颜色数据的字节序全部会错。3.3 画点、矩形与字符显示在8KB Flash里塞进可用UI初始化完成后最基础的原语是画点函数。ST7735的GRAM寻址方式是先设列地址窗口CASET再设行地址窗口RASET最后连续写入像素数据。每发送一个像素就是两个字节低字节在前高字节在后具体取决于MADCTL的RGB/BGR设置。void LCD_DrawPoint(unsigned int x, unsigned int y, unsigned int color) { WriteCmd(0x2A); // 列地址 WriteData(x 8); WriteData(x 0xF
F); WriteData(x 8); WriteData(x 0xFF); WriteCmd(0x2B); // 行地址 WriteData(y 8); WriteData(y 0xFF); WriteData(y 8); WriteData(y 0xFF); WriteCmd(0x2C); // RAMWR 写显存 WriteData(color 8); WriteData(color 0xFF); }如果在循环里逐个像素调用LCD_DrawPoint刷一整屏耗时非常长128x160个像素每个像素要发两次SPI字节12MHz晶振下软件SPI刷一帧在秒级。所以实际项目都会在字符和图片显示时采用整块填充的方式先用CASET和RASET框住一个区域然后连续发送该区域全部像素最后再拉高DC并写命令结束。常见做法是做一个LCD_FillRect函数调用点画区域设置后用for循环直
接把颜色数据发完中间不切换DC这样ST7735会自动把GRAM地址1直到填满窗口。ASCII字符显示基于一张8x16或8x8的点阵表在C51上更常用的是8x8小字库。把所有ASCII字符的8字节模板放在code区显示时按字符编码索引到起始偏移逐列取出数据每个bit作为像素的上色开关。中文字体在C51上比较吃力一则字模数据大二则GB2312编码处理复杂如果一定要显示中文建议只放需要的那十几个字的16x16字模用编码查表而不是整个字库全塞进去。4. STM32硬件SPI与Arduino库移植性能提升和快速出效果C51这种8位平台只能解决「点亮」问题到了STM32或Arduino平台上驱动方式就从寄存器模拟转向硬件SPI和现成库。STM32的硬件SPI可以跑16MHz或更高DMA又能把CPU从枯燥的像素搬运中解放出来Arduino则用Adafruit_ST7735或TFT_eSPI把底层细节封装
掉几分钟就能看到画面。这一章把两条路都走一遍。4.1 STM32硬件SPI配置SPI_CR1和DMA搬运显存数据在STM32上驱动ST7735首选硬件SPI。以STM32F103C8T6为例SPI1的SCLK和MOSI复用映射到PA5/PA7CS、DC、RST用普通GPIO控制。初始化代码的特点是SPI模式选Master、时钟空闲低电平、第一个跳变沿采样对应CPOL0、CPHA08位数据长度MSB先发。void SPI1_Init(void) { GPIO_InitTypeDef gpio; SPI_InitTypeDef spi; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE); gpio.GPIO_Pin GPIO_Pin_5 | GPIO_Pin_7; // SCK与MOSIMIS

本文来源:https://kwkr.cn/news/395781
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。
Overview: The complete set of software and hardware documentation for the 1.44-inch LCD serial module ST7735 covers the three major embedded platforms: C51, STM32, and Arduino. It is suitable for developers who are debugging screens of the same model or preparing to work on small-size display projects. The compressed package is in RAR format and is approximately 18.05 MB in size. It contains the module's schematic and dimensional drawings, the Altium package library, the chip PDF, and the source code for multi-platform SPI drivers, as well as the image/text font generator software. The content required for hardware design, code porting, and interface creation is essentially complete. Currently, 219 people have studied/downloaded this reference package, which is one of the more practical resources of its kind. Of particular note is that the STM32 hardware SPI English and Chinese display test source code can be directly referenced. The wiring instructions and test code can help readers quickly implement basic display functions. For those who are new to the ST7735 driver, these resources can also help them avoid detours and complete project validation more quickly. 1. A complete implementation plan for the 1.44-inch ST7735 serial interface display, from the schematic diagram to the drivers for three platforms. The 1.44-inch, 128x160, ST7735-driven TFT-LCD serial interface display is arguably the most frequently mentioned small display in embedded development board documentation. Its control pins are minimal, and SPI is...
It's sufficient, comes with its own GRAM, and has decent color reproduction, so it should be included in every development kit, from C51 to STM32 to Arduino. However, in actual projects, many people start burning sample programs as soon as they receive the manufacturer's information package. Only when they actually encounter the need to change the main controller, modify pins, adjust brightness, or add Chinese characters do they start to go through the schematic diagram and driver source code line by line. This blog post looks at this display as a combination of hardware and firmware. It examines the schematic to see which components cannot be omitted, how to configure the SPI speed and command timing, what the minimum viable code for each of the three mainstream drivers (C51/STM32/Arduino) looks like, and where to start when the screen freezes, displays incorrectly, or flickers. 2. ST7735's hardware foundation: interface protocol, key points on the schematic, and package library selection 2.1 Why ST7735? Comparison of LCD controllers of the same size The ST7735 is a single-chip TFT LCD controller that supports up to 132x162 pixels. It has an internal GRAM and power supply circuit, and only requires a 3.3V power supply, a four-wire SPI, and a few control pins to drive it. It is positioned differently from the common SSD1306, ILI9341, and ILI9488. The SSD1306 is an OLED monochrome/dual-color display, and its resolution is typically 1
The 28x64 excels in self-illumination and ultra-low power consumption, but it lacks color information entirely. The ILI9341 is commonly used in true-color screens of 2.4 inches or larger, with a resolution of 240x320, making it suitable for instruments or simple GUIs. The ILI9488, on the other hand, is a 480x320 true-color screen with high color depth, but it requires more GRAM and a faster bus. The ST7735 falls somewhere in between. Its 128x160 resolution and 16-bit color are just enough to display a color image with some information, but the amount of data isn't so large as to overwhelm an 8-bit microcontroller. From the perspective of selection logic, the ST7735 is suitable for projects that "aim for color display but do not pursue a complex UI." If your panel only displays a few lines of sensor data, a simple curve, or status icons, using the ST7735 is the most hassle-free option. However, once you need to run swipe animations, multi-level menus, or even display images, you'll need to evaluate whether the frame rate is acceptable. One parameter that is often overlooked is the interface speed. The ST7735 supports SPI mode 0 and mode 3. The maximum serial clock varies depending on the manufacturer's batch. The module is typically labeled as 15MHz–20MHz, but it can perform well at 8MHz or higher. When selecting a module, first check whether the manufacturer has indicated the RAM model and glass batch. The same chip may perform differently with different glass batches.
There will be differences in color and response speed on the glass. 2.1.1 The interface protocol is SPI or parallel port. The title mentions "serial port module," but the term "serial port" can easily cause confusion in the context of the ST7735. What is referred to here is not the UART serial port but the SPI serial interface – the data lines on the module are SCLK, MOSI, which are often labeled as SDA on the module, CS, DC, which are often labeled as A0 or RS on the module, RST, and BLK. The complete driver only requires 5 signal lines plus a power ground. Even with backlight control, it does not exceed 8 lines. The "40-pin LCD interface" on some 1.44-inch modules is an FPC with glass terminals that leads to the main board. Through a small adapter board, the FPC is converted to an 8-pin or 10-pin header. Upon receiving the product, first confirm the pinout definition because the pin order may not be completely consistent across different batches of modules. From a performance standpoint, the internal data bus of the ST7735 is parallel, but the external interface supports serial communication. When using SPI, each time GRAM is written, it must pass through a shift register. Therefore, the refresh rate of the same display will be much faster when using a parallel interface compared to SPI. The reason why module manufacturers generally use SPI is because the wiring is simple and the number of pins is low, making it suitable for DIY and prototype verification. If your product's final design is confirmed to use STM32, the opposite can also be done.
Check whether the module supports parallel port mode – The ST7735 has IM0~IM3 pins to determine the interface mode, but the 1.44-inch module usually already has the mode fixed to SPI. To change to parallel port mode, you would need to use jumper wires or even abandon the finished module. 2.2 The three key areas in the module schematic diagram are the power supply, backlight, and SPI signal. Once you have the schematic diagram, first look at the power supply section. The power supply of the ST7735 is divided into the analog power supply VCI, the logic power supply IOVCC, and the LCD driver power supply, which is generated by an internal charge pump. On the 1.44-inch module, the manufacturer has usually combined VCI and IOVCC into a single 3.3V LDO power supply. You only need to draw 3.3V from the main control board. However, there is a pitfall: the VCC pin on many modules is very sensitive to voltage ripple, especially when the backlight suddenly turns on. If the capacitance is insufficient, water ripples or red and green horizontal stripes will appear. The two 10 uF and 100 nF capacitors near VCC in the schematic diagram cannot be omitted. They must be soldered on before testing. Backlight control is the second key element. A common design for connecting the BLK pin on the module to the backlight LED circuit is to use a transistor or MOS transistor switch to control the series resistor to determine the backlight current. The backlight is brightest when directly connected to 3.3V, but the current may reach 20–40 mA, such as
If the LDO margin of the main control board is insufficient, it will affect the analog voltage of the ST7735. A more common practice is to connect BLK to a PWM pin of the main controller and use a 10k resistor for pull-down to control the brightness by adjusting the PWM duty cycle. Note that some modules already have a current-limiting resistor inside the BLK pin. Users of the TFT_eSPI library can directly adjust digitalWrite after initialization to observe the change in screen brightness and determine which type of backlight circuit the module belongs to. What needs attention on the SPI signal line is not the pull-up, but the level matching and signal integrity. The GPIOs of C51/STM32 are all 3.3V logic. For the 5V output of the Arduino Uno, it is recommended to connect a resistor of several hundred ohms in series for voltage division, or to connect it directly to a level shifter before entering the module. When the SPI trace length exceeds 10 cm, the phase shift between the clock and data lines can cause the entire screen to be misaligned or the first row to display abnormally. The solution is to reduce the SPI clock to below 4 MHz or to also consider CS and DC in the equal-length routing. 2.3 Package Library and PCB Layout: From the Module to Your Own Board. If you are not directly jumpering the module to the development board, but instead want to mount the 1.44-inch display on your own PCB, the selection of the package library becomes important. The module commonly has two
There are two types of packages: one is a large board with a header pin pad pitch of 2.54 mm, which is suitable for prototyping; the other is a stamp hole or Wi-Fi module-type pad, which is suitable for SMT mass production. Many module manufacturers include Altium/AD package libraries in their documentation packages, but after exporting them, there are often issues with inconsistent origins and silkscreen extending beyond the board outline. I usually create a new schematic component, name the pins according to the actual pinout order of the module, and then pair it with a separate PCB package. This way, when drawing the board, it is less likely to be affected by the unusual origin point of the manufacturer's library. Based on experience with layout, do not route other high-current lines through the FPC cable area of this display. The power decoupling capacitor for the ST7735 should be placed as close as possible to the module's power supply pins. If the board also has a Wi-Fi module or a motor driver, the GND of the LCD should be routed back to the power supply ground via a separate line to prevent current noise from the motor's start-stop operations from interfering with the SPI signal loop. If the metal frame on the back of the screen is well grounded, it can also act as a shield to reduce interference from touch or wireless signals. 3. The software SPI implementation of the C51 driving the ST7735 uses minimal register-level code. The processing power and memory space of the C51 microcontroller are limited, especially the classic STC89C52, which only has 8KB of program Flash and cannot run heavy-duty graphics libraries like those used in Arduino. Therefore, C
The correct approach for the 51 driver is to write the register-level SPI yourself, implementing only the functions of drawing points, drawing rectangles, and displaying ASCII characters. This chapter presents a set of minimal driver chips that can be fully compiled, using the STC89C52RC as an example, with a 12 MHz crystal oscillator. 3.1 Pin Assignment and Implementation Approach for Software SPI. The STC89C52 itself does not come with hardware SPI; only the STC12 and STC15 series have it, so ordinary GPIOs are used for simulation. It is recommended to assign SCLK, MOSI, CS, DC, and RST to the same group of ports for convenient assignment and macro substitution. The following pin table shows the common connection methods. You can also adjust it according to your own board, as long as you make the corresponding modifications in the driver header file. Pin Functions 51 MCU Pin Descriptions SCLK P1.0 SPI clock, idle low level MOSI (SDA) P1.1 Master-out, slave-in data, active on the rising edge CS P1.2 Chip select, ST7735 selected when low level DC (A0) P1.3 Low level for writing commands, high level for writing data RST P1.4 Reset, active low BLK P1.5 Backlight control, directly outputs high level to turn on The core of the software SPI is the byte transmission function. The ST7735 supports SPI mode 0 and mode 3C51 software.
When simulating, it is recommended to fix SCLK to low when idle in mode 0. Data is sampled on the rising edge of SCLK. // spi_delay() is implemented by an empty loop, with fine-tuning based on the crystal oscillator frequency. void SPI_WriteByte(unsigned char dat) { unsigned char i; for (i = 0; i < 8; i++) { if (dat & 0x80) MOSI = 1; // Send the most significant bit first else MOSI = 0; SCLK = 0; // Idle level is low dat = dat << 1; // Shift to prepare for the next bit SCLK = 1; // Latch data on the rising edge } } The key point of this code is to shift out the most significant bit of the data each time and allow the ST7735 to sample on the rising edge of SCLK. Note that in the loop, MOSI is written first and then SCLK is pulled high to meet the setup time requirement. If your microcontroller is too fast, SPI_WriteByte will work even without a delay, but occasional misalignment is likely to occur when the signal line is long or the module load is heavy. In this case, simply add two empty operations after SCLK1. 3.2 Initialization Sequence S
The register configuration of the ST7735 and its meanings. After the ST7735 is powered on, a series of initialization commands must be sent, otherwise the display will not function properly. The ST7735S series packaged by different manufacturers are largely similar. Below is a common initialization code that has been verified on multiple displays, including software reset, exit sleep mode, color format, and display memory window settings. void LCD_Init(void) { RST 0; DelayMs(50); // Reset hold time of at least 10us, actually extended RST 1; DelayMs(120); // Exiting reset requires waiting for the internal PLL to stabilize WriteCmd(0x01); // SWRESET Software reset DelayMs(150); WriteCmd(0x11); // SLPOUT Exit sleep mode DelayMs(120); WriteCmd(0x36); // MADCTL Set scan direction WriteData(0xA0); // RGB sequence normal scan, adjusted based on panel silkscreen WriteCmd(0x3A); // COL
MOD Color Format WriteData(0x05); // 16-bit/pixel 5-6-5 format WriteCmd(0x20); // INVOFF Disable inverted display WriteCmd(0x2A); // CASET Set column address window WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x7F); WriteCmd(0x2B); // RASET Set row address window WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x9F); WriteCmd(0x29); // DISPON Turn on display DelayMs(20); } Here, the difference between WriteCmd and WriteData lies in the logic level state of the DC pin: DC0 when writing commands, and DC1 when writing data. The MADCTL parameter A0 of 0x36 indicates RGB color order plus
The scanning direction is from left to right and from top to bottom. However, 1.44-inch screens from different batches may have been rotated 180 degrees during glass assembly, causing the image to be upside down. In such cases, change this value to 0xA0 or 0x70 for comparison. Setting 0x3A to 0x05 represents 16-bit color, which is the most consistent register setting in the code. Do not change it to 0x06, otherwise, the byte order of subsequent color data will be completely incorrect. 3.3 Drawing points, rectangles, and characters. After squeezing the usable UI into the 8KB Flash and completing initialization, the most basic primitive is the function for drawing points. The GRAM addressing method of the ST7735 is to first set the column address window CASET, then set the row address window RASET, and finally write the pixel data continuously. Each pixel sent consists of two bytes, with the low byte first and the high byte last, depending on the RGB/BGR setting of MADCTL. void LCD_DrawPoint(unsigned int x, unsigned int y, unsigned int color) { WriteCmd(0x2A); // Column address WriteData(x 8); WriteData(x 0xF
F); WriteData(x 8); WriteData(x 0xFF); WriteCmd(0x2B); // Row address WriteData(y 8); WriteData(y 0xFF); WriteData(y 8); WriteData(y 0xFF); WriteCmd(0x2C); // RAMWR Write to video memory WriteData(color 8); WriteData(color 0xFF); } If LCD_DrawPoint is called pixel by pixel in a loop to refresh an entire screen, it takes a very long time. For 128x160 pixels, each pixel needs to send two SPI bytes. With a 12 MHz crystal oscillator, software SPI takes seconds to refresh one frame. Therefore, in actual projects, when displaying characters and images, the method of filling the entire block is used. First, an area is enclosed using CASET and RASET, then all pixels in that area are sent continuously, and finally, the DC is raised and the command is written to end the process. A common practice is to create an LCD_FillRect function that calls the point-drawing area. After setting it, a for loop is used to directly
After sending the color data, do not switch the DC in the middle. This way, the ST7735 will automatically set the GRAM address to 1 until the window is filled. ASCII character display is based on an 8x16 or 8x8 dot matrix table. The 8x8 small font library is more commonly used on C51. When displaying all the 8-byte templates of ASCII characters in the code area, use the character encoding to index to the starting offset, extract the data column by column, and use each bit as the color switch for the pixel. Chinese fonts are relatively challenging on C51. Firstly, the font data is large, and secondly, the processing of GB2312 encoding is complex. If Chinese characters must be displayed, it is recommended to only include the 16x16 font data for the dozen or so characters needed and use encoding to look up the table instead of loading the entire font library. 4. STM32 hardware SPI and Arduino library porting: Performance improvements and quick results. An 8-bit platform like C51 can only solve the "lighting up" problem. On the STM32 or Arduino platform, the driving method shifts from register simulation to hardware SPI and ready-made libraries. The STM32's hardware SPI can run at 16 MHz or higher, and DMA can free the CPU from the tedious task of pixel transfer. Arduino, on the other hand, uses Adafruit_ST7735 or TFT_eSPI to encapsulate the underlying details.
You can see the image in a few minutes. This chapter covers both approaches. 4.1 STM32 Hardware SPI Configuration SPI_CR1 and DMA Transfer of Frame Buffer Data The preferred method for driving the ST7735 on the STM32 is hardware SPI. Taking STM32F103C8T6 as an example, the SCLK and MOSI of SPI1 are multiplexed and mapped to PA5/PA7, while CS, DC, and RST are controlled by ordinary GPIOs. The initialization code is characterized by the selection of Master mode for SPI, clock idle at low level, the first transition edge sampling corresponding to CPOL0, CPHA0, 8-bit data length, and MSB first. void SPI1_Init(void) { GPIO_InitTypeDef gpio; SPI_InitTypeDef spi; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE); gpio.GPIO_Pin GPIO_Pin_5 | GPIO_Pin_7; // SCK and MOSI MISI