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

This is another PIC project that shows how to interface PIC18F46K22 microcontroller with ST7735 TFT display. In this post I’m going to do a simple rotation test to the ST7735 TFT display.
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 last project is a graphics test of the ST7735 TFT display, project link is below:
PIC MCU with ST7735 TFT – Graphics Test Example | mikroC Projects

Project Hardware Required:

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

PIC18F46K22 with ST7735S TFT display rotation 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 TFT color display

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 TFT 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).

The display module is supplied with 5V between pins VCC and GND. BL pin also is connected to +5V.
The display module contains AMS1117 3V3 voltage regulator which steps down the 5V into 3.3V and then supplies the display controller.

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.

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 TFT display are initialized as shown below:

The push button is connected to pin RB0 (#33), it’s defined in the C code as:

Rest of code is described through comments.

Full mikroC code:

My test hardware circuit is shown in the video below:

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

Leave a Reply

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