published on in Electronics
tags: psoc st7565

PSoC component for ST7565 LCDs

I recently released a PSoC 4 Component to control serial graphic LCDs using the ST7565 controller ICs. My display came from Adafruit and includes RGB backlight but I am sure there are more variants out there.

Usage

The component is easy to use, first grab the source code from the Github repository:

Source Code Releases

The download includes a sample project if you want to quickly try the display. To use this in another project, include the ST7565-Component project in your workspace and mark it as a dependency for your main project.

How to include the component as a dependency in PSoC Creator

After marking the project as a dependency, the component should be available under the “Community” tag of the component picker.

For the following examples, the component will be named “LCD” for simplicity’s sake.

Initializing the display is easy:

/* Initialize the display */
LCD_init();
/* Refresh the display so we are sure it displays nothing */
LCD_refresh();

Working with this library will be familiar to anyone that has used the Adafruit GFX Library before. Some basic drawing:

/* Drawing lines */
LCD_draw_line(x1, y1, x2, y2,  color);
LCD_draw_line(17, 42, 112, 12, 1);
LCD_draw_line(3, 72, 120, 90, 1);

/* Draw circles */
LCD_draw_circle(x0, y0, r, color);
LCD_draw_circle(40, 32, 5, 1);

/* Draw rectangles */
LCD_draw_rect(x, y, w, h, color);
LCD_draw_rect(18, 42, 121, 19, 1);

/* Draw text */
LCD_set_textSize(3); // 3 x 8 pixels height
LCD_set_cursor(0, 0);
LCD_write_string("Hello world!");

/* Display the changes */
LCD_refresh();

LCD_refresh() only marks that the display should be refresh. The actual refreshing takes places in the LCD_refresh_loop() function that you should place in your main loop. This is done so that refreshing the display does not block code execution.

Following is a bare minimum example of using and refreshing the display.

int main() {
    CyGlobalIntEnable; // Enable interrupts

    LCD_init();
    LCD_refresh();

    for (;;) {
        do_stuff();
        waste_time();
        do_something_else();

        LCD_refresh_loop();
    }
}

Resources

The component's internal wiring

The component uses internally the stock PSoC SPI Master Component which requires 3 status cells! That’s 75% of the total cells available on the PSoC4 Pioneer kit. If the application uses more external SPI components it would be beneficial to use the internal SPI Master component to save digital space.

It is also important to note that this display does no buffering so 1024 bytes are reserved from the SRAM to buffer it for drawing.

Clock speed

I’ve used this display at SPI clock speeds as high as 4MHz and as low as 100kHz. 4MHz is the upper limit accoarding to the datasheet but it will probably work a bit faster. To change the clockspeed, modify the Clock_SPI component in the internal diagram. Remember that the final SPI clock is the internal clock divided by 2. It seems that the clock speed does not affect the refresh rates that much, which are capped much lower than 4MHz.

Closing thoughts

The full library reference is available at the Github wiki over here. I also created a hardware compatibility page over there, if anyone tries this library with other display modules feel free to contact me with how it went!