This section covers GLCD devices that use the SH1106 graphics controller. THe SH1106 is a single-chip CMOS OLED/PLED driver with controller for organic/polymer light emitting diode dot-matrix graphic display system. SH1106 consists of 132 segments, 64 commons that can support a maximum display resolution of 132 X 64. It is designed for Common Cathode type OLED panel.
The GCBASIC constants shown below control the configuration of the SH1106 controller. GCBASIC supports i2C hardware and software connectivity - this is shown in the tables below.
The SH1106 is a monochrome device.
To use the SH1106 driver simply include the following in your user code. This will initialise the driver. You can select Full Mode GLCD, Low Memory Mode GLCD or Text mode these require 1024, 128 or 0 byte GLCD buffer respectively - you microcontroller requires sufficient RAM to support the selected mode of GLCD operation.
Specific to the Rajguru Electronics 13002-Series display you can can specify a GLCD_SubType 13002 to enable support.
#include <glcd.h>
; ----- Define GLCD Hardware settings
#define GLCD_TYPE GLCD_TYPE_SH1106
#define GLCD_I2C_Address 0x78
'#define GLCD_TYPE_SH1106_LOWMEMORY_GLCD_MODE 'select Low Memory mode of operation
'#define GLCD_TYPE_SH1106_CHARACTER_MODE_ONLY 'select Text mode of operation
'#define GLCD_SubType 13002 'add to support Rajguru Electronics 13002-Series display
; ----- Define Hardware settings
' Define I2C settings
#define HI2C_BAUD_RATE 400
#define HI2C_DATA
HI2CMode MasterThe GCBASIC constants for control display characteristics are shown in the table below.
| Constants | Controls | Options |
|---|---|---|
|
|
|
Required |
|
|
I2C address of the GLCD. |
Required |
|
|
|
400 or 100 |
|
|
|
Mandated, plus |
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. |
|
|
|
Specifies that the display controller will operate in text mode and BMP
draw mode only. |
Optional |
|
|
Specifies that the display controller will operate in Low Memory mode. |
Optional |
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. |
|
|
|
Set a byte value to the controller, see the datasheet for usage. |
|
|
|
Read a byte value from the controller, see the datasheet for usage. |
|
|
|
Commence a series of GLCD commands when in low memory mode. Must be followed a |
|
|
|
Commence a series of GLCD commands when in low memory mode. Must follow a |
The additional GCBASIC commands for this GLCD are shown in the table below.
| Command | Purpose |
|---|---|
|
|
Inverts the display |
|
|
Set the display to normal mode |
|
|
Sets the constrast between 0 and 255. The contrast increases as the value increases. |
For a SH1106 datasheet, please refer here.
This example shows how to drive a SH1106 based Graphic LCD module with the built in commands of GCBASIC.
; ----- Configuration
#chip mega328p,16
#include <glcd.h>
; ----- Define Hardware settings
' Define I2C settings
#define HI2C_BAUD_RATE 400
#define HI2C_DATA
HI2CMode Master
; ----- Define GLCD Hardware settings
#define GLCD_TYPE GLCD_TYPE_SH1106
#define GLCD_I2C_Address 0x78
GLCDCLS
GLCDPrint 0, 0, "GCBASIC"
GLCDPrint (0, 16, "Anobium 2021")
wait 3 s
GLCDCLS
' Prepare the static components of the screen
GLCDPrint ( 0, 0, "PrintStr") ; Print some text
GLCDPrint ( 64, 0, "@")
; Print some more text
GLCDPrint ( 72, 0, ChipMhz) ; Print chip speed
GLCDPrint ( 86, 0, "Mhz") ; Print some text
GLCDDrawString( 0,8,"DrawStr") ; Draw some text
box 0,0,GLCD_WIDTH-1, GLCD_HEIGHT-1 ; Draw a box
box GLCD_WIDTH-5, GLCD_HEIGHT-5,GLCD_WIDTH-1, GLCD_HEIGHT-1 ; Draw a box
Circle( 44,41,15) ; Draw a circle
line 64,31,0,31 ; Draw a line
DO forever
for CCount = 31 to 127
GLCDPrint ( 64 , 36, hex(longNumber_E ) ) ; Print a HEX string
GLCDPrint ( 76 , 36, hex(longNumber_U ) ) ; Print a HEX string
GLCDPrint ( 88 , 36, hex(longNumber_H ) ) ; Print a HEX string
GLCDPrint ( 100 , 36, hex(longNumber ) ) ; Print a HEX string
GLCDPrint ( 112 , 36, "h" ) ; Print a HEX string
GLCDPrint ( 64 , 44, pad(str(wordNumber), 5 ) ) ; Print a padded string
GLCDPrint ( 64 , 52, pad(str(byteNumber), 3 ) ) ; Print a padded string
box (46,9,56,19) ; Draw a Box
GLCDDrawChar(48, 9, CCount ) ; Draw a character
outString = str( CCount ) ; Prepare a string
GLCDDrawString(64, 9, pad(outString,3) ) ; Draw a string
filledbox 3,43,11,51, wordNumber ; Draw a filled box
FilledCircle( 44,41,9, longNumber xor 1) ; Draw a filled box
line 0,63,64,31 ; Draw a line
; Do some simple maths
longNumber = longNumber + 7 : wordNumber = wordNumber + 3 : byteNumber++
NEXT
LOOP
endThis example shows how to drive a SH1106 based Graphic I2C LCD module with the built in commands of GCBASIC using Low Memory Mode GLCD.
Note the use of GLCD_Open_PageTransaction and GLCD_Close_PageTransaction to support the Low Memory Mode of operation and the contraining of all GLCD commands with the transaction commands. The
use Low Memory Mode GLCD the two defines GLCD_TYPE_SH1106_LOWMEMORY_GLCD_MODE and GLCD_TYPE_SH1106_CHARACTER_MODE_ONLY are included in the user program.
#chip mega328p,16
#include <glcd.h>
; ----- Define Hardware settings
' Define I2C settings
#define HI2C_BAUD_RATE 400
#define HI2C_DATA
HI2CMode Master
; ----- Define GLCD Hardware settings
#define GLCD_TYPE GLCD_TYPE_SH1106 'for 128 * 64 pixels support
#define GLCD_I2C_Address 0x78
#define GLCD_TYPE_SH1106_LOWMEMORY_GLCD_MODE
#define GLCD_TYPE_SH1106_CHARACTER_MODE_ONLY
dim outString as string * 21
GLCDCLS
GLCD_Open_PageTransaction 0,7
GLCDPrint 0, 0, "GCBASIC"
GLCDPrint (0, 16, "Anobium 2021")
GLCD_Close_PageTransaction
wait 3 s
GLCDCLS
DO forever
for CCount = 31 to 127
outString = str( CCount ) ; Prepare a string
GLCD_Open_PageTransaction 0,7
' Prepare the static components of the screen
GLCDPrint ( 0, 0, "PrintStr") ; Print some text
GLCDPrint ( 64, 0, "@")
; Print some more text
GLCDPrint ( 72, 0, ChipMhz) ; Print chip speed
GLCDPrint ( 86, 0, "Mhz") ; Print some text
GLCDDrawString( 0,8,"DrawStr") ; Draw some text
box 0,0,GLCD_WIDTH-1, GLCD_HEIGHT-1 ; Draw a box
box GLCD_WIDTH-5, GLCD_HEIGHT-5,GLCD_WIDTH-1, GLCD_HEIGHT-1 ; Draw a box
Circle( 44,41,15) ; Draw a circle
line 64,31,0,31 ; Draw a line
GLCDPrint ( 64 , 36, hex(longNumber_E ) ) ; Print a HEX string
GLCDPrint ( 76 , 36, hex(longNumber_U ) ) ; Print a HEX string
GLCDPrint ( 88 , 36, hex(longNumber_H ) ) ; Print a HEX string
GLCDPrint ( 100 , 36, hex(longNumber ) ) ; Print a HEX string
GLCDPrint ( 112 , 36, "h" ) ; Print a HEX string
GLCDPrint ( 64 , 44, pad(str(wordNumber), 5 ) ) ; Print a padded string
GLCDPrint ( 64 , 52, pad(str(byteNumber), 3 ) ) ; Print a padded string
box (46,8,56,19) ; Draw a Box
GLCDDrawChar(48, 9, CCount ) ; Draw a character
GLCDDrawString(64, 9, pad(outString,3) ) ; Draw a string
filledbox 3,43,11,51, wordNumber ; Draw a filled box
FilledCircle( 44,41,9, longNumber xor 1) ; Draw a filled box
line 0,63,64,31 ; Draw a line
GLCD_Close_PageTransaction
; Do some simple maths
longNumber = longNumber + 7 : wordNumber = wordNumber + 3 : byteNumber++
NEXT
LOOP
endFor more help, see GLCDCLS, GLCDDrawChar, GLCDPrint, GLCDReadByte, GLCDWriteByte or Pset
Supported in <GLCD.H>

