This post shows how to make the ST7735 SPI TFT display vertically scrolling using PIC18F4550 microcontroller and CCS PIC C compiler.
The CCS C codes below are tested with versions 4.068 and 5.051.
For this project we need a driver for the ST7735 TFT display which can be found in the following post:
ST7735 SPI TFT Display Driver for CCS PIC C compiler
And the following post show how to interface ST7735 TFT display with PIC18F4550 microcontroller:
Interfacing PIC18F4550 with 1.8″ TFT display
Abbreviations:
TFT: Thin-Film Transistor.
LCD: Liquid Crystal Display.
SPI: Serial Peripheral Interface.
MOSI: Master Out Slave In.
MISO: Master In Slave Out.
SCK: Serial Clock
DIY: Do-It-Yourself
ST7735 TFT Vertical Scrolling with PIC18F4550 circuit:
The circuit schematic of all our examples below is as shown in the following image.
Hardware Required:
- PIC18F4550 microcontroller —> datasheet
- ST7735 TFT display
- 8MHz crystal oscillator
- 2 x 22pf ceramic capacitor
- 5 x 1k ohm resistor
- Bread board & jumper wires
- 5V source
- PIC Microcontroller programmer (PICkit 3, PICkit 4…)
PIC18F4550 MCLR pin function is disabled in the code.
ST7735 TFT top to bottom and bottom to top vertical scrolling:
To make the TFT scrolls first we have to set the window that we would like to scroll, this is done using the following command:
setScrollDefinition(TFA, BFA, _scroll_direction);
Where TFA is top fixed area and BFA is bottom fixed area (in pixel)
_scroll_direction can be 0 or 1( 0 for to to bottom and 1 for bottom to top).
Example:
setScrollDefinition(40, 20, 1);
That makes the TFT display area from pixel 40 to pixel 140 (160 – 20) scrolls from bottom to top.
If TFA = BFA = 0 the whole screen is selected to scroll as shown in the example below.
Another command is required to make the TFT scrolls which is:
VerticalScroll(_vsp);
Where _vsp is an unsigned int8 number which controls the level of the scroll.
Example 2:
The following example shows how to make TFT scrolls from top to bottom:
Here TFT = BFA = 0.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /* PIC18F4550 microcontroller with ST7735R SPI TFT vertical scrolling example CCS C code ST7735 TFT display driver for CCS PIC C compiler is required https://simple-circuit.com/ */ #define top_to_bottom 0 #define bottom_to_top 1 #define TFA 0 // Top Fixed Area 0 pixel #define BFA 0 // Bottom Fixed Area 0 pixel // TFT module connections #define TFT_CS PIN_D1 #define TFT_DC PIN_D0 #define TFT_SPI_HARDWARE // End TFT module connections #include <18F4550.h> #fuses NOMCLR HSPLL PLL2 CPUDIV1 #use delay(clock = 48000000) #include <ST7735_TFT.c> #use fast_io(D) char *txt = "ST7735 TFT vertical scrolling"; unsigned int8 scroll = 0; void main(){ TFT_BlackTab_Initialize(); fillScreen(ST7735_BLACK); drawtext(0, 5, txt, ST7735_WHITE, ST7735_BLACK, 1); strcpy (txt, "Hello World!"); drawtext(28, 100, txt, ST7735_CYAN, ST7735_BLACK, 1); setScrollDefinition(TFA, BFA, top_to_bottom); while(TRUE){ VerticalScroll(scroll + TFA); scroll++; if(scroll >= (_height - TFA - BFA)) scroll = 0; delay_ms(100); } } |
ST7735 TFT Vertical Scrolling with PIC18F4550 video:
The following video shows the result of top to bottom scrolling of the ST7735 display.
If the line: setScrollDefinition(TFA, BFA, top_to_bottom); changed to:
setScrollDefinition(TFA, BFA, bottom to top);
then we will see the following result:
ST7735 TFT Vertical Scrolling example:
This is an other example for ST7735 TFT vertical scrolling.
In this example the scrolling direction is from bottom to top.
After every scrolling process the microcontroller deletes the data that may appear in the bottom of the screen by drawing a horizontal line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | /* PIC18F4550 microcontroller with ST7735R SPI TFT vertical scrolling example CCS C code ST7735 TFT display driver for CCS PIC C compiler is required https://simple-circuit.com/ */ #define top_to_bottom 0 #define bottom_to_top 1 #define TFA 30 // Top Fixed Area 30 pixel #define BFA 0 // Bottom Fixed Area 0 pixel // TFT module connections #define TFT_CS PIN_D1 #define TFT_DC PIN_D0 #define TFT_SPI_HARDWARE // End TFT module connections #include <18F4550.h> #fuses NOMCLR HSPLL PLL2 CPUDIV1 #use delay(clock = 48000000) #include <ST7735_TFT.c> #use fast_io(D) char *txt = "ST7735 TFT vertical scrolling"; char *nbr = " "; unsigned int8 i, scroll = 0; unsigned int16 number = 1; void main(){ TFT_BlackTab_Initialize(); fillScreen(ST7735_BLACK); drawtext(0, 5, txt, ST7735_WHITE, ST7735_BLACK, 1); strcpy (txt, "Line:"); for(i = 0; i < 13; i++){ drawtext(0, i * 10 + 30, txt, ST7735_YELLOW, ST7735_BLACK, 1); sprintf(nbr,"%Lu",number); drawtext(40, i * 10 + 30, nbr, ST7735_GREEN, ST7735_BLACK, 1); number++; delay_ms(500);} setScrollDefinition(TFA, BFA, bottom_to_top); while(TRUE){ for(i = 0; i < 10; i++){ VerticalScroll(scroll + TFA); drawFastHLine(0, scroll + TFA, _width, ST7735_BLACK); // Delete lines which may appear in bottom of TFT scroll++; delay_ms(100); if(scroll >= (_height - TFA)) scroll = 0; } sprintf(nbr,"%Lu",number); if(scroll == 0){ drawtext(0, 150, txt, ST7735_YELLOW, ST7735_BLACK, 1); drawtext(40, 150, nbr, ST7735_GREEN, ST7735_BLACK, 1); } else{ drawtext(0, 20 + scroll, txt, ST7735_YELLOW, ST7735_BLACK, 1); drawtext(40, 20 + scroll, nbr, ST7735_GREEN, ST7735_BLACK, 1); } number++; } } |
Example video:
The video below shows example result.
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.