Interfacing PIC18F46K22 MCU with ST7735 TFT – Graphics Test Example

This post shows how to interface Microchip PIC18F46K22 8-bit microcontroller with ST7735 TFT display (128×160 pixel resolution).
The ST7735 TFT display is a color display that uses SPI protocol, it’s low cost and easy to use.
This module works with 3.3V only, connecting it directly to a 5V system will not work and may damage its controller circuit!
CCS C Compiler is used in this project.

The display which is used in this project is shown below (face):

ST7735S SPI TFT display face

and the back of the display module:

ST7735S SPI TFT display back

As shown in the back of the display module there is the AMS1117 3V3 voltage regulator, it’s used to supply the display controller circuit with 3.3V from an input supply of 5V (because it does work with 3.3V only).
Also, we can disuse the built-in voltage regulator (AMS1117 3V3) if we already have a regulated voltage source of 3.3V, here we should close (solder) jumper J1 (red ellipse).

Project Hardware Required:

  • PIC18F46K22 microcontroller   —->  datasheet
  • ST7735 TFT display module (ST7735R or ST7735S)
  • 5 x 1k ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires

PIC18F46K22 with ST7735S color display graphics test

Interfacing PIC18F46K22 MCU with ST7735 TFT circuit:
Project circuit schematic diagram is shown below.

The ST7735S shown in project circuit diagram has 8 pins: (from right to left): RST (reset), CS (chip select), DC (or D/C: data/command), DIN (data in), CLK (clock), VCC, BL (back light) and Gnd (ground).

The ST7735 display module is supplied with 5V. GND pin is connected to circuit ground, VCC and BL pins are connected to circuit +5V.

PIC18F46K22 ST7735 SPI TFT display circuit

All the grounded terminals are connected together.

The PIC18F46K22 microcontroller has 2 hardware SPI modules (MSSP1 and MSSP2 modules).
In this project SPI1 module is used with SCK1 on pin RC3 (#18) and SDO1 (MOSI) on pin RC5 (#24). SCK1 and SDO1 pins of the PIC18F46K22 MCU are respectively connected to CLK and DIN pins of the ST7735S display module.
SCK: Serial Clock.
SDO: Serial Data-Out, synonym for MOSI.
MOSI: Master-Out Slave-In.

All PIC18F46K22 MCU output pins are 5V, connecting a 5V pin directly to the ST7735 display board may damage its controller circuit. To avoid that, I connected each control line of the display to the microcontroller through 1k ohm resistor.

So, the ST7735 display is connected to the PIC18F46K22 MCU as follows (each one through 1k resistor):
RST pin is connected to pin RD0 (#19),
CS pin is connected to pin RD1 (#20),
D/C pin is connected to pin RD2 (#21),
DIN pin is connected to pin RC5 (#24),
CLK pin is connected to pin RC3 (#18).

In this project the PIC18F46K22 microcontroller runs with its internal oscillator @ 32 MHz, MCLR pin is configured as an input pin.

Interfacing PIC18F46K22 MCU with ST7735 TFT C code:
The following C code is for CCS C compiler, it was tested with versions 5.051 and 5.083.

To be able to compile project C code with no error, 2 libraries are required:
The first library is a driver for the ST7735 TFT display, its full name (with extension) is ST7735.c, download link is below:
ST7735 TFT display library for CCS C compiler

The second library is graphics library, its full name is GFX_Library.c, download link is the one below:
Graphics library for CCS C compiler

after the download of the 2 library files, add both of them to the project folder.

The 2 library files are included in the main code as shown below:

As mentioned above, the ST7735 TFT is connected to PIC18F46K22 microcontroller SPI1 module pins (SCK1 and SDO1) which is initialized with the following line:

The other pins: RST, CS and DC are defined as shown below:

Full CCS C code:

My protoboad circuit of the project is shown in this video:

Proteus simulation:
We can simulate this project with Proteus ISIS software as shown in the following video:

Proteus simulation file download link is below, use version 8.6 or higher to open it:
PIC18F46K22 + ST7735 TFT Proteus simulation

Related Projects:
Interfacing PIC18F46K22 MCU with ST7735 TFT – Rotation Test Example

1 thought on “Interfacing PIC18F46K22 MCU with ST7735 TFT – Graphics Test Example”

  1. Hello. fantastic code that works in CCS. Now, I am trying to adapt your code to a PIC in XC8. But, I don’t know what means “#define ST7735_SPI_Write(x) SPI_XFER(ST7735, x)” exactly. Do you have some info about ? Regards and thanks. Vincent

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top