ST7735R SPI TFT driver for mikroC PRO for PIC

This is a small library (driver) of the ST7735R (ST7735S) SPI TFT display (1.8″ , 128×160 Pixel resolution) for mikroC PRO for PIC compiler. With this library we can easily connect the ST7735R TFT display with any PIC microcontroller with sufficient RAM and ROM which depends on the project.
This library is based on the Adafruit TFT library for Arduino. This library works with any PIC microcontroller with or without hardware SPI module (hardware SPI is faster than software SPI).
Basically the ST7735R TFT display has 5 control lines: RST (Reset, active low), CS (Chip Select, active low), DC (Data/Command), SDA (Serial Data Line) and SCL (Serial Clock Line).

Some images of the ST7735R TFT module:

Using the ST7735 TFT library:
The ST7735 SPI TFT library can work with hardware SPI or software SPI. The hardware SPI is more faster than the software SPI. If you want to use your microcontroller hardware SPI module the following variables must be defined:

Examples:
The following ST7735 SPI TFT display is connected to microcontroller hardware SPI module pins, CS is connected to RD0 and DC is connected to RD1:#define TFT_SPI_HARDWARE
#define TFT_CS at RD0_bit;
#define TFT_DC at RD1_bit;
#define TFT_CS_Direction at TRISD0_bit;
#define TFT_DC_Direction at TRISD1_bit;

The following ST7735 SPI TFT is connected to the microcontroller where software SPI is used:#define TFT_CS at RD0_bit;
#define TFT_DC at RD1_bit;
#define TFT_CLK at RD2_bit;
#define TFT_DATA at RD3_bit;#define TFT_CS_Direction at TRISD0_bit;
#define TFT_DC_Direction at TRISD1_bit;
#define TFT_CLK_Direction at TRISD2_bit;
#define TFT_DATA_Direction at TRISD3_bit;

ST7735_TFT_Init(): initializes the ST7735 module, must be called before any other function.
fillScreen: fills the whole screen with a given color.drawFastVLine: draws a vertical line starting at (x, y) with height h.drawFastHLine: draws a horizontal line starting at (x, y) with width w.drawCircle: draws a circle where (x0, y0) are center coordinates an r is circle radius.drawRect: draws rectangle at (x,y) where h is height and w is width of the rectangle.fillRect: fills a rectangle starting from coordinates (x, y) with width of w and height of h.drawLine: draws a line from (x0, y0) to (x1, y1).drawRoundRect: draws a rectangle with rounded edges. h: height, w:width, r: radius of the rounded edges.drawTriangle: draws a triangle of coordinates (x0, y0), (x1, y1) and (x2, y2).drawChar: writes a char (c) on the TFT at coordinates (x, y). size: char size.drawText: Writes text (*text) on the TFT at coordinates (x, y). size: text size.setTextWrap: turn on or off wrap of the text (1 or 0).invertDisplay: invert display colors (1 or 0).setScrollDefinition: This command defines the Vertical Scrolling Area of the display where:
top_fix_height: describes the Top Fixed Area,
bottom_fix_height: describes the Bottom Fixed Area and
_scroll_direction: is scroll direction (0 for top to bottom and 1 for bottom to top).VerticalScroll: This command is used together with the last command. These two commands describe the scrolling area and the scrolling mode.NormalDisplay(): returns the TFT display to its normal state for example exit from scrolling mode.Color565: converts 24-bit color format into 16-bit format and returns the result.

Library download:
ST7735R library source file can be downloaded from the link below, library file full name is ‘ST7735_TFT.C’ . Adding this library to the project is so easy, just put the library file (ST7735_TFT.C) in the project folder and add #include <ST7735_TFT.c> to project source file.