128×64 グラフィック LCD をマイクロコントローラーで使用する方法
How to Use a 128×64 Graphic LCD with a Microcontroller
128×64 graphic LCD is a versatile display solution widely used in embedded systems, 産業機器, 測定器, コントロールパネル, 医療機器, そしてDIYエレクトロニクス. Unlike character LCD modules that mainly display predefined letters and numbers, a graphic LCD provides a matrix of pixels that allows a microcontroller to display text, アイコン, シンボル, シンプルなグラフィック, メニュー, and custom user interfaces.
With a resolution of 128 水平方向のピクセルと 64 垂直方向のピクセル, this type of LCD offers enough display area for many compact embedded applications while maintaining low power consumption and relatively simple control requirements. This article explains how to connect, initialize, and use a 128×64 graphic LCD with a microcontroller.
1. What Is a 128×64 Graphic LCD?
128×64 graphic LCD contains 8,192 individually controllable pixels arranged in 128 コラムと 64 行. Each pixel can normally be switched on or off independently, making the display suitable for monochrome graphics.
Depending on the module design, a 128×64 LCD may use controllers such as ST7920, KS0108, ST7565, UC1701, or compatible LCD controllers. Different controllers require different communication methods and initialization commands, so checking the LCD datasheet before starting development is very important.
Common 128×64 LCD features include:
- 128×64 pixel resolution
- Monochrome display
- LED backlight options
- Parallel or serial communication
- 低消費電力
- Custom character and graphic display
- Wide range of viewing modes
- Support for embedded microcontrollers
They can be used with Arduino boards, STM32 microcontrollers, PIC MCUs, AVR devices, ESP32 boards, and many other embedded platforms.
2. Understand the LCD Pinout
Before connecting the LCD, identify the interface and pin definitions from the manufacturer's datasheet.
Typical parallel 128×64 graphic LCD may include pins for:
- VSS – Ground
- VDD – Power supply
- VO – LCD contrast adjustment
- RS or DI – Register/Data selection
- R/W – Read/Write control
- E – Enable signal
- D0–D7 – Data bus
- CS1 / CS2 – Chip selection
- RST – Reset
- LED+ – Backlight positive
- LED− – Backlight negative
Modules using an ST7920 controller may also support serial communication, reducing the number of microcontroller GPIO pins required.
Always confirm the operating voltage. Some modules are designed for 5 V systems, while others operate at 3.3 V. Connecting a display to an incorrect voltage may result in unstable operation or permanent damage.
3. Connect the LCD to the Microcontroller
After identifying the pins, connect the display to the microcontroller.
For a parallel interface, connect the LCD data pins to available GPIO pins on the MCU. Then connect the control lines such as RS, E, R/W, CS, and RST.
Basic connection may look like:
Microcontroller → Graphic LCD
VCC → VDD
GND → VSS
GPIO → RS
GPIO → E
GPIO → R/W
GPIO → RST
GPIO pins → D0–D7
If the module supports an 8-bit parallel interface, eight GPIO pins are required for the data bus. Some controllers can operate in a 4-bit or serial mode to reduce pin usage.
For applications where GPIO resources are limited, an SPI or serial graphic LCD is often more convenient.
4. Adjust the LCD Contrast
LCD contrast is essential for obtaining a clear display.
Many graphic LCD modules include a VO or V0 contrast pin. A potentiometer can be connected between the supply voltage and ground, with the center terminal connected to the LCD contrast input.
Rotate the potentiometer until the pixels appear clearly.
If the contrast voltage is incorrect, the LCD may appear completely blank or display a dark screen even though the microcontroller program is working correctly.
したがって, if nothing appears during initial testing, checking the contrast setting should be one of the first troubleshooting steps.
5. Initialize the Graphic LCD
After the hardware connection is complete, the microcontroller must initialize the LCD controller.
The initialization procedure depends on the controller IC. It usually includes:
- Resetting the LCD controller
- Selecting the communication mode
- Turning the display on
- Configuring the display parameters
- Clearing the display memory
- Setting the initial drawing position
例えば, an LCD library may contain an initialization command such as:
lcd_init();After initialization, the program can clear the screen:
lcd_clear();Using a compatible LCD library can greatly simplify development because the low-level timing and controller commands are already handled by the software.
6. 表示テキスト
Although a graphic LCD does not work exactly like a standard character LCD, text can still be displayed using bitmap fonts.
Each character is stored as a small pixel pattern. 例えば, a 5×7 or 8×8 font can be stored inside the microcontroller's flash memory.
The program reads the font data and transfers the corresponding pixels to the LCD.
Typical function could look like:
lcd_draw_string(10, 10, "Hello World");Here, the first two values represent the X and Y coordinates.
This method gives designers more flexibility than a conventional character LCD because different font sizes, styles, アイコン, and custom symbols can be used.
7. Draw Graphics and Icons
One of the main advantages of a 128×64 graphic LCD is the ability to draw graphical elements.
Depending on the software library, common functions include:
draw_pixel(x, y);
draw_line(x1, y1, x2, y2);
draw_rectangle(x, y, width, height);
draw_circle(x, y, radius);These functions can be combined to create menus, battery indicators, temperature symbols, プログレスバー, graphs, warning icons, or equipment status interfaces.
例えば, an industrial controller could display:
- Current temperature
- Machine status
- Battery level
- Operating mode
- Alarm symbols
- Simple trend graphs
All of these elements can be arranged freely within the 128×64 pixel area.
8. Use a Frame Buffer
For more advanced applications, developers often create a frame buffer inside the microcontroller's RAM.
Full monochrome 128×64 image requires:
128 × 64 ÷ 8 = 1024 bytes
This means a complete screen image can be stored in approximately 1 KB of RAM.
The microcontroller first modifies the image in memory and then transfers the entire buffer to the LCD.
This technique provides smoother graphics and makes it easier to draw multiple interface elements before refreshing the screen.
しかし, microcontrollers with very limited RAM may use partial screen updates instead.
9. Important Programming Considerations
When developing software for a graphic LCD, several factors should be considered.
First, confirm the controller type and communication timing. Sending commands too quickly may cause missing pixels or incorrect display data.
Second, minimize unnecessary full-screen refreshes. Graphic LCDs do not usually require extremely high refresh rates. Updating only the changed part of the display can reduce MCU workload.
Third, organize fonts and graphics efficiently. Bitmap images can consume significant flash memory, particularly when many icons or large fonts are used.
Finally, use hardware SPI or optimized parallel communication where possible if faster screen updates are required.
10. Troubleshooting Common Problems
If the LCD does not work correctly, check the following areas.
Blank screen: Verify the power supply, contrast voltage, 配線, reset signal, and initialization sequence.
Random pixels: Check communication timing and data connections.
Text appears incorrectly: Confirm that the font mapping and LCD memory addressing are correct.
Only part of the screen works: On controllers such as KS0108, check the chip-select signals because the 128-pixel-wide screen may be divided between two controller sections.
Backlight does not work: Verify LED polarity and whether a current-limiting resistor is required.
Testing the display with a simple pixel or text example before developing the complete user interface can make debugging much easier.
結論
Using a 128×64 graphic LCD with a microcontroller provides an effective way to create flexible embedded user interfaces. Compared with traditional character LCD modules, graphic displays allow developers to freely combine text, 数字, アイコン, シンボル, 行, and custom graphics.
The basic development process includes identifying the LCD controller, checking the pinout, connecting the display correctly, adjusting contrast, initializing the controller, and writing data to the LCD memory.
Once communication is established, developers can create everything from simple status screens to sophisticated menus and graphical instrument interfaces.
With its compact size, relatively low power consumption, customizable graphics, and broad microcontroller compatibility, の 128×64 graphic LCD display module remains a practical choice for industrial controllers, measurement equipment, スマートデバイス, 計器類, and many other embedded applications.






