Giter Site home page Giter Site logo

andygock / glcd Goto Github PK

View Code? Open in Web Editor NEW
96.0 15.0 49.0 316 KB

Graphic LCD Library for microcontrollers based embedded systems. Compatible with chipsets PCD854, ST7565R, NTD75451 and many AVR, LPC, PIC, STM32 devices.

License: Other

C 94.43% C++ 5.57%

glcd's Introduction

glcd - Graphic LCD Library

by Andy Gock

Documentation

For up to date documentation, please see the doxygen pages under the doxygen_pages directory and within the source code.

A online version can also be seen at:

https://andygock.github.io/glcd-documentation/

However the above site may not always be up to date.

Introduction

Welcome to GLCD, an open source graphic LCD library written by Andy Gock.

This library has been written cleanly, to allow easy modification for use with different microcontroller devices and controller chipsets. Logic relating to devices and controllers are palced in seperate files and specific implementations can be chosen by the use of special defined symbols.

It is suitable for monochrome (black and white) LCDs with page by page data and command write style data transfer protocol. It is not compatible with color graphic LCDs.

Features

  • Draw text, of different sizes, from small 5x7 pixel fonts to large custom characters. Custom fonts can be generated using free MikroElektronika Font Creator software.
  • Can write text from SRAM and Flash memory.
  • Scrolling text.
  • Draw vertical or horizontal bar graphs, with or without borders.
  • Draw circles, lines, rectangles - filled or unfilled.
  • Draw individual pixels in any color (black or white).
  • Display is fully buffered, for a Nokia 5110 display of 84x48 dots, you'll need at least 504 bytes of SRAM to store the frame buffer.
  • It only writes the part of the frame buffer which has changed. It does not re-write the entire buffer to the LCD every frame update.

Supported devices

Controllers and chipsets

Works with:

  • PCD8544 based LCDs, e.g Nokia 3110 and 5110 LCDs
  • ST7565R / ST7565P serial interface
  • NT75451 parallel interface (used on NGX BlueBoards)

The following graphic displays have been physically tested with and confirmed working:

  • NHD-C12864WC-FSW-FBW-3V3-M
  • NHD-C12864A1Z-FSW-FBW-HTT
  • NHD-C12832A1Z-FSW-FBW-3V3
  • ZOLEN-12864-FFSSWE-NAA

Microcontrollers

MCUs supported

  • Atmel AVR 8-bit
  • NXP LPC111x ARM Cortex-M0
  • NXP LPC11Uxx ARM Cortex-M0
  • ST STM32 F0 ARM Cortex-M0
  • ST STM32 F4 ARM Cortex-M4
  • Microchip PIC24H (and probably other 16-bit MCUs)

Development boards tested on (with on-board LCD)

  • NGX BlueBoard LPC11U37 (with on-board NT75451 graphic LCD)

Development boards tested on (without on-board LCD)

  • Microstick II with PIC24H and Nokia 3310/5110 LCD, ST7565R and ST7565P
  • ST Nucleo F401RE

Special note

Not all combinations of microcontroller platform and LCD controllers are supported out of the box. However you can edit the files devices/ and controllers/ and add your desired combination. More information on how to do this can be read in the doxygen documentation.

Setup of symbols for compiler

The following symbols need to be defined for the compiler:

Select microcontroller

Pick microcontroller type (pick one only):

GLCD_DEVICE_LPX111X
GLCD_DEVICE_LPX11UXX
GLCD_DEVICE_AVR8
GLCD_DEVICE_STM32F0XX
GLCD_DEVICE_STM32F4XX
GLCD_DEVICE_PIC24H

Select LCD controller

Pick LCD controller type (pick one only):

GLCD_CONTROLLER_PCD8544
GLCD_CONTROLLER_ST7565R
GLCD_CONTROLLER_NT75451

For ST7565P controllers, treat as ST7565R. For most if not all parts here, they behave the same way.

Select SPI or parallel interface

If using a parallel interface LCD (e.g NT75451 on NGX BlueBoard):

GLCD_USE_PARALLEL

When using SPI controllers:

GLCD_USE_SPI

Note the SPI symbol isn't actually checked by the source at the moment, and it is fine if it is not used. It is for forward compatibility only. One day I may decide to check for it.

Initialisation sequence

For the Newhaven displays using ST7565 based controllers listed above which have been tested as working, there are certain initialisation sequences which should be followed, and this may vary from display to display. To force a certain (and tested) initialisation sequence, define one of the following:

GLCD_INIT_NHD_C12832A1Z_FSW_FBW_3V3
GLCD_INIT_NHD_C12864A1Z_FSW_FBW_HTT
GLCD_INIT_NHD_C12864WC_FSW_FBW_3V3_M
GLCD_INIT_ZOLEN_12864_FFSSWE_NAA

If you don't specify a NHD model, ST7565 controller selection will default to GLCD_INIT_NHD_C12864WC_FSW_FBW_3V3_M sequence. This however may change in the future.

Reset time

To set a reset time, used by the glcd_reset() function, set GLCD_RESET_TIME to desired duration in milliseconds.

Contrast

When using PCD8544 controllers, define a PCD8544_CONTRAST symbol with a 8-bit unsigned integer for the contast value. If this is not defined, a default value will be used.

LCD dimensions

Set GLCD_LCD_WIDTH and GLCD_LCD_HEIGHT to define custom LCD dimensions. If these are not user defined, then a default width and height is used. The default dimensions are 128x64 except for PCD8544 controllers which is 84x48.

Compiler setup

These symbols need to be set in the configuration options of your IDE, usually in the "defined symbols" section, or they can be defined in a makefile as -D options.

Example:

-DGLCD_DEVICE_LPC111X

Delay Timing

Some operations such as sending a reset pulse, requires the use of a delay timer. The library will refer to a external function called delay_ms(t) where t is the delay required in milliseconds. Please ensure you have this function elsewhere in your program.

AVR devices

If you are using avr-gcc with Atmel devices, you can force the library to use the built-in _delay_ms() function by setting the compiler symbols:

GLCD_USE_AVR_DELAY
__DELAY_BACKWARD_COMPATIBLE__

F_CPU must be set to your clock frequency for the above AVR built-in delay routine to work.

Sample applications and videos

  • STM32F0 Discovery with PCD8544 Nokia 5110 LCD - Download Keil MDK project
  • Custom PCB with Atmel ATMEGA2560 and ST7565R Newhaven 128×64 display - Download Atmel Studio 6 project
  • Atmel AT90USBKEY board with PCD8544 Nokia 5110 LCD - Download Atmel Studio 5 project
  • ZERO Z111xP Cortex-M0 LPC1114 board with PCD8544 Nokia 5110 LCD - Download CooCox CoIDE project or watch video
  • NGX LPC11U37 BlueBoard with built in NT75451 parallel chipset LCD - Download Keil MDK project
  • Microstick II development board, with PIC24H and Newhaven ST7565R display NHD-C12864A1Z-FSW-FBW-HTT - Download MPLAB X project or watch video
  • Microstick II development board, with PIC24H and Newhaven ST7565P display NHD-C12832A1Z-FSW-FBW-3V3 - Download MPLAB X project or watch video
  • Microstick II development board, with PIC24H and PCD8544 Nokia 5110 display - Download MPLAB X project
  • Pinguino development board, with PIC32MX440F256H and PCD8544 Nokia 5110 display - Download MPLAB X project (Thanks to Joris Putcuyps)

The code samples above will have the glcd library code already inside it, however I haven’t made any attempt to keep the glcd library updated in the examples so I advise that if you are using the example code, to replace the glcd directory (usually in library/glcd or lib/glcd) with the latest updated code.

Display bitmap images

Bitmap images can be converted into a byte array using LCD Assistant

When using this software, we need to set 8 pixels per byte with vertical byte orientation. Do not include size.

glcd's People

Contributors

andygock avatar miguelmoreto avatar mircho avatar silver-kuusik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glcd's Issues

Problem drawing char with height multiple of 8

Hello,

thanks for this great library. I'm using it with a STM32 and a ST7565 based LCD. It works pretty well, but there is a problem when drawing a character in MIKRO format that have a height of an exact multiple of 8.

In text.c, line 118:

uint8_t bytes_high = font_current.height / 8 + 1;

If you have a font with height 16, the bytes_high will be 3, which is incorrect (should be 2). The drawing result is a mess, because the lib "thinks" that the char have 3 bytes in height.

I change that line with:

    uint8_t bytes_high;

    if ((font_current.height % 8) > 0){
        bytes_high = (font_current.height / 8) + 1;
    }
    else{
        bytes_high = (font_current.height / 8);
    }

Basically it just checks if the remainder is zero, if it is, it means that the height is a exact multiple of 8 and adding a 1 is not necessary.

With that modification I can use any font with 16, 24, 36, ... height pixels.

Thanks,

Miguel

glcd_draw_string_xy(0,0,string);

Hi,
thanks for the greate library. I made a project with this library.I noticed that the (glcd_draw_string_xy(0,0,string);) affect the code speed .
specially that the code is dependent on reading sensors and timers.
any help to boost this function.
Regards.

Selected bounding box size issue.

Hello Andy & all,
I have been unsuccessful in my attempts to use your LCD library.
In my application code, a function call to, for example, glcd_test_hello_world() would subsequently call glcd_update_bbox() with 0,0,127,63 xmin, ymin, xmax, ymax arguments.
glcd_bbox_selected contained possibly suspicious bounding box x/y values:
glcd_bbox_selected->x_min: 0
glcd_bbox_selected->y_min: 128
glcd_bbox_selected->x_max: 0
glcd_bbox_selected->y_max: 16

Updating the bounding box size, at glcd-0.5.2/src/glcd.c line 91:
if (xmax > glcd_bbox_selected->x_max) {
glcd_bbox_selected->x_max = xmax;
}
appears to alter glcd_bbox_selected->x_max from 0 to 127, causing a HardFault_Handler() while(1)-loop function call in the auto-generated LPC11U6x Microcontroller Startup code. This behaviour is consistent.

A further query, is the number of banks a reference to the number of display data RAM pages. Should it be #define GLCD_NUMBER_OF_BANKS (GLCD_LCD_HEIGHT / 8)? However, it didn't resolve the bounding box size issue that I appear to be experiencing.
/*

  • GLCD_NUMBER_OF_BANKS is typically GLCD_LCD_HEIGHT/8
  • Don't adjust these below unless required.
    */
    #define GLCD_NUMBER_OF_BANKS (GLCD_LCD_WIDTH / 8)
    #define GLCD_NUMBER_OF_COLS GLCD_LCD_WIDTH

Note that I am able to access the LCD module from the MCU (LPC11U68) using SPI initialisation and display data RAM commands.
Has anyone experienced similar bounding box size behaviour when developing / debugging their application? It appears that glcd_bbox_selected ymin & xmax values may have been swapped, can someone indicate where in the code these values are assigned?

Regards,
Des.

The following is a brief background to my development setup:

IDE environment: LPCXpresso v8.1.4 [Build 606] [2016-03-14]
Development board: NXP Xpresso LPC11U68 v2 Issue B
Development hardware library: LPCOpen v2.06 software package for NXP Xpresso LPC11U68 board
Graphic LCD library: glcd-0.5.2
Graphic LCD module: NHD-C12864A1Z-FS(RGB)-FBW-HT1 (ST7565P controller)

Using the following compiler-related symbols:
GLCD_CONTROLLER_ST7565R
GLCD_DEVICE_LPC11UXX
GLCD_INIT_NHD_C12864A1Z_FSW_FBW_HTT
GLCD_USE_SPI

For successful compilation, amendments to glcd-0.5.2\devices\LPC11Uxx.h, from line 50 were need for alignment with LPCXpresso SSP port and GPIO port and pin assignments:
/* Define port and pins used to connect to LCD */
#define CONTROLLER_SPI_PORT_NUMBER LPC_SSP0
#define CONTROLLER_MOSI_PORT 0
#define CONTROLLER_MOSI_PIN 9
#define CONTROLLER_MISO_PORT 0
#define CONTROLLER_MISO_PIN 8
#define CONTROLLER_SCK_PORT 1
#define CONTROLLER_SCK_PIN 29
#define CONTROLLER_SS_PORT 0
#define CONTROLLER_SS_PIN 2
#define CONTROLLER_A0_PORT 0
#define CONTROLLER_A0_PIN 12
#define CONTROLLER_RST_PORT 0
#define CONTROLLER_RST_PIN 14

/* Preprocessor macros */
#define GLCD_SELECT()     Chip_GPIO_SetPinState(LPC_GPIO, CONTROLLER_SS_PORT, CONTROLLER_SS_PIN, false)
#define GLCD_DESELECT()   Chip_GPIO_SetPinState(LPC_GPIO, CONTROLLER_SS_PORT, CONTROLLER_SS_PIN, true)
#define GLCD_A0_LOW()     Chip_GPIO_SetPinState(LPC_GPIO, CONTROLLER_A0_PORT, CONTROLLER_A0_PIN, false)
#define GLCD_A0_HIGH()    Chip_GPIO_SetPinState(LPC_GPIO, CONTROLLER_A0_PORT, CONTROLLER_A0_PIN, true)
#define GLCD_RESET_LOW()  Chip_GPIO_SetPinState(LPC_GPIO, CONTROLLER_RST_PORT, CONTROLLER_RST_PIN, false)
#define GLCD_RESET_HIGH() Chip_GPIO_SetPinState(LPC_GPIO, CONTROLLER_RST_PORT, CONTROLLER_RST_PIN, true)

For successful compilation, amendments to glcd-0.5.2\devices\LPC11Uxx.c, from line 142, using LPCOpen function call Chip_SSP_SendFrame() :
void glcd_spi_write(uint8_t c)
{
GLCD_SELECT();
//SSP_Send(CONTROLLER_SPI_PORT_NUMBER,&c,1);
Chip_SSP_SendFrame(CONTROLLER_SPI_PORT_NUMBER, c);
GLCD_DESELECT();
}

Implement: glcd_draw_bitmap_area

Description

A function to show icons anywhere on the screen.

Motivation

Be able to update icons anywhere on the display without fully refreshing display buffer. Useful for user interfaces with icons.

Status

Figured it's quite complex to calculate out the pixels in the buffer to update. @andygock do you know if there is perhaps a simpler more elegant approach to this ?

This the implementation I started, not complete:

const unsigned char data[] = {
     0x01, 0x00, 0xe0, 0xe0, 0x60, 0x60, 0x60, 0xfc, 0xfe, 0xe2, 0x02, 0x1e, 0x3c, 0x00, 0x00, 0x01, 
     0x80, 0x00, 0x0f, 0x0f, 0x0f, 0x0c, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
};
glcd_clear_buffer();
glcd_draw_bitmap_area(0, 0, 16, 16, data);
glcd_write();

void glcd_draw_bitmap_area(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const unsigned char *data)
{
	uint8_t i;

	if (y % 8 == 0) {
		for (i = 0; i < h / 8; i++) {
			memcpy(glcd_buffer_selected + x + i * GLCD_NUMBER_OF_COLS, data + i * w, w);
		}
	}
	else {
		for (i = 0; i < w; i++) {
			glcd_buffer_selected[i + x + (y / 8) * GLCD_NUMBER_OF_COLS] = data[i] & (uint8_t) (0xff << (y % 8));
			glcd_buffer_selected[i + x + (y / 8 + h / 8) * GLCD_NUMBER_OF_COLS] = data[i] & (0xff00 & (0x00ff << (y % 8))) >> 8;
		}
		if (h > 8)
			memcpy(glcd_buffer_selected + x + GLCD_NUMBER_OF_COLS, data + w, (w * h) - w);
	}

	glcd_bbox_reset();
	glcd_update_bbox(x, y, x + w - 1, y + h - 1);
}

Reporter

@silver-kuusik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.