ST7735 Controllers

This section covers GLCD devices that use the ST7735 graphics controller. The ST7735 or ST7735R is a single-chip controller/driver for 262K-color, graphic type TFT-LCD.

GCBASIC supports 65K-color mode operations.

The GCBASIC constants shown below control the configuration of the ST7735 or ST7735R controller.    GCBASIC supports an 8 bit bus connectivity. The 8 bit must be a single port of consective bits - this is shown in the tables below.

To use the ST7735 driver simply include the following in your user code. This will initialise the driver.

    #include <glcd.h>
    #define GLCD_TYPE GLCD_TYPE_ST7735R          ' <<< the constant that selects this controller driver
    #define ST7735TABCOLOR ST7735_BLACKTAB  ; can also be ST7735_GREENTAB or ST7735_REDTAB or GLCD_TYPE_ST7735R_160_80

    'Pin mappings for ST7735
    #define GLCD_DC     porta.0           'example port setting
    #define GLCD_CS    porta.1           'example port setting
    #define GLCD_RESET  porta.2           'example port setting
    #define GLCD_DI     porta.3           'example port setting
    #define GLCD_DO     porta.4           'example port setting
    #define GLCD_SCK    porta.5           'example port setting

Key line: #define GLCD_TYPE GLCD_TYPE_ST7735R — tells <glcd.h> to compile in the ST7735R driver; ST7735TABCOLOR then selects which physical tab variant of the chip is fitted, since different manufacturing batches need different internal offsets to display correctly.

The GCBASIC constants for control display characteristics are shown in the table below.

Constants Controls Options

GLCD_TYPE

GLCD_TYPE_ST7735 or GLCD_TYPE_ST7735R or GLCD_TYPE_ST7735R_160_80

 

ST7735TABCOLOR

Specifies the type of ST7735 chipset. The default is ST7735_BLACKTAB

Options are ST7735_BLACKTAB, ST7735_GREENTAB or ST7735_REDTAB. Each tab is a different ST7735 configuration. If you do not know your type try each constant and test.

GLCD_DATA_PORT

Not Available for this controller.

Not applicable.

GLCD_DC

Specifies the output pin that is connected to Data/Command IO pin on the GLCD.

Required

GLCD_CS

Specifies the output pin that is connected to Chip Select (CS) on the GLCD.

Required

GLCD_Reset

Specifies the output pin that is connected to Reset pin on the GLCD.

Required

GLCD_DI

Specifies the output pin that is connected to Data In (GLCD out) pin on the GLCD.

Required

GLCD_DO

Specifies the output pin that is connected to Data Out (GLCD in) pin on the GLCD.

Required

GLCD_SCK

Specifies the output pin that is connected to Clock (CLK) pin on the GLCD.

Required

ST7735_HardwareSPI

Specifies that hardware SPI will be used

SPI ports MUST be defined that match the SPI module for each specific microcontroller

#define ST7735_HardwareSPI

HWSPIMode

Specifies the speed of the SPI communications for Hardware SPI only.

Optional defaults to MASTERFAST.

Options are MASTERSLOW,
MASTER,
MASTERFAST, or
MASTERULTRAFAST for specific AVRs only.

     

ST7735_XSTART

Specifies the adjustment made to the X axis when writing to the GLCD. This is used to correct any geometry correction required for specific GLCDs.

Optional. Defaults are set for each specific GLCD.

ST7735_YSTART

Specifies the adjustment made to the Y axis when writing to the GLCD. This is used to correct any geometry correction required for specific GLCDs.

Optional. Defaults are set for each specific GLCD.

The GCBASIC constants for control display characteristics are shown in the table below.

Constants Controls Default

GLCD_WIDTH

The width parameter of the GLCD

160
This cannot be changed

GLCD_HEIGHT

The height parameter of the GLCD

128
This cannot be changed

GLCDFontWidth

Specifies the font width of the GCBASIC font set.

6

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

GLCDCLS

Clear screen of GLCD

GLCDCLS

GLCDPrint

Print string of characters on GLCD using GCB font set

GLCDPrint( Xposition, Yposition, Stringvariable )

GLCDDrawChar

Print character on GLCD using GCB font set

GLCDDrawChar( Xposition, Yposition, CharCode )

GLCDDrawString

Print characters on GLCD using GCB font set

GLCDDrawString( Xposition, Yposition, Stringvariable )

Box

Draw a box on the GLCD to a specific size

Box ( Xposition1, Yposition1, Xposition2, Yposition2, [Optional In LineColour as 0 or 1] )

FilledBox

Draw a box on the GLCD to a specific size that is filled with the foreground colour.

FilledBox (Xposition1, Yposition1, Xposition2, Yposition2, [Optional In LineColour 0 or 1] )

Line

Draw a line on the GLCD to a specific length that is filled with the specific attribute.

Line ( Xposition1, Yposition1, Xposition2, Yposition2, [Optional In LineColour 0 or 1] )

PSet

Set a pixel on the GLCD at a specific position that is set with the specific attribute.

PSet(Xposition, Yposition, Pixel Colour 0 or 1)

GLCDWriteByte

Set a byte value to the controller, see the datasheet for usage.

GLCDWriteByte (LCDByte)

GLCDReadByte

Read a byte value from the controller, see the datasheet for usage.

bytevariable = GLCDReadByte

ST7735_[color]

Specify color as a parameter for many GLCD commands

Any color can be defined using a valid hexidecimal word value between 0x0000 to 0xFFFF., see the RGB565 color picker for a wider range of color parameters.

Internally, the generic GLCDRotate command is implemented for this controller by GLCDRotate_ST7735, which handles the four orientations (LANDSCAPE, PORTRAIT, LANDSCAPE_REV, PORTRAIT_REV), swaps GLCDDeviceWidth/GLCDDeviceHeight for the landscape modes, and selects RGB or BGR colour order according to ST7735TABCOLOR. Bytes are sent to the controller via the internal SendCommand_ST7735 helper (hardware SPI, or a bit-banged software path when ST7735_HardwareSPI is not defined). Both are internal implementation routines — use the public GLCDRotate command rather than calling either directly.

For a ST7735 datasheet, please refer here.

For a ST7735R datasheet, please refer here.

Example:

    ;Chip Settings
    #chip 16F1937,32
    #config MCLRE_ON

    #include <glcd.h>

    'Defines for ST7735
    #define GLCD_TYPE GLCD_TYPE_ST7735R
    'Pin mappings for ST7735
    #define GLCD_DC porta.0
    #define GLCD_CS porta.1
    #define GLCD_RESET porta.2
    #define GLCD_DI porta.3
    #define GLCD_DO porta.4
    #define GLCD_SCK porta.5

    GLCDPrint(0, 0, "Test of the ST7735 Device")          ' <<< the GLCDPrint instruction
    end

Key line: GLCDPrint(0, 0, "Test of the ST7735 Device") — once the SPI pins and ST7735TABCOLOR are correctly set for the fitted panel, drawing commands like GLCDPrint behave the same as on any other GCBASIC-supported GLCD.

See Also:

  • GLCDCLS — clearing the display
  • GLCDDrawChar — drawing a single character
  • GLCDPrint — printing a value at a specific location, as used above
  • GLCDReadByte / GLCDWriteByte — low-level byte access, for expert use
  • GLCDRotate — rotating the display, implemented for this controller by the internal GLCDRotate_ST7735 routine
  • Pset — setting a single pixel

Supported in <GLCD.H>