Experimenting with ST7735 1.8-inch 128×160 color LCD on a PIC microcontroller

5.00 avg. rating (94% score) - 1 vote

This tiny 1.8-inch LCD module is the second color LCD that I successfully attempted (the first is the Nokia 3510i LCD). The breakout board which I purchased from eBay also comes with an SD card socket:

The pinout for the board is as follows, inclusive of the SD card connections:
1.  GND

2.  VCC 
3.  NC
4.  NC
5.  NC
7.  LCD A0 (R/S)
10. LCD CS
11. SD SCK
14. SD CS
15. LED+
16. LED-

Interface via SPI

This LCD controller, ST7735, uses SPI for communication and requires just 5 data lines, namely RESET, A0, SDA, SCK and CS. Of particular note is the A0 line, also known as R/S, which indicates whether the bytes being transferred should be interpreted as command or as pixel data. Although SPI communication should preferably be done using the hardware SPI module (there are two on my PIC24FJ64GA002) for faster display speed, it can also be done via bit-banging if hardware SPI is not available. The following function will send a byte via SPI using software:
void write_spi_byte(unsigned char c){
    char x;
        LCD_SCK = 0;
        LCD_SDA = 0;
        if(c & 0x80)
        LCD_SDA = 1;
        LCD_SCK = 1;
        c <<= 1;

I converted the Adafruit’s Arduino library for this LCD to compile under Microchip C30 compiler for my PIC24FJ64GA002 and the LCD is able to draw some graphics nicely:
Using the bundled SD card socket and Microchip MDD library, together with my custom 5×7 font, I was able to display some SD card information on the LCD:
The board I purchased has an AMS1117 on-board regulator and expects at least 5V to be supplied to VCC to be able to generate 3.3V for the LCD and SD card to work. I did not know this and supplied 3.3V to VCC initially, only to find out that the SD card worked intermittently while the LCD still worked well. If you have problems with the SD card on this module, check if this is the case.

Setting the color model

The ST7735 controller supports up to 262,144 (218) colors. However, to be able to use 262K colors, for each pixel, 18-bit of data have to be transferred via SPI. Since this increases the complexity. I have decided to stay with 65,536 colors (16-bit) colors, where pixel data can be transferred nicely just by using 2 SPI writes.
In 16-bit color mode, the LCD expects pixel data to be in RGB565 format. The following will convert from the well-known RGB888 (24-bit color) format to RGB565:
#define RGB565(r,g,b) ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)))
An interesting point to note about this LCD is that there seems to be two variants with slightly different behaviors. If your module comes with a black tab, the BLUE and RED byte of each pixel will be swapped, resulting in the wrong color being displayed. If your module has a red or green tab, the byte order for each pixel will be correct.
To fix this issue, you can change the above RGB565 macro to swap the red and blue byte, or you can change the value of the MADCTL register during initialization:

// R and B byte are swapped
// writedata(0xC8);

// normal R G B order


Various bitmaps from my SD card as shown on the LCD:
The C30 source code for this LCD can be downloaded here.
5.00 avg. rating (94% score) - 1 vote


A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

48 thoughts on “Experimenting with ST7735 1.8-inch 128×160 color LCD on a PIC microcontroller

  • January 27, 2014 at 11:32 am

    Is there any possibility to download the full source code? I tried it but it doesn't work :(, maybe the speed from my pic16f1827 is too slow.

    Greg ( fb@synk.at )

  • January 27, 2014 at 11:39 am

    Hi Greg,

    What errors are you encountering with the provided code? Are you able to compile it? Take note that you'll need the custom font (provided in the article as well) for the code to compile, The source code is using software (bit-bang) SPI, or you can also use hardware SPI. The PIC16F1827 has 1 hardware SPI module.

    What SPI speed is your PIC running at? This LCD should work with an SPI speed at 1MHz or above.

    If all fails, refer this https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/Adafruit_ST7735.cpp source code and have a look at the function void Adafruit_ST7735::initB(void). Your LCD may require a slightly different initialization routine, depending on the color of its tab (red, green or blue).

    Let me know if you have any other questions.

  • January 27, 2014 at 9:09 pm

    Hi MD, thanks for you quick response. I have no trouble with your code and I am able to compile it. I took not all from your code because I want only to change the color of the screen and draw two lines. I found already another example on the internet (https://sites.google.com/site/arduinomega2560projects/microchip-pic/level-3/st7735-1-8-tft), when I am using his code and changing the ports, I can see many colorful pixels for a short time but not a line or something like that (his code is using the hardware spi).

    It should be 2 Mhz, because I use the internal oscillator with 8 Mhz. This is my code http://synk.at/testLCD.txt

    I have exactly the same LCD like you.

    Can I see the init of your PIC? Did you change anything?


  • January 27, 2014 at 11:29 pm

    Hi Greg,

    You can first try to write a simple program with a while(1) loop to toggle the pins assigned for this LCD (e.g. LATBbits.LATB1, LATAbits.LATA6) with sufficient delay (e.g. 100ms) in between and see if you can observe a square wave on your oscilloscope, or 2.5V on your multimeter if you do not own an oscilloscope, on each of the output pins. In fact it is a good practice to make sure all output pins you intend to use can be freely controlled from code and all input pins can recognize digital 0 and digital 1 properly before attempting to connect any devices to the PIC.

    In particular, make sure that you are able to control LATAbits.LATA6 freely from code. RA6 a shared pin on the PIC16F1827 so you'll need to set some registers to enable digital input on that pin. At minimum, set TRISA = 0x00 and TRISB = 0x00 for all output pins, and remove SDO1SEL because you're going to use software SPI (as in the code you sent me) and not hardware SPI.

    RA6 is a special pin on this PIC, so your configuration bits (_CONFIG() declaration at the beginning of your code) will needs to be set properly to allow using it as output. Refer to this http://www.microchip.com/forums/m691867.aspx for more details.

    The same applies for other output pins too, make sure that you can set their states from codes. This ensures that the LCD can receive the proper initialization data. If you're using the PICKit for programming, make sure that none of the pins you use for this LCD conflicts with the pins used for the PICKit – that will cause problems.

    The code on the website you sent me is very similar to my codes, except that the author does not set the gamma control (ST7735_GMCTRP1) of the LCD during initialization. As this is optional, both codes should work on your LCD. You can also try between the PORTA/PORTB registers and the LATA/LATB registers and check if there's any different when using the source code provided by that website. In my experience using the latch to write to the port is always better to avoid read-modify-write issues.

    You may find the entire source code for this LCD (and other interesting modules you can play with) here http://toughdev.com/public/pic24f_hobby2.zip designed for the PIC24FJ64GA002 but can be ported to other PIC too. The source code features a terminal via UART which allows you to read a 128×160 24-bit bitmap from the SD card slot and display it on the LCD. It is using software SPI for this LCD (but can be switched to hardware SPI easily). For the PIC initialization (refer to function initIO() in main.c), nothing really special to take note of, except to set the correct TRIS bit to assign the input/output pins.

    Let me know your progress. :)

  • January 29, 2014 at 11:33 am

    Thank you for your detailed help :)! Now its working fine, RA6 was the problem ;)! You are my hero :)!

  • January 29, 2014 at 11:35 am

    Hi Greg,

    Glad you got it working. Enjoy playing with the LCD!

  • September 6, 2014 at 2:32 pm

    Thanks for this great tutorial, I have been a PIC fan for a long time. Just decided I wanted a graphics and touch screen display for a project. looked around purchased a few displays on E bay. found this site and your source code easy to understand.Got me up and running. Thanks again. Rod

  • September 7, 2014 at 9:32 am

    Glad you find the source code useful. :) I am also a PIC fan and electronics hobbyist too (my full time job is a software professional). Love the PIC- small but otherwise powerful microcontrollers.

  • September 9, 2014 at 7:44 am

    I am only a hobby programmer. so I need to ask. as this is a pic blog. How do I erase a character before drawing another on top. Basically I need to create animation its the most basic function but its eluding me on this display.
    In the PC we called it double buffering. Well it was last time I programmed a computer. Could you point me in the direction of some code. for this display.
    Is there a way to write to the ram and display it after the write.

  • September 9, 2014 at 10:31 am

    Hi Rodney,

    For simple clearing of the screen and drawing new text/graphics over, you can use ST7735_fillRect function, provided in my library. Just fill the area you want to draw with a color that is the same as the background color. This will effectively clear that area of the display and you can draw the new contents over.

    However, to create animation on this display, you would need to use what you've already described in your question, which is a double buffer. On a PC or a PIC with a large enough memory, you can try to declare an array (~40K for this LCD) which holds on the pixel color information. For any drawing, update that array first without affecting the LCD. Once the drawing is finalized, create another method which will write the entire array contents to the LCD. At a fast enough SPI speed (32 MHz for example), the transfer of 40K of data would finish in a fraction of seconds and there would (hopefully) be no visible effects on the LCD, resulting in a smooth animation. You can perhaps do this on a PIC with large enough RAM (PIC32 or DSPIC for example).

    You can check the datasheet of the ST7735 here ftp://imall.iteadstudio.com/IM120419001_ITDB02_1.8SP/DS_ST7735.pdf
    I have read through the datasheet and apparently there is no internal support for double buffering on this LCD controller. There is some information in section 9.11 (Tearing Effect Output Line), 9.11.3 and 9.11.4 on pages 62-65 which describes how the LCD handles memory writes that are faster or slower than its internal update speed. You can see from the graphics illustration which shows the characters B or A being partially drawn – implying that there is no internal buffer on this LCD controller.

    You may also find the command list for this LCD on page 77 of the datasheet useful. Refer to this post http://fabienroyer.wordpress.com/2011/05/29/driving-an-adafruit-st7735-tft-display-with-a-netduino/ on a similar attempt at using software-buffering on this LCD.

  • September 10, 2014 at 6:41 am

    Again Thank you. Do you have a donation button. If you don't you should have.
    Even with the internet being a paradise of information sometimes its still just works to ask..
    Your explanation was spot on. Being in new tech sometimes its hard to know if what you are looking for is there or you just don't recognize it when you see it.
    My PIC of choice for this project . 32MX460 512 . So I went with your first option to write the back ground color over the text and then redraw the new text on top. I needed a 6 digit decimal hi speed counter for a frequency reading project with graphics support.
    I am going to give the array dump suggestion a try, that sounds like fun. The source code you provided with this Blog is very nicely written its clean easy to read and straight to the point, it integrated so well. Now to get the SD card reader going that looks a bit harder.
    cheers Rod

  • September 10, 2014 at 10:43 am

    Hi Rodney,

    I am happy to hear that my suggestions and the library work well for your project, a PIC-based frequency counter project! This makes me feel more excited and motivated to continue to maintain this blog to help other people with similar interests.

    I love the PIC32 too – it can run at at much faster speed compared with PIC24 and has more RAM to play. Unfortunately most PIC32 devices are in small packaging (TSSOP, SOIC, etc) and not the more hobbyist-friendly PDIP packaging. I have in my collection here the PIC32MX250F128B – one of the few PIC32s available in PDIP – and plan to play around with it soon, perhaps by attempting to display graphics on this ST7735 LCD using double-buffering and see the results.

    For interfacing with the SD card, you can use the Microchip Memory Disk Drive (MDD) library. It uses the hardware SPI module and contains everything you need to read SD card up to 2GB, in FAT12, FAT16 and FAT32 format. You simply need to change the HardwareProfile.h declaration to match your connections. Methods to read/write files on the SD card are something like fsfread, fsfwrite, fsfclose – similar to standard C functions so it's very easy to use.

    You can refer to my other article, http://www.toughdev.com/2014/03/using-picojpeg-library-on-pic24-with.html , which uses the MDD library to read JPEG file from an SD card and display on the ILI9341 LCD.

    Keep me updated on your progress.

  • September 19, 2014 at 10:09 pm

    Hi MD
    I now have the SD card supporting my project. I must say when I looked at the MDD library and the code for the card I was think What am I Going to now. They seem to write it to support there development kits and there was all this other code I did not need. The UART had me confused for a while. Once again your example code was very helpful, I am very happy to be moving forward will my project and to now have graphics and SD card to my skill set. Still plenty to do. cheers Rod

  • September 20, 2014 at 10:02 am

    Hi Rodney,

    Glad to hear you've made good progress on the SD card interfacing in your project. Let me know if you need any other help. :)

  • November 5, 2014 at 6:25 pm

    Hi MD
    I have been working on all thing PIC and the related. SD cards and TFT displays
    I have tested a quite a few different displays with a verity of controllers, Having good fun and learning heaps. You said ask if I had a question.
    I want to look a program I have in a PIC processor. The short question is can I disassemble a PIC hex file back to source code .
    I want to look at an algorithm that's in a chip I have. I can read the chip its not locked.
    I remember you saying you disassembled some old dos games.

  • November 5, 2014 at 10:25 pm

    Hi Rodney,

    Glad you're having fun with the PIC and LCD displays. :)

    If the code protection bit (CP) was not set in the configuration register of the PIC during programming, you'll be able to read the contents of the program memory back into a HEX file. From there it is possible to disassemble the HEX file back into assembly code. The few methods I know of are below:

    1. Start MPLAB 8.92 and open File>Import and select the HEX file which you've read back from the PIC. The output window should say that the Hex file is loaded successfully. After that, select View > Program Memory. A new window should open with several tabs at the bottom (OpCode Hex, Machine, Symbolic, etc.). Select the Symbolic tab and you'll see the disassemble listing of the HEX file. The first line should be something like "goto 0x200" which shows you where in memory the execution of the program should start.
    2. Use the free tool PICDISASM downloadable from http://www.hagi-online.org/picmicro/picdisasm_en.html – this supports PIC16 and lower. PIC24, PIC32 and dsPIC are not supported.
    3. Use the PIC disassembler downloadable from http://www.eolis-software.co.uk/picdisassembler24.shtml which supports most PIC devices including PIC24 and PIC32. However this tool is not free – a trial version can be downloaded for evaluation purposes.

    As for decompiling the HEX file back to the original source code – that is not possible as far as I know as much of the information required to create the original code is lost during compilation. There are some such tools for the x86 PC which attempts to construct a human-readable C code from the assembly listing but the quality of the generated C code may vary – sometimes reading the generated C code is harder then reading the disassembly! I do not know of such a tool for the PIC, presumably because its possible usage is limited and no-one has attempted yet.

    In my experience, with just some basic assembly knowledge and some understanding on the connections (e.g. where each pin is connected and what it is for), you can still understand what the program is doing by reading the assembly listing – as most of what the code is doing will possibly be just toggling output pins or reading input :) Other more complex logic such as interrupt may be harder to decipher. Try to recreate the complete ASM file from the disassemble listing (this requires figuring out the original configuration bits), compile it under MPASM and run it to debug. I have tried that before – quite tough but it's fun and a good learning exercise.

    Let me know if you manage to figure out the algorithm that you wanted.

  • January 9, 2015 at 4:57 pm


    Does this support the PIC32?

  • January 9, 2015 at 4:59 pm


    Yes, the code should be able to be ported to the PIC32 with only major changes. let me know if you encounter any issues.

  • April 12, 2015 at 3:50 am

    Thank you for the source to get me started on this GLCD. Much appreciated !

  • May 8, 2015 at 5:15 pm

    Thanks for your work! I would like to know is about the wiring. We are developing your code to PIC32 and I have many doubts about how to connect PIC32 to st7735 display.

  • May 8, 2015 at 11:57 pm

    Well in fact I tried to buld the project With MPLAB 8.9.2 and I have many errors. libpic30.h is missed, stddef.h too… it’s normal?

  • May 9, 2015 at 12:01 am

    For the connections you will need to connect the RESET , A0 (R/S), SDA, SCK, LCD CS pins of the LCD to your PIC. Exactly which pins on the PIC depend on your configuration, whether using software or hardware SPI, etc.

    Having many errors when compiling is not normal – it indicates compiler configuration errors. Try to check your C30 configuration. Take note that the code is meant for a PIC24, not a PIC32.

  • May 9, 2015 at 3:03 pm

    Thanks for the reply!
    The wiring out of LCD it’s clear to me, I don’t know how to configure (using the code I think) the configuration connect it to my PIC.I mean, RESET pin on LCD to X pin to PIC. How can I set this X pin in my PIC (in this project of course)?

    I’m using C32 to my PIC32 not C30. In fact, I tried to compile using a PIC24 using Explorer 16 board and it happened another errors.

    Now, after too many hours, I get this output after build:
    Clean: Deleting intermediary and output files.
    Clean: Done.
    Executing: “C:\Program Files\Microchip\MPLAB C32 Suite\bin\pic32-gcc.exe” -mprocessor=32MX795F512L -x c -c “main.c” -o”main.o” -MMD -MF”main.d” -D__DEBUG -g
    In file included from main.c:2:0:
    delay.h:1:22: fatal error: libpic30.h: No such file or directory
    compilation terminated.
    Halting build on first failure as requested.
    Debug build of project `C:\Users\FolderX\Desktop\pic24f_hobby2\project.mcp’ failed.
    Language tool versions: pic32-as.exe v2.02, pic32-gcc.exe v2.02, pic32-ld.exe v2.02, pic32-ar.exe v2.02
    Preprocessor symbol `__DEBUG’ is defined.
    Fri May 08 08:58:07 2015

    It happens two things.
    libpic30.h include doesn’t exist. I have a doubt about if we need to use libpic30 or another because I’m using PIC32. Anyway, MPLAB should find this include.

    On the other hand, language tool versions. I changed my PIC to the right model, I reinstalled MPLAB, I updated C32 to 1.3.4, I selected the rigth gcc.exe C32 in Project->Select language tools locations -> C32 -> pic32-gcc.exe… I don’t know what to try else.

    Thanks a lot,

  • May 9, 2015 at 3:21 pm


    The RESET pin should be connected to any output pin on the PIC and the corresponding connection declaration in st7735.h should be adjusted accordingly. You would only need to bundle st7735.h and st7735.c in your project and check the #include to make sure you’re only including the files that you need – the source code provided is part of another project and may contain other unnecessary includes.

    From your replies it seems as if you’re new to interfacing peripherals to the PIC. Usually the correct approach is to try to write simple program to toggle pins first, and make sure that all pins that you want to use to connect to the LCD can be toggled from your code. Make sure that the program to toggle the pins can be compiled and run successfully before you attempt any other advanced features – otherwise you’ll be confused with the multiple errors.

    With regards to the libpic30.h error, I can only says it’s due to compiler configuration error, perhaps try a fresh install?

    Let me know how it goes.

  • May 9, 2015 at 5:15 pm

    Hi MD,

    First of all, thanks for your time. You are very kindly.I’m trying to do my best with this project and, yes, I’m a newbie with this things.

    After fight hardly, and follow your advise I’m starting for the beginning and the most simple thing. Even, I’m trying to build this project with PIC24 (I think it should be easier).
    But, it appears some errors as before.

    /* Various Write Protect functions diabled */

    /* Enable Primary Clock with PLL; Start with user selected clock source */
    /* Device has onboard unconfigurable brown-own reset if voltage is below certain threshold */

    _FOSCSEL(FNOSC_FRCPLL & IESO_OFF) // Internal Fst RC with PLL, then start with user-selected oscillator source
    _FOSC(POSCMD_NONE & OSCIOFNC_ON & IOL1WAY_OFF) // Primary Oscillator Disabled, Disable Clock Output at RA3 (Pin 10),
    _FWDT(FWDTEN_OFF) // Watch Dog Timer is disabled
    _FPOR(FPWRT_PWR128) // Power on Reset time is 128 ms

    // count of the 256Hz timer use for duration counting
    unsigned long timerCount = 0;

    main.c:21: error: syntax error before ‘_FSS’
    main.c:22: error: syntax error before ‘_FGS’
    main.c:28: error: syntax error before ‘&’ token
    main.c:31: error: syntax error before ‘_FICD’
    main.c:31: error: syntax error before ‘&’ token
    main.c:34: warning: return type defaults to ‘int’
    main.c: In function ‘_FICD':
    main.c:34: error: parameter ‘timerCount’ is initialized
    main.c:37: error: syntax error before ‘{‘ token
    main.c:85: error: parameter ‘cardInfo’ is initialized
    main.c:87: error: syntax error before ‘sprintf’
    main.c:107: error: parameter ‘filesCount’ is initialized

    How can is possible to fail in that statement?

    Thanks for everything,

  • May 9, 2015 at 5:24 pm

    Hi there,

    Where did you get the above source code from? The link in the article only provides 2 source files – st7735.h and st7735.c – supposed to be used with your own project.

    Your errors indicate that the compiler does not understand the declarations of the configuration bits – have you specified the correct PIC family?

    Again, don’t try something so complicated. Just use MPLAB to create a new PIC project targeting your PIC device, add a main.c with only a few lines to enable the oscillator and toggle a few pins. You can try to look for various online tutorials to get that working first before attempting something more sophisticated

  • May 9, 2015 at 6:24 pm

    Hi MD,

    You posted above (Sun. Jan 26, 2014) form github I guess. It’s a zip with all libraries and all content project.

    And yes, PIC is right selected.

  • May 9, 2015 at 7:02 pm


    The link I provided to the other reader back in Jan 2014 contained the entire source code for my PIC test project, which also include codes for other peripherals (SD cards, sensors, etc). It was provided since he asked for it.

    You do not need that, especially if you are new to PIC programming. Just start clean with a flash LED program and try to improve from then. To make the LCD work you only need the st7735.zip file downloaded from the article, with only some minor modifications once you’ve settled your compiler and connections,

  • May 12, 2015 at 6:59 pm

    Well, I’m trying to play with control LED’s, in fact, I’m connecting PIC32 to Expansion Board I/O. I have only two questions If you can answer me:
    -The Adafruit TFT 1,44″ has Vin,3v3,GND,SCK,S0,SI,TCS,RST,D/C,CCS,LIte. In connection you say it must be connected RESET,RS,CS,SCK,SDO.
    It’s possible to use it? Both are 4-SPI compatible but I don’t identify RS,CS and SDO in 1,44″ Adafruit board.

    -LAT/PORT A and B are clear, I’m doing same test with LED’s using port A. But, in the source code (s7735.h) it needs use LATB7 and LATB6. Which are this ports?
    I’m trying to find them in schematic Expansion Board and I can’t.

    Best regards amd thanks,

  • May 12, 2015 at 9:28 pm


    RS or RST is short for Reset, CS or CCS is short for Chip Select. SDO/SO and SDI/SI are short SPI Data Out and SPI Data In respectively. Refer to this for the possible naming convention of the SPI protocol: http://www.eeherald.com/section/design-guide/esmod12.html

    In my connections I use LATB6 for the SPI Data and LATB7 for the SPI Clock pins (only if software SPI is used). If you are using software SPI (e.g. bitbanging) for the interface, which is the default behaviour currently implemented in st7735.c, you can just assign these 2 pins to any other appropriate pins on other ports which are still available on your Explorer board.

    LATB6 and LATB7 are initially peripherals pin on this board (RP6, RP7) which can have different functionalities (UART, I2C, SPI, etc.) depending on your code. The reason you did not see LATB6 and LATB7 or your explorer board schematics is probably because they have been assigned to specific functionality, so their original names are not shown.

  • September 5, 2015 at 9:49 pm

    Hi MD,
    I have successfully ported code to PIC18F and 16F except SD, bmp support since these devices are not supported Microchip lib in XC.
    One problem is that 90 rotation is not work and it rotate 180 deg. I have tested,
    It rotated 180 deg and cannot change portrait to landscape.
    I checked my code again and again and no clue. Pls any advise and have your code tested rotation?

  • September 7, 2015 at 1:05 pm

    Hi oakkar7,

    Sorry for the late reply and glad you manage to port the code!

    To be honest I have not tried the rotation feature on this LCD module before, I simply swap/manipulate the pixel coordinates when drawing my bitmap to simulate the rotation effects.

    Just a suggestion, have you checked the datasheet and look for the specs on the MADCTL Memory Address Access Control 0x36 (36h) register? This register controls the rotation degrees, among other things. It was possible that the rotation feature was not property tested when I released the code for this LCD. The details can be found on page 110 of the datasheet, section 10.1.26

    Let me know how it goes.

  • May 6, 2016 at 8:35 pm

    I purchased a board with the same controller and similar pin outs. The seller claims that it's a touch display. Based on what you know about the module, could this be true? How would you connect the touch controls.

  • May 6, 2016 at 8:36 pm

    I purchased a board with the same controller and similar pin outs. The seller claims that it's a touch display. Based on what you know about the module, could this be true? How would you connect the touch controls.

  • May 8, 2016 at 10:26 am

    Certainly! Thanks for your help.

  • May 8, 2016 at 10:29 am

    Hi. It does not seem to support touch from the pinout. The SDA/SCK/CS/MISO/MOSI are purely for the main LCD module. If touch is supported, there should be separate pins named TP_XXXX for the touch controller. Nevertheless, you may want to confirm this by looking up the datasheet for the LCD module controller.

  • May 8, 2016 at 10:31 am

    That was my understanding. No data sheet available. Thanks for your thoughts!

  • May 8, 2016 at 10:32 am

    Thanks for your thoughts!

  • May 8, 2016 at 10:34 am

    No problem. You can still try to have a close look at the IC chipset on the lcd board and find out which controller they are using from the label, and google for the IC codes to find the datasheet.

  • May 8, 2016 at 11:58 am

    Unfortunately, no chipset is visible. :-/

  • May 8, 2016 at 1:08 pm

    Are there any screws on the module attaching the LCD to the PCB? If yes, try to unscrew these things – you may be able to find the driver/controller chipset hidden in between the board and the actual LCD. This is the case for one of my units.

  • March 27, 2017 at 11:39 am

    Hi oakkar7,

    I know it is almost two years after your post, but I am trying to implement this code with a PIC18F4620 with the XC8 compiler, and I have not gotten this to work. Is there any way that I can see how you ported this, if you still have it?

    Thank you,


  • ToughDev
    March 27, 2017 at 1:19 pm


    You can share with me any errors that you have when compiling the code using XC8, and I will try to help. Thanks.

  • March 27, 2017 at 10:13 pm

    So after changing some things I was able to make it compile. However, nothing is being written to the LCD. I know the display works because I tested it with an arduino and it works perfectly. I wrote an SPI_write() function which you can see here : https://pastebin.com/pyQmG5UC
    When I stepped through it I saw that the correct data was being written to the SSPBUF register, but it was getting overwritten immediately when I checked the busy flag.

    I don’t know if I am doing my SPI correctly or if Ihave more problems in my code. I did’t change much from the provided code but you can take a look here if you have time:

    font.h -> https://pastebin.com/FCaCdmBn
    Config.h -> https://pastebin.com/NaiHvHGc
    ST7735.h -> https://pastebin.com/XZrFYEVf
    Final.C -> https://pastebin.com/eGkvCY8K

    I apologize for my bad coding and thank you for taking the time to look at this.

  • ToughDev
    March 27, 2017 at 11:58 pm


    I checked your code and did not see where you set the SPI clock and SPI mode inside the configuration registers. Check the datasheet to see how to set these values. Without the clock being configured, SPI won’t work properly.

    A few other thoughts:

    (1) You are using the hardware SPI module. Have you checked that the SPI code is actually working properly, for example by using an oscilloscope and look at the SPI clock pin? If the code is working, there should be a clock signal on that pin.

    (2) If hardware SPI does not work, try to change to software SPI mode, e.g. bit-banging, and verify that the module can work. My example code was using bit-bang for SPI. It is easier this way and more convenient, especially if you don’t need to transfer data at high speed.

    (3) Be carefull when using the debugger to step through the code in these type of hardware projects. The LCD module could be waiting for the next command in a matter of milliseconds and by the time you step through the next line of code, it has timed out, causing all sort of weird issues.

    Let me know how it goes.

  • October 6, 2018 at 9:32 pm

    Hello! How can I use another font? What’s font generator program do I need?

  • February 22, 2019 at 8:43 pm

    How to modify “write char” to use custom fonts, not only 5×7?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>