PIC MCU with ST7735 TFT – Graphics Test Example | mikroC Projects

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!
The compiler used in this project is mikroElektronika mikroC PRO for PIC.
SPI: Serial Peripheral Interface.

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 @ 16 MHz, MCLR pin is configured as an input pin.

Interfacing PIC18F46K22 MCU with ST7735 TFT C code:
The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.6.0.

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 mikroC compiler

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

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

The default connection setting of the ST7735 library is hardware SPI1 module which is in our project MSSP1 module. Instead of hardware SPI1 module, mikroC software SPI library or hardware SPI2 module can be used.
To use mikroC software library, define the following line before #include “ST7735.c”:
#define ST7735_SOFT_SPI
In software SPI we’ve to configure the pins used (MISO, MOSI and SCK) by mikroC software SPI library as shown in the help file.
Also the configuration should be initialized in the main code (always before initializing the display) with this line:
Soft_SPI_Init();
The clock frequency of the software SPI library is fixed to 20 kHz (slow!).

If the display module is connected to hardware SPI2 (MSSP2 module) then we’ve to define this line:
#define ST7735_HARD_SPI2
and hardware SPI2 module must be initialized before the initialization of the ST7735 TFT display (for example SPI2_Init();).

Hints:
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). The other pins: RST, CS and DC are defined as shown below:

Hardware SPI1 module of the PIC18F46K22 mcu and the ST7735 display are initialized as shown below:

Rest of code is described through comments.

Full mikroC 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:
PIC MCU with ST7735 TFT – Rotation Test Example | mikroC Projects


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

2 thoughts on “PIC MCU with ST7735 TFT – Graphics Test Example | mikroC Projects”

  1. Hello Master, have a good time.
    I have the same problem, thank you for your help.( HI TEACHER. I HAVE TRIED TO MAKE THIS PROGRAM WORK BUT IT HAS NOT WORKED. THERE ARE MANY ERRORS THERE ARE NO DEFINED DATA, CS, ETC. COULD YOU PROVIDE ME WITH A COMPLETE PROJECT OF THIS BOOKSTORE EXAMPLE? I HAVE BEEN WORKING WITH MIKRO C RELATIVELY LITTLE AND AS FAR AS I KNOW, I HAVE BEEN ADDING THE BOOKSTORKS CORRECTLY. I AM LOOKING FORWARD TO YOUR RESPONSE.)

  2. HI TEACHER. I HAVE TRIED TO MAKE THIS PROGRAM WORK BUT IT HAS NOT WORKED. THERE ARE MANY ERRORS THERE ARE NO DEFINED DATA, CS, ETC. COULD YOU PROVIDE ME WITH A COMPLETE PROJECT OF THIS BOOKSTORE EXAMPLE? I HAVE BEEN WORKING WITH MIKROC RELATIVELY LITTLE AND AS FAR AS I KNOW, I HAVE BEEN ADDING THE BOOKSTORKS CORRECTLY. I AM LOOKING FORWARD TO YOUR RESPONSE. [email protected]

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