This section covers GLCD devices that use the SH1101A graphics controller.
The SH1101A is a single-chip CMOS OLED driver, 132 columns by 64 rows of RAM, used with 128 x 64
pixel panels (the visible area starts at RAM column 2). It is the same family as the SH1106/SH1106
used elsewhere in this library, and all the usual GCBASIC GLCD commands work with it: GLCDCLS,
GLCDPrint, Pset, Line, Box, FilledBox, Circle, FilledCircle, RoundRect, Triangle,
Ellipse, GLCDRotate, GLCDSetContrast, and the display modes.
Unlike several other small OLED controllers in this library, the SH1101A has no I2C interface
at all (confirmed in the SH1101A datasheet) - only an 8080-style 8-bit parallel bus, or a 4-wire
SPI interface (write-only: the serial interface cannot read the display back). Defining
I2C_DATA or HI2C_DATA alongside GLCD_TYPE_SH1101A compiles with a warning only, in case
another device on the board genuinely uses I2C.
The GCBASIC constants shown below control the configuration of the SH1101A controller. GCBASIC supports both the 8080 parallel bus and software SPI - this is shown in the examples below.
To use the SH1101A driver simply include the following in your user code. This will initialise
the driver as a #startup routine; with #option StartupMethodsDisabled (or when the display’s
own power supply must be switched on first), call InitGLCD yourself once power is applied.
'An 8080 parallel bus configuration, as wired on the Microchip PIC18F Starter Kit 1
#include <glcd.h>
; ----- Define GLCD Hardware settings
#define GLCD_TYPE GLCD_TYPE_SH1101A ' <<< the constant that selects this controller driver
#define GLCD_DATA_PORT PORTD ' D0..D7
#define GLCD_WR LATE.1 ' write strobe, active low
#define GLCD_RD LATE.0 ' read strobe, active low (held high)
#define GLCD_CS LATE.2 ' chip select, active low
#define GLCD_DC LATB.5 ' data / command (D/C#, A0)
#define GLCD_RESET LATB.4 ' optional: reset, active lowKey line: #define GLCD_TYPE GLCD_TYPE_SH1101A — tells <glcd.h> to compile in the SH1101A
driver. On the 8080 bus, GLCD_DATA_PORT is set back to an input after every write, since a pin
of it may be shared with other hardware (on the Starter Kit, RD6 is also the SD card/accelerometer
SPI2 input).
or,
'A 4-wire SPI configuration (software; write-only), with #define S4Wire_DATA
#include <glcd.h>
; ----- Define GLCD Hardware settings
#define GLCD_TYPE GLCD_TYPE_SH1101A
#define S4Wire_DATA
#DEFINE GLCD_DO PORTC.5
#DEFINE GLCD_SCK PORTC.4
#DEFINE GLCD_DC PORTB.1
#DEFINE GLCD_CS PORTC.3
#DEFINE GLCD_RESET PORTC.2The GCBASIC constants for control of display characteristics are shown in the table below.
| Constants | Controls | Options |
|---|---|---|
|
|
|
Required |
|
|
8080 parallel bus pins |
Required for the 8080 bus (mutually exclusive with the SPI pins below) |
|
|
4-wire software SPI pins (with |
Required for SPI (mutually exclusive with the 8080 bus pins above) |
|
|
Reset pin, active low |
Optional, either bus |
|
|
Panel geometry |
Fixed at |
|
|
Contrast at |
Optional - defaults to |
|
|
8080 bus only: removes the 1024-byte screen buffer, reading each byte back from the display before changing it. Slower, but frees RAM. Compiling this with the SPI bus instead of the 8080 bus stops the compile (the serial interface cannot read the display back) |
Optional, 8080 bus only |
|
|
With the full screen buffer: every |
Optional |
This example shows how to drive a SH1101A based Graphic LCD module on the 8080 parallel bus, as wired on the Microchip PIC18F Starter Kit 1.
#chip 18F46J50, 48
#include <glcd.h>
#define GLCD_TYPE GLCD_TYPE_SH1101A
#define GLCD_DATA_PORT PORTD
#define GLCD_WR LATE.1
#define GLCD_RD LATE.0
#define GLCD_CS LATE.2
#define GLCD_DC LATB.5
#define GLCD_RESET LATB.4
GLCDCLS
GLCDPrint 0, 0, "GCBASIC" ' <<< the GLCDPrint instruction
Box 0, 0, GLCD_WIDTH-1, GLCD_HEIGHT-1
Circle (44, 41, 15)
Line 0, 63, 64, 31
Do
LoopKey line: GLCDPrint 0, 0, "GCBASIC" — identical usage to the other OLED controllers in this
library; only the bus-selection constants above change which physical interface is used.
See Also:
- SSD1309 Controllers — a related small-OLED driver that also offers I2C
- GLCDCLS — clearing the display, as used above
- GLCDDrawChar — drawing a single character
- GLCDPrint — printing a value at a specific location, as used above
- Pset — setting a single pixel
Supported in <GLCD.H>

