This section covers GLCD devices that use the SSD1351 graphics controller. The SSD1351 is a single-chip controller/driver for 262K-color, graphic type OLED-LCD.
The GCBASIC constants shown below control the configuration of the SSD1351 controller. GCBASIC supports SPI, hardware and software SPI, connectivity. This is shown in the tables below.
GCBASIC supports 65K-color mode operations.
To use the SSD1351 driver simply include the following in your user code. This will initialise the driver.
#include <glcd.h>
#define GLCD_TYPE GLCD_TYPE_SSD1351
'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
#define GLCD_DC portb.0 ' Data command line
#define GLCD_CS portb.2 ' Chip select line
#define GLCD_RESET portb.1 ' Reset line
#define GLCD_DO portb.3 ' Data out | MOSI
#define GLCD_SCK portb.5 ' Clock Line
#define SSD1351_HardwareSPI ' remove/comment out if you want to use software SPI. If you are using PPS to setup the SPI - ensure that PPS SPI is disabled to use software SPI.The GCBASIC constants for control display characteristics are shown in the table below.
| Constants | Controls | Options |
|---|---|---|
|
|
|
|
|
|
Specifies the output pin that is connected to Data/Command IO pin on the GLCD. |
Required |
|
|
Specifies the output pin that is connected to Chip Select (CS) on the GLCD. |
Required |
|
|
Specifies the output pin that is connected to Reset pin on the GLCD. |
Required |
|
|
Specifies the output pin that is connected to Data Out (GLCD in) pin on the GLCD. |
Required |
|
|
Specifies the output pin that is connected to Clock (CLK) pin on the GLCD. |
Required |
|
|
Specifies that hardware SPI will be used |
SPI ports MUST be defined that match the SPI module for each specific microcontroller #define SSD1351_HardwareSPI |
|
HWSPIMode |
Specifies the speed of the SPI communications for Hardware SPI only. |
Optional defaults to MASTERFAST. Options are MASTERSLOW, |
The GCBASIC constants for control display characteristics are shown in the table below.
| Constants | Controls | Default |
|---|---|---|
|
|
The width parameter of the GLCD |
|
|
|
The height parameter of the GLCD |
|
|
|
Specifies the font width of the GCBASIC font set. |
|
The GCBASIC commands supported for this GLCD are shown in the table below. Always review the appropiate library for the latest full set of supported commands.
| Command | Purpose | Example |
|---|---|---|
|
|
Clear screen of GLCD |
|
|
|
Print string of characters on GLCD using GCB font set |
|
|
|
Print character on GLCD using GCB font set |
|
|
|
Print characters on GLCD using GCB font set |
|
|
|
Draw a box on the GLCD to a specific size |
|
|
|
Draw a box on the GLCD to a specific size that is filled with the foreground colour. |
|
|
|
Draw a line on the GLCD to a specific length that is filled with the specific attribute. |
|
|
|
Set a pixel on the GLCD at a specific position that is set with the specific attribute. |
Any color can be defined using a valid hexidecimal word value between 0x0000 to 0xFFFF. |
SSD1351_BLACK 'hexidecimal value 0x0000 SSD1351_BLUE 'hexidecimal value 0x001F SSD1351_RED 'hexidecimal value 0xF800 SSD1351_GREEN 'hexidecimal value 0x07E0 SSD1351_CYAN 'hexidecimal value 0x07FF SSD1351_MAGENTA 'hexidecimal value 0xF81F SSD1351_YELLOW 'hexidecimal value 0xFFE0 SSD1351_WHITE 'hexidecimal value 0xFFFF
Example:
#chip mega328p, 16
#option explicit
#include <glcd.h>
#define GLCD_TYPE GLCD_TYPE_SSD1351
'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
#define GLCD_DC portb.0 ' Data command line
#define GLCD_CS portb.2 ' Chip select line
#define GLCD_RESET portb.1 ' Reset line
#define GLCD_DO portb.3 ' Data out | MOSI
#define GLCD_SCK portb.5 ' Clock Line
#define SSD1351_HardwareSPI ' remove/comment out if you want to use software SPI. ' <<< selects hardware SPI for the SSD1351 link
'GLCD selected OLED font set.
#define GLCD_OLED_FONT
GLCDfntDefaultsize = 1
GLCDCLS
GLCDPrintStringLN ("GCBASIC")
GLCDPrintStringLN ("")
GLCDPrintStringLN ("Test of the SSD1351")
GLCDPrintStringLN ("")
GLCDPrintStringLN ("October 2021")
endKey line: #define SSD1351_HardwareSPI — routes the SSD1351 traffic through the microcontroller’s hardware SPI module instead of a bit-banged software implementation;
commenting this line out falls back to software SPI, which works on any pins but is slower (remember to disable PPS SPI first
if the pins were previously mapped through PPS).
See Also:
- GLCDCLS — clearing the display, as used above
- GLCDDrawChar — drawing a single character
- GLCDPrint — printing a value at a specific location
- GLCDReadByte / GLCDWriteByte — low-level byte access, for expert use
- Pset — setting a single pixel
Supported in <GLCD.H>

