High-resolution HD44780-compatible LCDs: introducing the ST7920

nick12ab

Senior Member
Character LCDs are a very popular and low-cost addition to an electronics project. The HD44780 interface is the de-facto character LCD interface for these types of displays, which makes finding code examples easy as well as switching between different display sizes and manufacturers.

Unfortunately the low resolution (5x8 characters) makes the display very blocky. It's also unsuitable for the very complex Chinese character set, due to both the low resolution and having only 8 bits per character, though this is probably irrelevant to the majority of you reading this. Fortunately, the Chinese came up with the solution: the Sitronix ST7920.

The ST7920 has actually been around for the best part of two decades, but it doesn't seem to get much attention. Just another graphic display controller like the crude KS0108B? No! This advanced display controller brings high-resolution (8x16 and 16x16) in-built character ROMs and a comprehensive instruction set compatible with the HD44780 command set. This allows it to be used as a near drop-in replacement for traditional 5x8 HD44780-compatible displays with minimal code changes, and it even works with the AXE133 PCB.

display-comparison-small.jpg

A variety of sizes are available, but the most common are:
  • 128x32 (equivalent to 16x2 or 8x2 characters)
  • 128x64 (equivalent to 16x4 or 8x4 characters and mechanically compatible with many KS0108B GLCDs)

These displays are very inexpensive (the displays are typically cheaper than the KS0108B equivalent) and available from a few manufacturers. The ST7920 incorporates cost-cutting measures like an in-built diode charge pump to generate the LCD voltage instead of relying on external 7660 charge pumps like KS0108B-based displays do, which helps to keep module costs down.

This article assumes good working knowledge of the HD44780 command set.

Sounds too good to be true? OK, there's a catch... the character addresses are not the same as a HD44780-compatible LCD. Also, because the controller was designed around Chinese characters (16x16 pixels) first and the Western characters are more of an afterthought (8x16 pixels), each address represents two Western characters. The start addresses of each line are:
  1. 128 (same as HD44780)
  2. 144 (192 on HD44780)
  3. 136 (148 on HD44780)
  4. 152 (212 on HD44780)
So yes, that means 128 is the first character, 129 is the third character, and 130 is the fifth character. If you want to write the second character, fourth character, etc. then you must overwrite the character before it as well. Most projects won't be affected because they just write a whole line at a time, but it may impact you if you're hoping to continuously update a right-aligned 3-digit number for example. This also means you can't "upgrade" a third-party closed-source product with a new display because you need to change the addresses in the code.

Getting started

Link to the ST7920 datasheet (link updated)

Aside from changing the addresses, if you only need to display text then you can send data to it just like any regular HD44780-compatible LCD. The display plugs directly into the AXE133 PCB ("staggered" like the 20x4 OLED), and all you need is to add a wire from the PSB pin on the LCD module to 'high' to set it to parallel mode. The only other electrical change to note is you have to turn Vo up to increase the contrast, the opposite of a HD44780 LCD, and you may wish to wire up the backlight pins and fit a PNP transistor to the AXE133 PCB. No code changes are required to the AXE133 firmware unless you're concerned about the welcome message, so if you send it some text like so, it should display it:
Example for sending to the AXE133 PCB via the serial connection: 254,128,"High-resolution ",254,144," Mostly HD44780-",254,136," Compatible LCD ",254,152,"with AXE133-PCB!"

20191004_160017.jpg
20191004_144143-1.jpg

On to the more advanced features...

The custom character (CGRAM) feature is not too dissimilar to that on HD44780 displays. There are four 16x16 CGRAM characters. To display them, write 0x00,0x00 for the first, 0x00,0x02 for the second, 0x00,0x04 for the third and 0x00,0x06 for the fourth while in data mode. To modify them, set the address counter to 64 just like when changing the CGRAM on a HD44780 LCD (when using the parallel interface, write 0x40 in instruction mode, or when using the AXE133, send 254,64), then write the character bitmap in data mode. The first data byte is the first 8 pixels on the first row, the second byte is the next 8 pixels on the first row, then the third byte is the first 8 pixels on the second row, and so on.

There are full-width Western characters in the Chinese character set. These are displayed by sending the appropriate GB or BIG5 codes e.g. 0xA3,0xC1 for 'A' in GB code. These can be used to display a bigger font with 8 characters per line. It is inadvisable to mix half-width and full-width characters; it will work, but it looks terrible.

20191004_150229-1.jpg

Notes about Chinese characters:
  • The controller is available in versions with characters encoded using GB encoding or BIG5 encoding, with each character encoded using two bytes. The EastRising ERM12864SYG-6 module, which is the one I'm using, uses GB encoding.
  • The characters are 16x16 pixels
  • If overwriting Chinese characters with English text, be sure to write an even number of characters (or clear the screen first), otherwise the English character represented by the second byte of the Chinese character will be displayed

Extended instruction mode

Extended instruction mode is used to draw graphics on the display. The datasheet explains the instructions well, so I won't cover it all here; I'll just mention the basics.

  • Any text is displayed at the same time as the graphics in graphics mode. The graphics and text pixels are XORed together to give the final display.
  • You can switch between basic and extended modes at any time.
  • Each byte represents a row of 8 pixels, so addressing is more similar to the T6963 and completely different to the KS0108B.
  • It is inadvisable to use the AXE133, although it will work, because the performance is bad and you can't write 255, 254 or 253 because they're reserved for AXE133 functions.

To enter, write the following as an instruction:
Text mode: 0b00110100
Graphic+text mode: 0b00110110
Back to basic instruction mode: 0b00110000 (text is superimposed on graphics unless you send the text mode instruction above first)

Drawing a 16-pixel high block of black pixels will give you light text on a dark background. See the attached file for a quick-and-dirty modified version of the AXE133 firmware which demonstrates this. The comparison image at the top of the page shows the result of running the attched code.
 

Attachments

Last edited:

hippy

Technical Support
Staff member
Very interesting. I don't recall seeing the ST7920 previously, or did and assumed it was a graphic rather than text display. One of its big advantages is it is a 2V7-5V5 device where HD74480's usually have problems below 5V.

My PDF reader wanted additional fonts downloading for your datasheet link; but I found a datasheet which didn't -

https://www.crystalfontz.com/controllers/Sitronix/ST7920/323
 

nick12ab

Senior Member
One of its big advantages is it is a 2V7-5V5 device where HD74480's usually have problems below 5V.
It's not quite that simple. A few extra external components need to be added for 3.3V operation (detailed on page 36 of your datasheet), and the principle of that is similar to this method of modifying HD44780-compatible LCDs for 3.3V operation except without the need for an extra IC.

Your datasheet is a bit newer than mine. It looks like the authors left some Chinese characters in the diagrams in the one I linked, which they removed in the updated version.
 
Top