Interfacing PIC18F46K22 MCU with ST7735 TFT – Rotation Test Example

This is another example that shows how to interface PIC18F46K22 microcontroller with ST7735 SPI TFT display. In this project I’m going to do a simple rotation test to the ST7735 TFT display.
The last project is a graphics test of the ST7735 TFT display, project link is below:
Interfacing PIC18F46K22 MCU with ST7735 TFT – Graphics Test Example

CCS C Compiler is used in this project.

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

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) which is initialized with the following line:

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

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

Full CCS C 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.