This paper selects STMicroelectronics' STM32F103RB based on the latest ARM Cortex-M3 core as the main control chip, and constructs a high-performance, low-power Chinese human-machine interface system by selecting a suitable LCD module.
1. System Working Principle
This system uses the STM32F103RBT6 as its core and an AM240320 TFT LCD screen from Crystal Optoelectronics as its display. Since the STM32F103RBT6 has only 128KB of internal Flash memory, using it to store Chinese character libraries would be a significant waste of chip resources. Therefore, this paper adopts a design approach where the microcontroller has an external SPI interface Flash memory. Characters that do not need repeated modification are stored in an external Flash chip and retrieved from the processor via the SPI interface when needed. Because the STM32F103RBT6 does not have an FSMC (Free Frame Controller), a software-simulated bus method is used to drive the LCD module.
2. System Hardware Design
2.1 Power Supply Circuit
Since the entire system uses a 3.3V power supply, an external voltage regulator circuit is required to stabilize the voltage at 3.3V. This design uses a three-terminal voltage regulator chip, LM1117-3.3, to stabilize the external battery voltage at 3.3V to power the system, supplying power to the processor, LCD, and SPI Flash. A diode IN4007 is connected in series with the positive terminal of the power supply to provide reverse connection protection for the system. The schematic diagram of the power supply section is shown in Figure 1.
Figure 1 Schematic diagram of the system power supply section
2.2 Circuit Design of Liquid Crystal Display Section
The LCD display section is mainly driven by a microcontroller to display the status of the human-machine interface . By sending command words, the LCD module is initialized and Chinese characters are displayed.
2.2.1 Features of STM32F Series ARM Microcontrollers
The STM32 processor uses ARM's latest V7 architecture core, the Cortex-M3, which is one-third faster and consumes three-quarters less power than the ARM7. It integrates branch prediction, single-cycle multiplication, and hardware division, significantly improving the processor's data processing capabilities. It also employs the latest Thumb-2 instruction set, effectively reducing code density and improving program execution efficiency. Based on power consumption and performance analysis, this paper uses the STM32F103RBT6 processor, which operates at 72MHz and features built-in high-speed memory (up to 128KB of flash memory and 20KB of SRAM), abundant enhanced I/O ports, and peripherals connected to two APB buses. With a power supply voltage of 2.0–3.6V, a series of power-saving modes ensure low-power application requirements, achieving a balance between performance and power consumption.
2.2.2 Characteristics of TFT LCD Display Modules
TFT LCD screens are thin-film transistor liquid crystal displays. Each pixel in a TFT LCD has a semiconductor switch, allowing each pixel to be directly controlled by a pulse. Therefore, each pixel is relatively independent and can be continuously controlled. This not only improves the display's response speed but also allows for precise control of color levels, resulting in more realistic colors in TFT LCDs.
Since most ARM processors with LCD controllers lack internal program and data memory, and most Cortex-M3 core microcontrollers do not have dedicated LCD controllers, systems without LCD controllers typically use the Intel 8080 interface or Motorola's 6800 interface. This system uses STM32's high-speed I/O ports to simulate the 8080 interface timing. Therefore, the selected TFT LCD must meet two conditions: first, it must have independent video memory; second, it must have an 8080 interface. The design uses an AM240320 TFT LCD screen from Crystal Optoelectronics (Taiwan), with its main control chip being the ILI9320. It has a built-in video memory of 172820 bytes (240x320x18/8), and the 16-bit data lines correspond to the display size in a 565 manner. It supports various control input signals, including the 8080 interface.
The STM32 uses an external 8MHz crystal oscillator as the input clock, and an internal phase-locked loop multiplies the clock to 72MHz as the system clock. It uses GPIO ports to simulate 8080 timing and drive a 2.8-inch TFT screen in parallel. The hardware circuit interface circuit of the display part processor and LCD is shown in Figure 2.
Figure 2 System LCD Interface Schematic Diagram
2.3 Characteristics of SPI Interface Flash Storage Stack
Since the entire Chinese character library in this system needs to be stored in external Flash memory, a Flash memory chip needs to be selected. The selection of the Flash memory chip needs to meet the following requirements. First, we aim to minimize the number of I/O ports used. Since LCD displays already employ parallel interfaces, continuing to use parallel interface Flash memory would consume more I/O ports, necessitating the selection of chips with even more I/O ports. This is unreasonable for portable devices. Therefore, the Flash memory selected in this system design is the SST25VF080B from SST Corporation. It uses an SPI interface, a high-speed, full-duplex, synchronous communication bus that only requires four pins, saving pins and PCB layout space. Due to its ease of use, more and more chips are integrating this communication protocol. The SPI Flash memory used in this paper is the SST25VF080B chip from SST Corporation, with a capacity of 8M bits. Its operating voltage range is 2.7–3.6V, operating in SPI mode 0 or mode 3, with a maximum operating frequency of 50MHz. The minimum erase unit is a 4KB sector, allowing for 100,000 erase/write cycles and data retention for over 100 years. The STM32F103RBT6 has a high-speed hardware SPI interface, which can easily connect and communicate with the SST25VF080B. Therefore, we use SPIFlash to store the Chinese character library. The hardware circuit interface diagram of the character library storage part is shown in Figure 3.
Figure 3 Schematic diagram of the SPI Flash interface
3. System Software Design
The system software consists of two parts: character library access and TFT LCD display software design. Character library access is primarily achieved through the SPI interface of the STM32F103RBT6, calling the Chinese character library stored in the SST25VF080B. The TFT LCD display mainly uses the STM32F103RBT6's general-purpose I/O port to simulate a 16-bit 8080 parallel port to drive the LCD. One issue to consider during software design is that different character libraries use different encoding standards, resulting in slight differences in decoding. Commonly used Chinese character libraries include GB2312 and GBK.
3.1 GB2312 and GBK character sets
GB2312 includes 7445 graphic characters, including simplified Chinese characters and symbols, letters, and Japanese kana, of which 6763 are Chinese characters. GB2312 stipulates that "each graphic character is represented by two bytes, with each byte using a seven-bit encoding." The first byte is conventionally called the "high byte," and the second byte is called the "low byte." GB2312-80 includes most commonly used level 1 and 2 Chinese characters, and symbols from zone 9. This character set is supported by almost all Chinese systems and internationalized software, and it is the most basic Chinese character set. Its encoding range is 0xa1 to 0xfe in both the high and low bytes; Chinese characters start at 0xb0a1 and end at 0xf7fe. GB2312 divides the code table into 94 zones, corresponding to the first byte (0xa1~0xfe); each zone has 94 bits (0xa1~0xfe), corresponding to the second byte. The values of the two bytes are the zone number and the position number, respectively, plus 32 (20H), hence it is also called the zone-position code. Zones 01~09 are for symbols and numbers, zones 16~87 are for Chinese characters (0xb0~0xf7), and zones 10~15 and 88~94 are blank areas awaiting further standardization. GB2312 divides the included Chinese characters into two levels: the first level contains 3755 commonly used Chinese characters, placed in zones 16~55, arranged in alphabetical order by Pinyin/stroke order; the second level contains 3008 less commonly used Chinese characters, placed in zones 56~87, arranged in radical/stroke order. Therefore, GB2312 can represent a maximum of 6763 Chinese characters.
The GBK encoding is fully compatible with GB2312 and supports Traditional Chinese characters, containing over 20,000 characters. The encoding format is as follows: each GBK character consists of two bytes. The first byte is 0x81~0xFE, and the second byte is divided into two parts: 0x40~0x7E and 0x80~0xFE. The characters in the same regions as in GB2312 are identical. The meaning represented by the first byte is called the zone. Therefore, GBK has a total of 126 zones (0xFE~0x81+1), and each zone contains 190 characters (0xFE~0x80+0x7E~0x40+2), for a total of 126 x 190 = 23940 characters. The dot matrix library is built sequentially starting from 0x8140, with the dot matrix size of each zone multiplied by the number of bytes used for each character. This allows us to locate Chinese characters within the font library.
When GBKL < 0X7F: Hp = ((GBKH-0x81) × 190 + GBKL-0X40) × (size x 2);
When GBKL > 0X80: Hp = ((GBKH-0x81) × 190 + GBKL-0X41) × (size x 2);
Where GBKH and GBKLL represent the first and second bytes (i.e., the high and low bits) of GBK respectively, size represents the size of the Chinese character font (e.g., 16-bit font, 12-bit font, etc.), and Hp is the starting address of the corresponding Chinese character dot matrix data in the font library.