├── .gitignore ├── .gitattributes ├── doxygen_pages ├── AddingController.txt ├── AddingDevice.txt └── MainPage.txt ├── devices ├── PIC32.h ├── PIC32.c ├── LPC111x.h ├── LPC111x.c ├── inc │ ├── STM32F0xx.h │ └── STM32F10x.h ├── AVR8.h ├── PIC24H.h ├── STM32F10x.c ├── AVR8.c ├── STM32F4.h ├── STM32F0xx.c ├── LPC11Uxx.c ├── LPC11Uxx.h └── PIC24H.c ├── LICENSE ├── controllers ├── NT75451.h ├── PCD8544.h ├── ST7565R.h ├── PCD8544.c ├── NT75451.c └── ST7565R.c ├── fonts ├── Earthbound_12x19_48to57.h ├── Liberation_Sans11x14_Numbers.h ├── font5x7.h ├── Liberation_Sans15x21_Numbers.h ├── Liberation_Sans20x28_Numbers.h ├── Bebas_Neue18x36_Numbers.h ├── Bebas_Neue20x36_Bold_Numbers.h └── Liberation_Sans17x17_Alpha.h ├── unit_tests.h ├── glcd_devices.h ├── glcd_controllers.h ├── glcd_graphs.h ├── graphs.c ├── glcd_text.h ├── glcd.c ├── glcd_text_tiny.h ├── glcd_graphics.h ├── text_tiny.c ├── graphics.c ├── README.md └── glcd.h /.gitignore: -------------------------------------------------------------------------------- 1 | fonts/HelveticaNeueLT_Com_57_Cn23x35_Numbers.h 2 | fonts/HelveticaNeueLT_Com_95_Blk18x19.h 3 | devices/glcd_user_config.h 4 | glcd-*.zip 5 | *.o 6 | *.map 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.aspx text 2 | *.asx text 3 | *.css text 4 | *.erb text 5 | *.erl text 6 | *.go text 7 | *.hs text 8 | *.html text 9 | *.js text 10 | *.jsp text 11 | *.less text 12 | *.md text 13 | *.markdown text 14 | *.php text 15 | *.pl text 16 | *.py text 17 | *.rb text 18 | *.rhtml text 19 | *.rjs text 20 | *.sass text 21 | *.scss text 22 | *.svg text 23 | *.textile text 24 | *.txt text 25 | *.xml text 26 | Procfile text 27 | *.bmp binary 28 | *.gif binary 29 | *.jpeg binary 30 | *.jpg binary 31 | *.png binary -------------------------------------------------------------------------------- /doxygen_pages/AddingController.txt: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | \page AddingController Adding a new chipset 4 | 5 | \page AddingController 6 | 7 | Code for new controllers are stored in `devices/`. Use a descriptive name for the corresponding `.c` and `.h` file. 8 | 9 | The best way to see how to do this is to view the files already in there. 10 | 11 | The code in here define routines which are specific for the chipset. This does not include the Required Functions used in the deive specific code. 12 | 13 | \see \ref AddingDevice 14 | 15 | Code in these files must only call functions which are: 16 | 17 | - those *required* functions in the `devices/*.h` files 18 | - within the same file as itself 19 | - functions declared by glcd.h 20 | 21 | \see \ref DeviceRequiredFunctions 22 | 23 | If you *must* do something that is compiler specfic, seperate the code using preprocessor commands that isolate the compiler in question. But try and avoid this if possible. 24 | 25 | ## Updating glcd.h 26 | 27 | After adding your device and controller, you'll also need to edit glcd.h, and make any additions as needed. Take a look at the existing code to see what needs to be done. Devices specific such as preprocessor macros, compiler specific include statements can be added here. 28 | 29 | */ -------------------------------------------------------------------------------- /devices/PIC32.h: -------------------------------------------------------------------------------- 1 | #ifndef GLCD_PINOUTS_PIC32_H_ 2 | #define GLCD_PINOUTS_PIC32_H_ 3 | 4 | #if defined(GLCD_DEVICE_USER) 5 | #include "glcd_user_config.h" 6 | #include "glcd_user_config.c" 7 | #else 8 | 9 | #if defined(GLCD_DEVICE_PIC32) 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #if defined(GLCD_CONTROLLER_PCD8544) 16 | // * Chipselect -> UEXT PIN 10 -> RF0 17 | #define LCD_CS_PORT IOPORT_F 18 | #define LCD_CS_PIN BIT_0 19 | // * D/C (data/command) -> UEXT PIN 6 -> Arduino A4 -> RD9 20 | #define LCD_DC_RESET_PORT IOPORT_D 21 | #define LCD_DC_PIN BIT_9 22 | // * LCD RESET(active low) -> UEXT PIN 5 -> Arduino A5 -> RD10 23 | #define LCD_RESET_PIN BIT_10 24 | #else 25 | #error "Controller not supported or defined in PIC32 module" 26 | #endif 27 | 28 | /** 29 | * \name Macros for control lines 30 | * @{ 31 | */ 32 | #define GLCD_SELECT() PORTClearBits(LCD_CS_PORT, LCD_CS_PIN) 33 | #define GLCD_DESELECT() PORTSetBits(LCD_CS_PORT, LCD_CS_PIN) 34 | #define GLCD_DC_LOW() PORTClearBits(LCD_DC_RESET_PORT, LCD_DC_PIN) 35 | #define GLCD_DC_HIGH() PORTSetBits(LCD_DC_RESET_PORT, LCD_DC_PIN) 36 | #define GLCD_RESET_LOW() PORTClearBits(LCD_DC_RESET_PORT, LCD_RESET_PIN) 37 | #define GLCD_RESET_HIGH() PORTSetBits(LCD_DC_RESET_PORT, LCD_RESET_PIN) 38 | /**@}*/ 39 | 40 | #endif /* GLCD_DEVICE_PIC32 */ 41 | 42 | #endif /* GLCD_DEVICE_USER */ 43 | 44 | #endif /* GLCD_PINOUTS_PIC32_H_ */ 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Modified BSD License 2 | 3 | Copyright (c) 2012, Andy Gock 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of Andy Gock nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL Andy Gock BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /devices/PIC32.c: -------------------------------------------------------------------------------- 1 | #include "../glcd.h" 2 | 3 | #if defined(GLCD_DEVICE_USER) 4 | #include "glcd_user_config.h" 5 | #include "glcd_user_config.c" 6 | #else 7 | 8 | #if defined(GLCD_DEVICE_PIC32) 9 | 10 | void glcd_init(void) 11 | { 12 | #if defined(GLCD_CONTROLLER_PCD8544) 13 | 14 | /* Set up remappable outputs for PIC32, SPI: DO and SCK */ 15 | SpiChnOpen(SPI_CHANNEL2, SPI_CON_ON|SPI_CON_MSTEN, 4); 16 | 17 | /* Set SS, DC and RST pins as output */ 18 | PORTSetPinsDigitalOut(LCD_CS_PORT, LCD_CS_PIN); 19 | PORTSetPinsDigitalOut(LCD_DC_RESET_PORT, LCD_DC_PIN | LCD_RESET_PIN); 20 | 21 | /* Deselect LCD */ 22 | GLCD_DESELECT(); 23 | 24 | /* Send reset pulse to LCD */ 25 | glcd_reset(); 26 | 27 | /* Initialise the display */ 28 | glcd_PCD8544_init(); 29 | 30 | /* Select screen buffer */ 31 | glcd_select_screen(glcd_buffer,&glcd_bbox); 32 | 33 | /* Clear screen, we are now ready to go */ 34 | glcd_clear(); 35 | #else 36 | #error "Controller not supported" 37 | #endif /* GLCD_CONTROLLER_* */ 38 | } 39 | 40 | void glcd_spi_write(uint8_t c) 41 | { 42 | GLCD_SELECT(); 43 | SpiChnPutC(SPI_CHANNEL2, c); 44 | // Wait until the byte is sent before deselecting 45 | while(SpiChnIsBusy(SPI_CHANNEL2)); 46 | GLCD_DESELECT(); 47 | } 48 | 49 | void glcd_reset(void) 50 | { 51 | GLCD_SELECT(); 52 | GLCD_RESET_LOW(); 53 | delay_ms(GLCD_RESET_TIME); 54 | GLCD_RESET_HIGH(); 55 | // Wait until the byte is sent before deselecting 56 | while(SpiChnIsBusy(SPI_CHANNEL2)); 57 | GLCD_DESELECT(); 58 | } 59 | 60 | #endif /* defined(GLCD_DEVICE_PIC32) */ 61 | 62 | #endif /* GLCD_DEVICE_USER */ 63 | -------------------------------------------------------------------------------- /controllers/NT75451.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file NT75451.h 3 | \author Andy Gock 4 | \brief Constants and definitions for NT75451 controller 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #if defined(GLCD_CONTROLLER_NT75451) 36 | 37 | #include "../glcd.h" 38 | 39 | /** Parallel write to NT75451 */ 40 | void glcd_parallel_write(uint8_t c); 41 | 42 | /** Initialise NT75451 based display */ 43 | void glcd_NT75451_init(void); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /fonts/Earthbound_12x19_48to57.h: -------------------------------------------------------------------------------- 1 | #ifndef Earthbound_12x19_48to57_H 2 | #define Earthbound_12x19_48to57_H 3 | 4 | // Size: 12x19 5 | // Chars: 48 to 57 6 | const char font_Earthbound_12x19_48to57[] PROGMEM = { 7 | 0x00, 0xe0, 0xf0, 0x38, 0x0c, 0x0c, 0x0c, 0x0c, 0x38, 0xf8, 0xc0, 0x00, 0x00, 0x1f, 0x7f, 0xe0, 0x80, 0x80, 0x80, 0x80, 0xe0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, // Char '0' 8 | 0x00, 0x10, 0x18, 0x18, 0xfc, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Char '1' 9 | 0x00, 0x08, 0x1c, 0x0c, 0x0c, 0x0c, 0x0c, 0x8c, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0xf8, 0x9c, 0x8c, 0x86, 0x86, 0x83, 0x83, 0x80, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, // Char '2' 10 | 0x00, 0x08, 0x1c, 0x0c, 0x0c, 0x0c, 0x0c, 0x8c, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x80, 0x81, 0x83, 0x83, 0xc7, 0xff, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, // Char '3' 11 | 0x00, 0x00, 0x00, 0x80, 0xc0, 0x70, 0x38, 0xfc, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1e, 0x1b, 0x11, 0x18, 0x10, 0xff, 0xff, 0x10, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, // Char '4' 12 | 0x00, 0x00, 0xf4, 0xfc, 0x1c, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc3, 0x83, 0x83, 0x83, 0x83, 0xc7, 0xfe, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, // Char '5' 13 | 0x00, 0xc0, 0xf0, 0x78, 0x1c, 0x0c, 0x0c, 0x0c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xc3, 0x83, 0x83, 0x83, 0xc3, 0xfe, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, // Char '6' 14 | 0x00, 0x0c, 0x0c, 0x0c, 0x0c, 0x8c, 0xcc, 0x7c, 0x3c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x80, 0xf0, 0x7c, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Char '7' 15 | 0x00, 0xf0, 0xf8, 0x1c, 0x0c, 0x0c, 0x0c, 0x0c, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x8f, 0x07, 0x06, 0x06, 0x8f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, // Char '8' 16 | 0x00, 0xf0, 0xf8, 0x1c, 0x0c, 0x0c, 0x0c, 0x1c, 0xf8, 0xe0, 0x00, 0x00, 0x00, 0x01, 0x87, 0x8e, 0x8c, 0x8c, 0x8c, 0xee, 0x7f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 // Char '9' 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /fonts/Liberation_Sans11x14_Numbers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Liberation_Sans11x14_Numbers.h 3 | * 4 | * Created: 30/03/2012 1:31:10 AM 5 | * Author: andy 6 | */ 7 | 8 | 9 | #ifndef LIBERATION_SANS11X14_NUMBERS_H_ 10 | #define LIBERATION_SANS11X14_NUMBERS_H_ 11 | 12 | 13 | //WARNING: This Font Require X-GLCD Lib. 14 | // You can not use it with MikroE GLCD Lib. 15 | 16 | //Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0 17 | //MikroElektronika 2011 18 | //http://www.mikroe.com 19 | 20 | //GLCD FontName : Liberation_Sans11x14 46 to 57 21 | //GLCD FontSize : 11 x 14 22 | 23 | static const char Liberation_Sans11x14_Numbers[] PROGMEM = { 24 | 0x04, 0x00, 0x00, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char . 25 | 0x05, 0x00, 0x38, 0x80, 0x3F, 0xFC, 0x0F, 0xFF, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char / 26 | 0x0A, 0x00, 0x00, 0xF0, 0x07, 0xFC, 0x1F, 0xFE, 0x3F, 0x0E, 0x38, 0x06, 0x30, 0x0E, 0x38, 0xFE, 0x3F, 0xFC, 0x1F, 0xF0, 0x07, 0x00, 0x00, // Code for char 0 27 | 0x0B, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x0C, 0x30, 0x0E, 0x30, 0xFE, 0x3F, 0xFE, 0x3F, 0xFE, 0x3F, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, // Code for char 1 28 | 0x0A, 0x00, 0x00, 0x18, 0x38, 0x1C, 0x3C, 0x1E, 0x3E, 0x06, 0x37, 0x86, 0x33, 0xC6, 0x31, 0xFE, 0x31, 0xFC, 0x30, 0x78, 0x30, 0x00, 0x00, // Code for char 2 29 | 0x0A, 0x00, 0x00, 0x18, 0x0C, 0x1C, 0x1C, 0x1E, 0x3C, 0xC6, 0x30, 0xC6, 0x30, 0xC6, 0x31, 0xFE, 0x3F, 0xBC, 0x1F, 0x3C, 0x0F, 0x00, 0x00, // Code for char 3 30 | 0x0B, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x07, 0xE0, 0x06, 0x38, 0x06, 0x1E, 0x06, 0xFE, 0x3F, 0xFE, 0x3F, 0xFE, 0x3F, 0x00, 0x06, 0x00, 0x06, // Code for char 4 31 | 0x0A, 0x00, 0x00, 0xFE, 0x0C, 0xFE, 0x1C, 0xC6, 0x3C, 0x66, 0x38, 0x66, 0x30, 0xE6, 0x38, 0xE6, 0x3F, 0xC6, 0x1F, 0x80, 0x0F, 0x00, 0x00, // Code for char 5 32 | 0x0A, 0x00, 0x00, 0xF0, 0x07, 0xFC, 0x1F, 0xFC, 0x3F, 0x8E, 0x38, 0xC6, 0x30, 0xC6, 0x30, 0xCE, 0x3F, 0x8C, 0x1F, 0x08, 0x0F, 0x00, 0x00, // Code for char 6 33 | 0x0A, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x06, 0x38, 0x06, 0x3F, 0xC6, 0x3F, 0xE6, 0x03, 0xFE, 0x00, 0x3E, 0x00, 0x0E, 0x00, 0x00, 0x00, // Code for char 7 34 | 0x0A, 0x00, 0x00, 0x38, 0x0F, 0xFC, 0x1F, 0xFE, 0x3F, 0xC6, 0x30, 0xC6, 0x30, 0xC6, 0x30, 0xFE, 0x3F, 0xFC, 0x1F, 0x38, 0x0F, 0x00, 0x00, // Code for char 8 35 | 0x0A, 0x00, 0x00, 0x78, 0x08, 0xFC, 0x18, 0xFE, 0x39, 0x86, 0x31, 0x86, 0x31, 0x86, 0x38, 0xFE, 0x1F, 0xFC, 0x1F, 0xF0, 0x07, 0x00, 0x00 // Code for char 9 36 | }; 37 | 38 | 39 | 40 | 41 | 42 | #endif /* LIBERATION_SANS11X14_NUMBERS_H_ */ 43 | -------------------------------------------------------------------------------- /unit_tests.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file unit_tests.h 3 | * \brief Various test functions to demonstrate features of the library 4 | * \author Andy Gock 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _UNIT_TESTS_H 36 | #define _UNIT_TESTS_H 37 | 38 | #define GLCD_UNIT_TEST_BITMAP_ENABLE 39 | 40 | extern volatile uint8_t unit_test_return; 41 | 42 | /** Make random "exploding circles" */ 43 | void glcd_test_circles(void); 44 | 45 | /* Shows a 8-bit counter incorementing, with a verticla and horizontal bar graph */ 46 | void glcd_test_counter_and_graph(void); 47 | 48 | /* Shows a 16-bit counter incrementing, using glcdutils font format */ 49 | void glcd_test_glcdutils(void); 50 | 51 | /** Scroll some text up and down the screen */ 52 | void glcd_test_text_up_down(void); 53 | 54 | /** Display all chars of tiny 5x7 font, scrolling previous lines one by one every second */ 55 | void glcd_test_tiny_text(void); 56 | 57 | /** Print hello world to display */ 58 | void glcd_test_hello_world(void); 59 | 60 | /** Demonstrating rectangle drawing */ 61 | void glcd_test_rectangles(void); 62 | 63 | /** Demonstrate scrolling bar graph */ 64 | void glcd_test_scrolling_graph(void); 65 | 66 | /** Demonstrate bitmap display */ 67 | void glcd_test_bitmap_128x64(void); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /doxygen_pages/AddingDevice.txt: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | \page AddingDevice Adding a new device 4 | 5 | \section AddingDevice Adding a new device 6 | 7 | Before you add a device, you should make sure you have set up your controller code. 8 | 9 | To add a custom device (microcontroller) implementation, you may wish to check out the source code of the existing devices for some guidance. Note that references to "device" refers to a microcontroller, not the graphics controller. 10 | 11 | The device specific code is stored under: 12 | 13 | devices/ 14 | 15 | For example, files relating to NXP LPC111x are `devices/LPC111x.c` and `devices/LPC111x.h` 16 | 17 | \subsection DeviceRequiredFunctions Required functions 18 | 19 | These files define behaviour which are specific to that device. Behaviour specific to a type of device should be not placed in any other directory other than this. 20 | 21 | These files should have functions for all those declared in by `glcd_devices.h`. 22 | 23 | This currently only includes, in the case of SPI operation: 24 | 25 | glcd_init(void) 26 | glcd_reset(void) 27 | glcd_spi_write(uint8_t c) 28 | 29 | In the case of parallel chipset operation `glcd_parallel_write(uint8_t c)` is used instead of ` glcd_spi_write(uint8_t c)`. 30 | 31 | For chipsets that may not need ay of the functions above, you'll still need to define the function in your code, even if you just leave it blank. 32 | 33 | The corresponding `devices/mydevice.h` should be used as well to store all required constants. Try and avoid using "magic numbers" in the code. This header file should also be used to store port and pin information for the implementation. 34 | 35 | Example: 36 | 37 | \code 38 | #define PCD8544_SPI_PORT_NUMBER 1 39 | #define PCD8544_MOSI_PORT LPC_GPIO2 40 | #define PCD8544_MOSI_PIN 3 41 | #define PCD8544_MISO_PORT LPC_GPIO2 42 | #define PCD8544_MISO_PIN 2 43 | #define PCD8544_SCK_PORT LPC_GPIO2 44 | #define PCD8544_SCK_PIN 1 45 | #define PCD8544_SS_PORT LPC_GPIO2 46 | #define PCD8544_SS_PIN 0 47 | #define PCD8544_DC_PORT LPC_GPIO2 48 | #define PCD8544_DC_PIN 4 49 | #define PCD8544_RST_PORT LPC_GPIO2 50 | #define PCD8544_RST_PIN 5 51 | \endcode 52 | 53 | If certain code is specific to a controller and is not universal, use ifdef statements to isolate them e.g: 54 | 55 | \code 56 | #if defined(GLCD_CONTROLLER_PCD8544) 57 | /* insert code */ 58 | #else 59 | /* Use a meaningful error message */ 60 | #error "Controller not supported for LPC111x" 61 | #endif 62 | \endcode 63 | 64 | ## Updating glcd.h 65 | 66 | After adding your device and controller, you'll also need to edit glcd.h, and make any additions as needed. Take a look at the existing code to see what needs to be done. Devices specific such as preprocessor macros, compiler specific include statements can be added here. 67 | 68 | ## Overriding configurations 69 | 70 | Coming soon. 71 | 72 | 73 | */ -------------------------------------------------------------------------------- /devices/LPC111x.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file LPC111x.h 3 | * \brief Pinouts and driver config for NXP LPC111x ARM Cortex-M0 MCUs. 4 | * \author Andy Gock 5 | */ 6 | 7 | /* 8 | 9 | Copyright (c) 2012 Andy Gock 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining 12 | a copy of this software and associated documentation files (the 13 | "Software"), to deal in the Software without restriction, including 14 | without limitation the rights to use, copy, modify, merge, publish, 15 | distribute, sublicense, and/or sell copies of the Software, and to 16 | permit persons to whom the Software is furnished to do so, subject to 17 | the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be 20 | included in all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | 30 | */ 31 | 32 | #ifndef LPC111X_H_ 33 | #define LPC111X_H_ 34 | 35 | #if defined(GLCD_DEVICE_LPC111X) 36 | 37 | /* 38 | * Set up SSP and GPIO drivers (GPIO drivers required for SSP) 39 | * Change these paths if the files are located elsewhere 40 | */ 41 | #include "../../drivers/ssp.h" 42 | #include "../../drivers/gpio.h" 43 | 44 | #define swap(a, b) { uint8_t t = a; a = b; b = t; } 45 | 46 | /* Define port and pins used to connecto LCD */ 47 | #define CONTROLLER_SPI_PORT_NUMBER 1 48 | #define CONTROLLER_MOSI_PORT LPC_GPIO2 49 | #define CONTROLLER_MOSI_PIN 3 50 | #define CONTROLLER_MISO_PORT LPC_GPIO2 51 | #define CONTROLLER_MISO_PIN 2 52 | #define CONTROLLER_SCK_PORT LPC_GPIO2 53 | #define CONTROLLER_SCK_PIN 1 54 | #define CONTROLLER_SS_PORT LPC_GPIO2 55 | #define CONTROLLER_SS_PIN 0 56 | #define CONTROLLER_DC_PORT LPC_GPIO2 57 | #define CONTROLLER_DC_PIN 4 58 | #define CONTROLLER_RST_PORT LPC_GPIO2 59 | #define CONTROLLER_RST_PIN 5 60 | 61 | /* Preprocessor macros */ 62 | #define GLCD_SELECT() CONTROLLER_SS_PORT->DATA &= ~(1 << CONTROLLER_SS_PIN) 63 | #define GLCD_DESELECT() CONTROLLER_SS_PORT->DATA |= (1 << CONTROLLER_SS_PIN) 64 | #define GLCD_DC_LOW() CONTROLLER_DC_PORT->DATA &= ~(1 << CONTROLLER_DC_PIN) 65 | #define GLCD_DC_HIGH() CONTROLLER_DC_PORT->DATA |= (1 << CONTROLLER_DC_PIN) 66 | #define GLCD_RESET_LOW() CONTROLLER_RST_PORT->DATA &= ~(1 << CONTROLLER_RST_PIN) 67 | #define GLCD_RESET_HIGH() CONTROLLER_RST_PORT->DATA |= (1 << CONTROLLER_RST_PIN) 68 | 69 | #endif /* GLCD_DEVICE_LPC111X */ 70 | 71 | #endif /* LPC111X_H_ */ 72 | -------------------------------------------------------------------------------- /controllers/PCD8544.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file PCD8544.h 3 | * \brief Constants relating to PCD8544 LCD Controller (Nokia 5110 LCD). 4 | * \author Andy Gock 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef PCD8544_H_ 36 | #define PCD8544_H_ 37 | 38 | /** 39 | * \name Function set commands 40 | * @{ 41 | */ 42 | #define PCD8544_NOP 0 43 | #define PCD8544_FUNCTION_SET (1<<5) 44 | #define PCD8544_POWER_DOWN (1<<2) 45 | #define PCD8544_HORIZONTAL_ADDRESSING 0 46 | #define PCD8544_VERTICAL_ADDRESSING (1<<1) 47 | #define PCD8544_EXTENDED_INSTRUCTION (1<<0) 48 | /**@}*/ 49 | 50 | /** 51 | * \name Basic instruction set (H=0) 52 | * @{ 53 | */ 54 | #define PCD8544_DISPLAY_CONTROL (1<<3) 55 | #define PCD8544_DISPLAY_BLANK 0x0 56 | #define PCD8544_DISPLAY_NORMAL (1<<2) 57 | #define PCD8544_DISPLAY_ALL_ON (1<<0) 58 | #define PCD8544_DISPLAY_INVERTED (1<<2|1<<0) 59 | #define PCD8544_SET_Y_ADDRESS 0x40 60 | #define PCD8544_SET_X_ADDRESS 0x80 61 | /**@}*/ 62 | 63 | /** 64 | * \name Extended instruction set (H=1) 65 | * @{ 66 | */ 67 | #define PCD8544_SET_TEMP (1<<2) 68 | #define PCD8544_TEMPCO_0 0b00 69 | #define PCD8544_TEMPCO_1 0b01 70 | #define PCD8544_TEMPCO_2 0b10 71 | #define PCD8544_TEMPCO_3 0b11 72 | 73 | /** \todo Check if these instructions are from this group */ 74 | #define PCD8544_SET_BIAS (1<<4) 75 | #define PCD8544_SET_VOP (1<<7) 76 | /**@}*/ 77 | 78 | #define PCD8544_MAX_BANKS 6 79 | #define PCD8544_MAX_COLS 84 80 | 81 | /** Init PCD8544 controller / display */ 82 | void glcd_PCD8544_init(void); 83 | 84 | #endif /* PCD8544_H_ */ 85 | -------------------------------------------------------------------------------- /devices/LPC111x.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file LPC111x.c 3 | * \brief Initialisation and driver confiuration for NXP LPC111x ARM Cortex-M0 MCUs. 4 | * \author Andy Gock 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "../glcd.h" 36 | #include "LPC111x.h" 37 | 38 | #if defined(GLCD_DEVICE_LPC111X) 39 | 40 | void glcd_init(void) 41 | { 42 | 43 | #if defined(GLCD_CONTROLLER_PCD8544) 44 | /* 45 | * Set up SPI (SSP) 46 | * Note: Max allowed SPI clock is 4 MHz from datasheet. 47 | */ 48 | 49 | /* Select SSP/SPI port */ 50 | SSP_IOConfig( CONTROLLER_SPI_PORT_NUMBER ); 51 | 52 | /* Initialise SSP/SPI port */ 53 | SSP_Init( CONTROLLER_SPI_PORT_NUMBER ); 54 | 55 | /* Above functions take care of SPI pins */ 56 | 57 | /* Set SS, DC and RST pins to output */ 58 | CONTROLLER_SS_PORT->DIR |= (1 << CONTROLLER_SS_PIN); 59 | CONTROLLER_DC_PORT->DIR |= (1 << CONTROLLER_DC_PIN); 60 | CONTROLLER_RST_PORT->DIR |= (1 << CONTROLLER_RST_PIN); 61 | 62 | /* Reset the display */ 63 | glcd_reset(); 64 | 65 | glcd_PCD8544_init(); 66 | 67 | glcd_select_screen(glcd_buffer,&glcd_bbox); 68 | 69 | glcd_clear(); 70 | 71 | #else /* GLCD_CONTROLLER_PCD8544 */ 72 | #error "Controller not supported by LPC111x" 73 | #endif 74 | 75 | } 76 | 77 | void glcd_spi_write(uint8_t c) 78 | { 79 | GLCD_SELECT(); 80 | SSP_Send(CONTROLLER_SPI_PORT_NUMBER,&c,1); 81 | GLCD_DESELECT(); 82 | } 83 | 84 | void glcd_reset(void) 85 | { 86 | /* Toggle RST low to reset. Minimum pulse 100ns on datasheet. */ 87 | GLCD_SELECT(); 88 | GLCD_RESET_LOW(); 89 | delay_ms(GLCD_RESET_TIME); 90 | GLCD_RESET_HIGH(); 91 | GLCD_DESELECT(); 92 | } 93 | 94 | #endif /* GLCD_DEVICE_LPC111x */ 95 | -------------------------------------------------------------------------------- /devices/inc/STM32F0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file STM32F0xx.h 3 | \author Andy Gock 4 | \brief Functions specific to STM32 F0 ARM Cortex-M0 devices. 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef STM32F0XX_H_ 36 | #define STM32F0XX_H_ 37 | 38 | #if defined(GLCD_DEVICE_STM32F0XX) 39 | 40 | /** SPI port number e.g SPI1, SPI2 (not to be confused with GPIOA, GPIOB, etc) */ 41 | #define CONTROLLER_SPI_NUMBER SPI1 42 | #define CONTROLLER_SPI_PORT GPIOA 43 | #define CONTROLLER_SPI_SCK_PIN GPIO_Pin_5 44 | #define CONTROLLER_SPI_SCK_PINSRC GPIO_PinSource5 45 | #define CONTROLLER_SPI_MISO_PIN GPIO_Pin_6 46 | #define CONTROLLER_SPI_MISO_PINSRC GPIO_PinSource6 47 | #define CONTROLLER_SPI_MOSI_PIN GPIO_Pin_7 48 | #define CONTROLLER_SPI_MOSI_PINSRC GPIO_PinSource7 49 | 50 | #define CONTROLLER_SPI_SS_PORT GPIOA 51 | #define CONTROLLER_SPI_SS_PIN GPIO_Pin_1 52 | #define CONTROLLER_SPI_DC_PORT GPIOA 53 | #define CONTROLLER_SPI_DC_PIN GPIO_Pin_2 54 | #define CONTROLLER_SPI_RST_PORT GPIOA 55 | #define CONTROLLER_SPI_RST_PIN GPIO_Pin_3 56 | 57 | #define GLCD_SELECT() GPIO_ResetBits(CONTROLLER_SPI_SS_PORT,CONTROLLER_SPI_SS_PIN) 58 | #define GLCD_DESELECT() GPIO_SetBits(CONTROLLER_SPI_SS_PORT,CONTROLLER_SPI_SS_PIN) 59 | #define GLCD_DC_LOW() GPIO_ResetBits(CONTROLLER_SPI_DC_PORT,CONTROLLER_SPI_DC_PIN) 60 | #define GLCD_DC_HIGH() GPIO_SetBits(CONTROLLER_SPI_DC_PORT,CONTROLLER_SPI_DC_PIN) 61 | #define GLCD_RESET_LOW() GPIO_ResetBits(CONTROLLER_SPI_RST_PORT,CONTROLLER_SPI_RST_PIN) 62 | #define GLCD_RESET_HIGH() GPIO_SetBits(CONTROLLER_SPI_RST_PORT,CONTROLLER_SPI_RST_PIN) 63 | 64 | #else 65 | #error "Controller not supported by STM32F0XX" 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /glcd_devices.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file glcd_devices.h 3 | \brief Functions specific to certain devices (microcontrollers). 4 | These are functions are defined in devices/yourdevice.c 5 | \author Andy Gock 6 | */ 7 | 8 | /* 9 | Copyright (c) 2012, Andy Gock 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without 14 | modification, are permitted provided that the following conditions are met: 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | * Neither the name of Andy Gock nor the 21 | names of its contributors may be used to endorse or promote products 22 | derived from this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef GLCD_DEVICES_H_ 37 | #define GLCD_DEVICES_H_ 38 | 39 | #if defined(GLCD_DEVICE_AVR8) 40 | #include 41 | #elif defined(GLCD_DEVICE_LPC111X) 42 | #include "LPC11xx.h" 43 | #elif defined(GLCD_DEVICE_LPC11UXX) 44 | #include "LPC11Uxx.h" 45 | #elif defined(GLCD_DEVICE_STM32F0XX) 46 | #include "STM32F0xx.h" 47 | #elif defined(GLCD_DEVICE_STM32F10X) 48 | #include "STM32F10x.h" 49 | #elif defined(GLCD_DEVICE_STM32F4XX) 50 | #include "stm32f4xx.h" 51 | #include "devices/STM32F4.h" 52 | #elif defined(GLCD_DEVICE_PIC24H) 53 | #include 54 | #include 55 | #include 56 | #elif defined(GLCD_DEVICE_PIC32) 57 | #else 58 | #error "Device not supported or defined" 59 | #endif 60 | 61 | /** \addtogroup Devices Devices 62 | * Functions specific to certain devices (microcontrollers) 63 | * \{ 64 | */ 65 | 66 | /** 67 | * Initialise the LCD. This function is platform and controller specific. 68 | */ 69 | void glcd_init(void); 70 | 71 | #if !defined(GLCD_USE_PARALLEL) 72 | 73 | /** 74 | * Write a byte to the connected SPI slave. 75 | * \param c Byte to be written 76 | * \return Returned value from SPI (often not used) 77 | */ 78 | void glcd_spi_write(uint8_t c); 79 | 80 | #else 81 | /* must be GLCD_USE_SPI */ 82 | void glcd_parallel_write(uint8_t c); 83 | 84 | #endif 85 | 86 | /** 87 | * Reset the LCD. 88 | * \note Not all LCD controllers support reset. 89 | */ 90 | void glcd_reset(void); 91 | 92 | /** @}*/ 93 | 94 | #endif /* GLCD_DEVICES_H_ */ 95 | -------------------------------------------------------------------------------- /controllers/ST7565R.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ST7565R.h 3 | * \brief Constants relating to ST7565R LCD controller. 4 | * \author Andy Gock 5 | * 6 | * Constants and functions specific to ST7565R. 7 | * Tested with Newhaven Display model NHD-C12864WC-FSW-FBW-3V3-M 8 | * 9 | * \todo Need to move functions to be controller independent 10 | * 11 | */ 12 | 13 | /* 14 | Copyright (c) 2012, Andy Gock 15 | 16 | All rights reserved. 17 | 18 | Redistribution and use in source and binary forms, with or without 19 | modification, are permitted provided that the following conditions are met: 20 | * Redistributions of source code must retain the above copyright 21 | notice, this list of conditions and the following disclaimer. 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in the 24 | documentation and/or other materials provided with the distribution. 25 | * Neither the name of Andy Gock nor the 26 | names of its contributors may be used to endorse or promote products 27 | derived from this software without specific prior written permission. 28 | 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 30 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 31 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 32 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 33 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 35 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 36 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 38 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef ST7565R_H_ 42 | #define ST7565R_H_ 43 | 44 | /* Commands */ 45 | #define ST7565R_DISPLAY_ON 0xAF /* 0b10101111 */ 46 | #define ST7565R_DISPLAY_OFF 0xAE /* 0b10101110 */ 47 | #define ST7565R_PAGE_ADDRESS_SET 0xB0 /* 0b10110000 */ 48 | #define ST7565R_COLUMN_ADDRESS_SET_LOWER 0x00 49 | #define ST7565R_COLUMN_ADDRESS_SET_UPPER 0x10 50 | #define ST7565R_DISPLAY_NORMAL 0xA4 /* 0b10100100 */ 51 | #define ST7565R_DISPLAY_ALL_ON 0xA5 /* 0b10100101 */ 52 | #define ST7565R_NORMAL 0xA0 /* 0b10100000 */ 53 | #define ST7565R_REVERSE 0xA1 /* 0b10100001 */ 54 | #define ST7565R_RESET 0xE2 /* 0b11100010 */ 55 | #define ST7565R_SET_START_LINE (1<<6) 56 | 57 | /* These functions only available on ST7565 implementation (for now) */ 58 | 59 | /* Private functions */ 60 | void glcd_set_column_upper(uint8_t addr); 61 | void glcd_set_column_lower(uint8_t addr); 62 | 63 | /** All display points on (native) */ 64 | void glcd_all_on(void); 65 | 66 | /** Set to normal mode */ 67 | void glcd_normal(void); 68 | 69 | /** Set start line/page */ 70 | void glcd_set_start_line(uint8_t addr); 71 | 72 | /** Clear the display immediately, does not buffer */ 73 | void glcd_clear_now(void); 74 | 75 | /** Show a black and white line pattern on the display */ 76 | void glcd_pattern(void); 77 | 78 | /** Init ST7565R controller / display */ 79 | void glcd_ST7565R_init(void); 80 | 81 | #endif /* ST7565R_H_ */ 82 | -------------------------------------------------------------------------------- /devices/inc/STM32F10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file STM32F10x.h 3 | * \brief Device implementation for ST STM32F10x ARM Cortex-M3 MCUs 4 | * Requires the use of ST's Standard Peripheral Library 5 | * \author Andy Gock 6 | * 7 | * \todo Code is untested! 8 | */ 9 | 10 | /* 11 | Copyright (c) 2012, Andy Gock 12 | 13 | All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions are met: 17 | * Redistributions of source code must retain the above copyright 18 | notice, this list of conditions and the following disclaimer. 19 | * Redistributions in binary form must reproduce the above copyright 20 | notice, this list of conditions and the following disclaimer in the 21 | documentation and/or other materials provided with the distribution. 22 | * Neither the name of Andy Gock nor the 23 | names of its contributors may be used to endorse or promote products 24 | derived from this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 27 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 30 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 33 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | #ifndef STM32F10X_H_ 38 | #define STM32F10X_H_ 39 | 40 | #if defined(GLCD_DEVICE_STM32F10X) 41 | 42 | /** SPI port number e.g SPI1, SPI2 (not to be confused with GPIOA, GPIOB, etc) */ 43 | #define CONTROLLER_SPI_NUMBER SPI1 44 | #define CONTROLLER_SPI_PORT GPIOA 45 | #define CONTROLLER_SPI_SCK_PIN GPIO_Pin_5 46 | #define CONTROLLER_SPI_SCK_PINSRC GPIO_PinSource5 47 | #define CONTROLLER_SPI_MISO_PIN GPIO_Pin_6 48 | #define CONTROLLER_SPI_MISO_PINSRC GPIO_PinSource6 49 | #define CONTROLLER_SPI_MOSI_PIN GPIO_Pin_7 50 | #define CONTROLLER_SPI_MOSI_PINSRC GPIO_PinSource7 51 | 52 | #define CONTROLLER_SPI_SS_PORT GPIOA 53 | #define CONTROLLER_SPI_SS_PIN GPIO_Pin_1 54 | #define CONTROLLER_SPI_DC_PORT GPIOA 55 | #define CONTROLLER_SPI_DC_PIN GPIO_Pin_2 56 | #define CONTROLLER_SPI_RST_PORT GPIOA 57 | #define CONTROLLER_SPI_RST_PIN GPIO_Pin_3 58 | 59 | #define GLCD_SELECT() GPIO_ResetBits(CONTROLLER_SPI_SS_PORT,CONTROLLER_SPI_SS_PIN) 60 | #define GLCD_DESELECT() GPIO_SetBits(CONTROLLER_SPI_SS_PORT,CONTROLLER_SPI_SS_PIN) 61 | #define GLCD_DC_LOW() GPIO_ResetBits(CONTROLLER_SPI_DC_PORT,CONTROLLER_SPI_DC_PIN) 62 | #define GLCD_DC_HIGH() GPIO_SetBits(CONTROLLER_SPI_DC_PORT,CONTROLLER_SPI_DC_PIN) 63 | #define GLCD_A0_LOW() GPIO_ResetBits(CONTROLLER_SPI_DC_PORT,CONTROLLER_SPI_DC_PIN) 64 | #define GLCD_A0_HIGH() GPIO_SetBits(CONTROLLER_SPI_DC_PORT,CONTROLLER_SPI_DC_PIN) 65 | #define GLCD_RESET_LOW() GPIO_ResetBits(CONTROLLER_SPI_RST_PORT,CONTROLLER_SPI_RST_PIN) 66 | #define GLCD_RESET_HIGH() GPIO_SetBits(CONTROLLER_SPI_RST_PORT,CONTROLLER_SPI_RST_PIN) 67 | 68 | #else 69 | #error "Controller not supported by STM32F10X" 70 | #endif 71 | 72 | #endif /* STM32F10X_H_ */ 73 | -------------------------------------------------------------------------------- /glcd_controllers.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file glcd_controllers.h 3 | \brief Functions specific to certain graphic LCD controllers. 4 | \author Andy Gock 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GLCD_CONTROLLERS_H_ 36 | #define GLCD_CONTROLLERS_H_ 37 | 38 | /** 39 | * \addtogroup Controllers Controllers 40 | * Controller specific functions. 41 | * 42 | * Currently only the following controllers are supported: 43 | * - PCD8544 (Nokia 5110 LCD) SPI interface 44 | * - ST7565R with SPI interface 45 | * 46 | * The C and header files defining these functions are stored in the subdirectory: 47 | * 48 | * devices/ 49 | * 50 | * \{ 51 | */ 52 | 53 | /** 54 | * Send command byte to LCD. 55 | * \param c Command byte to be written to LCD 56 | */ 57 | void glcd_command(uint8_t c); 58 | 59 | /** 60 | * Send data byte to LCD. 61 | * \param c Data byte to be written to LCD 62 | */ 63 | void glcd_data(uint8_t c); 64 | 65 | /** 66 | * Set contrast. 67 | * \param val Value from 0 to 127. This should be experimentally determined. Supported by PCD8544 only. 68 | */ 69 | void glcd_set_contrast(uint8_t val); 70 | 71 | /** 72 | * Power down the device. 73 | */ 74 | void glcd_power_down(void); 75 | 76 | /** 77 | * Power up the device. 78 | */ 79 | void glcd_power_up(void); 80 | 81 | /** 82 | * Set Y address of RAM (select bank). 83 | * - for PCD8544, device must be under basic instruction set mode before using this. 84 | * \param y page address of RAM (0 <= Y < GLCD_LCD_HEIGHT/8) 85 | * \see GLCD_LCD_HEIGHT 86 | * \see GLCD_NUMBER_OF_BANKS 87 | * 88 | * \note Update: \p y is actually bank number, not pixel number! 89 | */ 90 | void glcd_set_y_address(uint8_t y); 91 | 92 | /** 93 | * Set X address of RAM (column). Device must be under basic instruction set mode before using this. 94 | * \param x X address of RAM (0 <= X <= GLCD_LCD_WIDTH-1) 95 | * \see GLCD_LCD_WIDTH 96 | */ 97 | void glcd_set_x_address(uint8_t x); 98 | 99 | /** 100 | * Update the display within the specified bounding box. This physically writes data to the device's RAM. 101 | */ 102 | void glcd_write(void); 103 | 104 | /** @}*/ 105 | 106 | #endif /* GLCD_CONTROLLERS_H_ */ 107 | -------------------------------------------------------------------------------- /glcd_graphs.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file glcd_graphs.h 3 | \brief GLCD Library - Graph drawing functions. 4 | \author Andy Gock 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GLCD_GRAPHS_H 36 | #define GLCD_GRAPHS_H 37 | 38 | /** \addtogroup Graphing 39 | * Functions for graphing, e.g drawing bar graphs etc. 40 | * @{ 41 | */ 42 | 43 | /** Draw horizontal bar graph with 1 px wide border. 44 | * The bar graph draws from left to right as val increases. 45 | * \param x x location for top-left of border 46 | * \param y y location for top-left of border 47 | * \param width width of the border 48 | * \param height height of the border (must be over 2) 49 | * \param val value to display in graph (0-255 8 bit value). 50 | */ 51 | void glcd_bar_graph_horizontal(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val); 52 | 53 | /** Draw horizontal bar graph with no border. 54 | * The bar graph draws from left to right as val increases. 55 | * \param x x location for top-left of bar 56 | * \param y y location for top-left of bar 57 | * \param width width of the bar at full val 58 | * \param height height of the bar 59 | * \param val value to display in graph (0-255 8 bit value). 60 | */ 61 | void glcd_bar_graph_horizontal_no_border(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val); 62 | 63 | /** Draw vertical bar graph with 1px wide border. 64 | * The bar graph draws from bottom to top as val increases. 65 | * \param x x location for top-left of border 66 | * \param y y location for top-left of border 67 | * \param width width of the border 68 | * \param height height of the border 69 | * \param val value to display in graph (0-255 8 bit value). 70 | */ 71 | void glcd_bar_graph_vertical(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val); 72 | 73 | /** Draw vertical bar graph with no border. 74 | * The bar graph draws from bottom to top as val increases. 75 | * \param x x location for top-left of bar 76 | * \param y y location for top-left of bar 77 | * \param width width of the bar 78 | * \param height height of the bar 79 | * \param val value to display in graph (0-255 8 bit value). 80 | */ 81 | void glcd_bar_graph_vertical_no_border(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val); 82 | 83 | /** \todo write doc */ 84 | void glcd_scrolling_bar_graph(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val); 85 | 86 | /** @}*/ 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /fonts/font5x7.h: -------------------------------------------------------------------------------- 1 | /* 2 | * font5x7.h 3 | * 4 | * Created: 28/03/2012 1:52:20 AM 5 | * Author: andy 6 | */ 7 | 8 | // Title : Graphic LCD Font (Ascii Charaters) 9 | // Author : Pascal Stang 10 | 11 | #ifndef FONT5X7_H_ 12 | #define FONT5X7_H_ 13 | 14 | // standard ascii 5x7 font 15 | // defines ascii characters 0x20-0x7F (32-127) 16 | static const char Font5x7[] PROGMEM = { 17 | 0x00, 0x00, 0x00, 0x00, 0x00,// (space) 18 | 0x00, 0x00, 0x5F, 0x00, 0x00,// ! 19 | 0x00, 0x07, 0x00, 0x07, 0x00,// " 20 | 0x14, 0x7F, 0x14, 0x7F, 0x14,// # 21 | 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $ 22 | 0x23, 0x13, 0x08, 0x64, 0x62,// % 23 | 0x36, 0x49, 0x55, 0x22, 0x50,// & 24 | 0x00, 0x05, 0x03, 0x00, 0x00,// ' 25 | 0x00, 0x1C, 0x22, 0x41, 0x00,// ( 26 | 0x00, 0x41, 0x22, 0x1C, 0x00,// ) 27 | 0x08, 0x2A, 0x1C, 0x2A, 0x08,// * 28 | 0x08, 0x08, 0x3E, 0x08, 0x08,// + 29 | 0x00, 0x50, 0x30, 0x00, 0x00,// , 30 | 0x08, 0x08, 0x08, 0x08, 0x08,// - 31 | 0x00, 0x60, 0x60, 0x00, 0x00,// . 32 | 0x20, 0x10, 0x08, 0x04, 0x02,// / 33 | 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 34 | 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 35 | 0x42, 0x61, 0x51, 0x49, 0x46,// 2 36 | 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 37 | 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 38 | 0x27, 0x45, 0x45, 0x45, 0x39,// 5 39 | 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 40 | 0x01, 0x71, 0x09, 0x05, 0x03,// 7 41 | 0x36, 0x49, 0x49, 0x49, 0x36,// 8 42 | 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 43 | 0x00, 0x36, 0x36, 0x00, 0x00,// : 44 | 0x00, 0x56, 0x36, 0x00, 0x00,// ; 45 | 0x00, 0x08, 0x14, 0x22, 0x41,// < 46 | 0x14, 0x14, 0x14, 0x14, 0x14,// = 47 | 0x41, 0x22, 0x14, 0x08, 0x00,// > 48 | 0x02, 0x01, 0x51, 0x09, 0x06,// ? 49 | 0x32, 0x49, 0x79, 0x41, 0x3E,// @ 50 | 0x7E, 0x11, 0x11, 0x11, 0x7E,// A 51 | 0x7F, 0x49, 0x49, 0x49, 0x36,// B 52 | 0x3E, 0x41, 0x41, 0x41, 0x22,// C 53 | 0x7F, 0x41, 0x41, 0x22, 0x1C,// D 54 | 0x7F, 0x49, 0x49, 0x49, 0x41,// E 55 | 0x7F, 0x09, 0x09, 0x01, 0x01,// F 56 | 0x3E, 0x41, 0x41, 0x51, 0x32,// G 57 | 0x7F, 0x08, 0x08, 0x08, 0x7F,// H 58 | 0x00, 0x41, 0x7F, 0x41, 0x00,// I 59 | 0x20, 0x40, 0x41, 0x3F, 0x01,// J 60 | 0x7F, 0x08, 0x14, 0x22, 0x41,// K 61 | 0x7F, 0x40, 0x40, 0x40, 0x40,// L 62 | 0x7F, 0x02, 0x04, 0x02, 0x7F,// M 63 | 0x7F, 0x04, 0x08, 0x10, 0x7F,// N 64 | 0x3E, 0x41, 0x41, 0x41, 0x3E,// O 65 | 0x7F, 0x09, 0x09, 0x09, 0x06,// P 66 | 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q 67 | 0x7F, 0x09, 0x19, 0x29, 0x46,// R 68 | 0x46, 0x49, 0x49, 0x49, 0x31,// S 69 | 0x01, 0x01, 0x7F, 0x01, 0x01,// T 70 | 0x3F, 0x40, 0x40, 0x40, 0x3F,// U 71 | 0x1F, 0x20, 0x40, 0x20, 0x1F,// V 72 | 0x7F, 0x20, 0x18, 0x20, 0x7F,// W 73 | 0x63, 0x14, 0x08, 0x14, 0x63,// X 74 | 0x03, 0x04, 0x78, 0x04, 0x03,// Y 75 | 0x61, 0x51, 0x49, 0x45, 0x43,// Z 76 | 0x00, 0x00, 0x7F, 0x41, 0x41,// [ 77 | 0x02, 0x04, 0x08, 0x10, 0x20,// "\" 78 | 0x41, 0x41, 0x7F, 0x00, 0x00,// ] 79 | 0x04, 0x02, 0x01, 0x02, 0x04,// ^ 80 | 0x40, 0x40, 0x40, 0x40, 0x40,// _ 81 | 0x00, 0x01, 0x02, 0x04, 0x00,// ` 82 | 0x20, 0x54, 0x54, 0x54, 0x78,// a 83 | 0x7F, 0x48, 0x44, 0x44, 0x38,// b 84 | 0x38, 0x44, 0x44, 0x44, 0x20,// c 85 | 0x38, 0x44, 0x44, 0x48, 0x7F,// d 86 | 0x38, 0x54, 0x54, 0x54, 0x18,// e 87 | 0x08, 0x7E, 0x09, 0x01, 0x02,// f 88 | 0x08, 0x14, 0x54, 0x54, 0x3C,// g 89 | 0x7F, 0x08, 0x04, 0x04, 0x78,// h 90 | 0x00, 0x44, 0x7D, 0x40, 0x00,// i 91 | 0x20, 0x40, 0x44, 0x3D, 0x00,// j 92 | 0x00, 0x7F, 0x10, 0x28, 0x44,// k 93 | 0x00, 0x41, 0x7F, 0x40, 0x00,// l 94 | 0x7C, 0x04, 0x18, 0x04, 0x78,// m 95 | 0x7C, 0x08, 0x04, 0x04, 0x78,// n 96 | 0x38, 0x44, 0x44, 0x44, 0x38,// o 97 | 0x7C, 0x14, 0x14, 0x14, 0x08,// p 98 | 0x08, 0x14, 0x14, 0x18, 0x7C,// q 99 | 0x7C, 0x08, 0x04, 0x04, 0x08,// r 100 | 0x48, 0x54, 0x54, 0x54, 0x20,// s 101 | 0x04, 0x3F, 0x44, 0x40, 0x20,// t 102 | 0x3C, 0x40, 0x40, 0x20, 0x7C,// u 103 | 0x1C, 0x20, 0x40, 0x20, 0x1C,// v 104 | 0x3C, 0x40, 0x30, 0x40, 0x3C,// w 105 | 0x44, 0x28, 0x10, 0x28, 0x44,// x 106 | 0x0C, 0x50, 0x50, 0x50, 0x3C,// y 107 | 0x44, 0x64, 0x54, 0x4C, 0x44,// z 108 | 0x00, 0x08, 0x36, 0x41, 0x00,// { 109 | 0x00, 0x00, 0x7F, 0x00, 0x00,// | 110 | 0x00, 0x41, 0x36, 0x08, 0x00,// } 111 | 0x08, 0x08, 0x2A, 0x1C, 0x08,// -> 112 | 0x08, 0x1C, 0x2A, 0x08, 0x08 // <- 113 | }; 114 | 115 | 116 | 117 | 118 | #endif /* FONT5X7_H_ */ 119 | -------------------------------------------------------------------------------- /fonts/Liberation_Sans15x21_Numbers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Liberation_Sans15x21_Numbers.h 3 | * 4 | * Created: 30/03/2012 1:34:30 AM 5 | * Author: andy 6 | */ 7 | 8 | 9 | #ifndef LIBERATION_SANS15X21_NUMBERS_H_ 10 | #define LIBERATION_SANS15X21_NUMBERS_H_ 11 | 12 | 13 | //WARNING: This Font Require X-GLCD Lib. 14 | // You can not use it with MikroE GLCD Lib. 15 | 16 | //Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0 17 | //MikroElektronika 2011 18 | //http://www.mikroe.com 19 | 20 | //GLCD FontName : Liberation_Sans15x21 46 to 57 21 | //GLCD FontSize : 15 x 21 22 | 23 | static const char Liberation_Sans15x21_Numbers[] PROGMEM = { 24 | 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char . 25 | 0x07, 0x00, 0x00, 0x1E, 0x00, 0xE0, 0x1F, 0x00, 0xFF, 0x1F, 0xF8, 0xFF, 0x03, 0xFF, 0x1F, 0x00, 0xFF, 0x01, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char / 26 | 0x0E, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0xF8, 0xFF, 0x01, 0xFC, 0xFF, 0x07, 0xFC, 0xFF, 0x07, 0x3E, 0x80, 0x0F, 0x0E, 0x00, 0x0E, 0x0E, 0x00, 0x0E, 0x0E, 0x00, 0x0E, 0x1E, 0x80, 0x0F, 0xFC, 0xFF, 0x07, 0xFC, 0xFF, 0x07, 0xF8, 0xFF, 0x01, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x00, // Code for char 0 27 | 0x0E, 0x00, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x38, 0x00, 0x0E, 0x38, 0x00, 0x0E, 0x1C, 0x00, 0x0E, 0x0E, 0x00, 0x0E, 0xFE, 0xFF, 0x0F, 0xFE, 0xFF, 0x0F, 0xFE, 0xFF, 0x0F, 0xFE, 0xFF, 0x0F, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, // Code for char 1 28 | 0x0E, 0x00, 0x00, 0x00, 0x60, 0x00, 0x0F, 0x78, 0x80, 0x0F, 0x7C, 0xC0, 0x0F, 0x7C, 0xE0, 0x0F, 0x1E, 0xF0, 0x0F, 0x0E, 0xF8, 0x0E, 0x0E, 0x7C, 0x0E, 0x0E, 0x3E, 0x0E, 0x1E, 0x1F, 0x0E, 0xFE, 0x0F, 0x0E, 0xFC, 0x07, 0x0E, 0xF8, 0x03, 0x0E, 0xF0, 0x01, 0x0E, 0x00, 0x00, 0x00, // Code for char 2 29 | 0x0E, 0x00, 0x00, 0x00, 0x30, 0x80, 0x01, 0x38, 0x80, 0x03, 0x3C, 0x80, 0x07, 0x3C, 0x80, 0x0F, 0x1E, 0x00, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x1E, 0x1F, 0x0F, 0xFE, 0xFF, 0x0F, 0xFC, 0xFB, 0x07, 0xFC, 0xF9, 0x03, 0xF0, 0xE0, 0x01, 0x00, 0x00, 0x00, // Code for char 3 30 | 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xFE, 0x00, 0x80, 0xEF, 0x00, 0xC0, 0xE7, 0x00, 0xF0, 0xE1, 0x00, 0x7C, 0xE0, 0x00, 0x3E, 0xE0, 0x00, 0xFE, 0xFF, 0x0F, 0xFE, 0xFF, 0x0F, 0xFE, 0xFF, 0x0F, 0xFE, 0xFF, 0x0F, 0x00, 0xE0, 0x00, 0x00, 0xE0, 0x00, // Code for char 4 31 | 0x0E, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xF8, 0x87, 0x03, 0xFE, 0x87, 0x07, 0xFE, 0x87, 0x0F, 0xFE, 0x07, 0x0F, 0x0E, 0x03, 0x0E, 0x8E, 0x03, 0x0E, 0x8E, 0x03, 0x0E, 0x8E, 0x07, 0x0F, 0x8E, 0xFF, 0x07, 0x0E, 0xFF, 0x07, 0x0E, 0xFE, 0x03, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, // Code for char 5 32 | 0x0E, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0xF0, 0xFF, 0x01, 0xF8, 0xFF, 0x07, 0xFC, 0xFF, 0x07, 0x3E, 0x0E, 0x0F, 0x0E, 0x07, 0x0E, 0x0E, 0x07, 0x0E, 0x0E, 0x07, 0x0E, 0x1E, 0x0F, 0x0F, 0x3E, 0xFF, 0x0F, 0x3C, 0xFE, 0x07, 0x38, 0xFE, 0x03, 0x30, 0xF8, 0x01, 0x00, 0x00, 0x00, // Code for char 6 33 | 0x0E, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x0F, 0x0E, 0xE0, 0x0F, 0x0E, 0xF8, 0x0F, 0x0E, 0xFE, 0x0F, 0x8E, 0xFF, 0x00, 0xCE, 0x0F, 0x00, 0xFE, 0x03, 0x00, 0xFE, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 7 34 | 0x0E, 0x00, 0x00, 0x00, 0xF0, 0xE0, 0x01, 0xF8, 0xFB, 0x03, 0xFC, 0xFB, 0x07, 0xFE, 0xFF, 0x0F, 0x1E, 0x1F, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x1E, 0x1F, 0x0F, 0xFE, 0xFF, 0x0F, 0xFC, 0xFB, 0x07, 0xFC, 0xFB, 0x03, 0xF0, 0xE0, 0x01, 0x00, 0x00, 0x00, // Code for char 8 35 | 0x0E, 0x00, 0x00, 0x00, 0xF0, 0x83, 0x01, 0xF8, 0x87, 0x03, 0xFC, 0x8F, 0x07, 0xFE, 0x9F, 0x0F, 0x1E, 0x1E, 0x0F, 0x0E, 0x1C, 0x0E, 0x0E, 0x1C, 0x0E, 0x0E, 0x1C, 0x0E, 0x1E, 0x8E, 0x0F, 0xFC, 0xFF, 0x07, 0xFC, 0xFF, 0x03, 0xF8, 0xFF, 0x01, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x00 // Code for char 9 36 | }; 37 | 38 | 39 | 40 | 41 | 42 | #endif /* LIBERATION_SANS15X21_NUMBERS_H_ */ 43 | -------------------------------------------------------------------------------- /controllers/PCD8544.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file PCD8544.c 3 | * \brief Functions relating to PCD8544 LCD Controller (Nokia 5110 LCD). 4 | * \author Andy Gock 5 | * \see glcd.h 6 | */ 7 | 8 | /* 9 | Copyright (c) 2012, Andy Gock 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without 14 | modification, are permitted provided that the following conditions are met: 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | * Neither the name of Andy Gock nor the 21 | names of its contributors may be used to endorse or promote products 22 | derived from this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #if defined(GLCD_CONTROLLER_PCD8544) 37 | 38 | #include "../glcd.h" 39 | 40 | void glcd_command(uint8_t c) 41 | { 42 | GLCD_DC_LOW(); 43 | glcd_spi_write(c); 44 | } 45 | 46 | void glcd_data(uint8_t c) 47 | { 48 | GLCD_DC_HIGH(); 49 | glcd_spi_write(c); 50 | } 51 | 52 | void glcd_set_contrast(uint8_t val) { 53 | glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); 54 | glcd_command(PCD8544_SET_VOP | (val&0x7f)); 55 | glcd_command(PCD8544_FUNCTION_SET); 56 | glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); 57 | } 58 | 59 | void glcd_power_down(void) 60 | { 61 | /* First, fill RAM with zeroes to ensure minimum specified current consumption */ 62 | glcd_clear(); 63 | 64 | /* Power down */ 65 | glcd_command(PCD8544_FUNCTION_SET|PCD8544_POWER_DOWN); 66 | } 67 | 68 | void glcd_power_up(void) 69 | { 70 | glcd_command(PCD8544_FUNCTION_SET); 71 | } 72 | 73 | void glcd_set_y_address(uint8_t y) 74 | { 75 | glcd_command(PCD8544_SET_Y_ADDRESS|(y > 5 ? 5 : y)); 76 | } 77 | 78 | void glcd_set_x_address(uint8_t x) 79 | { 80 | glcd_command(PCD8544_SET_X_ADDRESS|(x & 0x7f)); 81 | } 82 | 83 | void glcd_write() 84 | { 85 | uint8_t bank; 86 | 87 | for (bank = 0; bank < PCD8544_MAX_BANKS; bank++) { 88 | /* Each bank is a single row 8 bits tall */ 89 | uint8_t column; 90 | 91 | if (glcd_bbox_selected->y_min >= (bank+1)*8) { 92 | continue; /* Skip the entire bank */ 93 | } 94 | 95 | if (glcd_bbox_selected->y_max < bank*8) { 96 | break; /* No more banks need updating */ 97 | } 98 | 99 | glcd_command(PCD8544_SET_Y_ADDRESS | bank); 100 | glcd_command(PCD8544_SET_X_ADDRESS | glcd_bbox_selected->x_min); 101 | 102 | for (column = glcd_bbox_selected->x_min; column <= glcd_bbox_selected->x_max; column++) 103 | { 104 | glcd_data( glcd_buffer_selected[PCD8544_MAX_COLS * bank + column] ); 105 | } 106 | } 107 | 108 | glcd_reset_bbox(); 109 | 110 | } 111 | 112 | void glcd_PCD8544_init(void) { 113 | 114 | glcd_reset(); 115 | 116 | /* Get into the EXTENDED mode! */ 117 | glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); 118 | 119 | /* LCD bias select (4 is optimal?) */ 120 | glcd_command(PCD8544_SET_BIAS | 0x2); 121 | 122 | /* Set VOP (affects contrast) */ 123 | /* Experimentally determined, play with this figure until contrast looks nice */ 124 | #if defined(PCD8544_CONTRAST) 125 | glcd_command(PCD8544_SET_VOP | PCD8544_CONTRAST); 126 | #else 127 | glcd_command(PCD8544_SET_VOP | 80); 128 | #endif 129 | 130 | /* Back to standard instructions */ 131 | glcd_command(PCD8544_FUNCTION_SET); 132 | 133 | /* Normal mode */ 134 | glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); 135 | } 136 | 137 | #endif 138 | -------------------------------------------------------------------------------- /controllers/NT75451.c: -------------------------------------------------------------------------------- 1 | /** 2 | \file NT75451.c 3 | \author Andy Gock 4 | \brief Function specific to NT75451 controller. 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #if defined(GLCD_CONTROLLER_NT75451) 36 | 37 | #include "../glcd.h" 38 | 39 | void glcd_command(uint8_t c) 40 | { 41 | GLCD_RS_LOW(); 42 | glcd_parallel_write(c); 43 | GLCD_RS_HIGH(); 44 | } 45 | 46 | void glcd_data(uint8_t c) 47 | { 48 | GLCD_RS_HIGH(); 49 | glcd_parallel_write(c); 50 | GLCD_RS_LOW(); 51 | } 52 | 53 | void glcd_set_contrast(uint8_t val) { 54 | } 55 | 56 | void glcd_power_down(void) 57 | { 58 | } 59 | 60 | void glcd_power_up(void) 61 | { 62 | } 63 | 64 | void glcd_set_y_address(uint8_t y) 65 | { 66 | /** Code by NGX Technologies */ 67 | glcd_command(0xB0 | (y > GLCD_NUMBER_OF_BANKS ? GLCD_NUMBER_OF_BANKS : y)); 68 | } 69 | 70 | void glcd_set_x_address(uint8_t x) 71 | { 72 | /** Code by NGX Technologies */ 73 | uint8_t lsb, msb; 74 | 75 | msb = (((x & 0xF0) >> 4)| 0x10); 76 | lsb = (x & 0x0F); 77 | 78 | glcd_command(lsb); 79 | glcd_command(msb); 80 | } 81 | 82 | /* Write screen buffer to display, within bounding box only */ 83 | void glcd_write() 84 | { 85 | uint8_t bank; 86 | 87 | for (bank = 0; bank < GLCD_NUMBER_OF_BANKS; bank++) { 88 | /* Each bank is a single row 8 bits tall */ 89 | uint8_t column; 90 | 91 | if (glcd_bbox_selected->y_min >= (bank+1)*8) { 92 | continue; /* Skip the entire bank */ 93 | } 94 | 95 | if (glcd_bbox_selected->y_max < bank*8) { 96 | break; /* No more banks need updating */ 97 | } 98 | 99 | glcd_set_y_address(bank); 100 | glcd_set_x_address(glcd_bbox_selected->x_min); 101 | 102 | for (column = glcd_bbox_selected->x_min; column <= glcd_bbox_selected->x_max; column++) 103 | { 104 | glcd_data( glcd_buffer_selected[GLCD_NUMBER_OF_COLS * bank + column] ); 105 | } 106 | } 107 | 108 | /* Display updated, we can reset the bounding box */ 109 | glcd_reset_bbox(); 110 | 111 | } 112 | 113 | void glcd_NT75451_init(void) { 114 | /* Initialise sequence - code by NGX Technologies */ 115 | glcd_command(0xE2); /* S/W RESWT */ 116 | glcd_command(0xA0); /* ADC select */ 117 | glcd_command(0xC8); /* SHL Normal */ 118 | glcd_command(0xA3); /* LCD bias */ 119 | glcd_command(0x2F); /* Power control */ 120 | glcd_command(0x22); /* reg resistor select */ 121 | glcd_command(0x40); /* Initial display line 40 */ 122 | glcd_command(0xA4); /* Normal display */ 123 | glcd_command(0xA6); /* Reverce display a7 */ 124 | glcd_command(0x81); /* Ref vg select mode */ 125 | glcd_command(0x3f); /* Ref vg reg select */ 126 | glcd_command(0xB0); /* Set page address */ 127 | glcd_command(0x10); /* Set coloumn addr MSB */ 128 | glcd_command(0x00); /* Set coloumn addr LSB */ 129 | glcd_command(0xAF); /* Display ON */ 130 | } 131 | 132 | #endif 133 | 134 | -------------------------------------------------------------------------------- /graphs.c: -------------------------------------------------------------------------------- 1 | /** 2 | \file graphs.c 3 | \brief Functions relating to graphs. e.g bar graphs etc. 4 | \author Andy Gock 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "glcd.h" 36 | 37 | static uint8_t glcd_map(uint8_t x1, uint8_t x2, uint8_t x); 38 | 39 | void glcd_bar_graph_horizontal(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val) 40 | { 41 | if (height < 3) { 42 | return; 43 | } 44 | glcd_draw_rect(x, y, width, height, BLACK); 45 | glcd_fill_rect(x+1, y+1, glcd_map(0,width-2,val), height-2 , BLACK); 46 | } 47 | 48 | void glcd_bar_graph_horizontal_no_border(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val) 49 | { 50 | if (height < 3) { 51 | return; 52 | } 53 | glcd_fill_rect(x, y, glcd_map(0,width,val), height , BLACK); 54 | } 55 | 56 | void glcd_bar_graph_vertical(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val) 57 | { 58 | glcd_draw_rect(x, y, width, height, BLACK); 59 | glcd_fill_rect(x+1, y+1+glcd_map(0,height-2,255-val), width-2, height-2-glcd_map(0,height-2,255-val), BLACK); 60 | } 61 | 62 | void glcd_bar_graph_vertical_no_border(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val) 63 | { 64 | glcd_fill_rect(x, y+glcd_map(0,height-2,255-val), width, height-2-glcd_map(0,height-2,255-val), BLACK); 65 | } 66 | 67 | void glcd_scrolling_bar_graph(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val) 68 | { 69 | uint8_t nx, ny; 70 | uint8_t color; 71 | 72 | /* Draw border of graph */ 73 | glcd_draw_rect(x,y,width,height,BLACK); 74 | 75 | /* Scroll inner contents left by one pixel width */ 76 | for (ny = 1; ny <= (height-2); ny++) { 77 | /* Redraw each horizontal line */ 78 | for (nx = 1; nx <= (width-2); nx += 1) { 79 | color = glcd_get_pixel(x+nx+1,y+ny); 80 | glcd_set_pixel(x+nx,y+ny,color); 81 | } 82 | } 83 | 84 | val = val * (height-3) / 255; 85 | 86 | /* Make sure we're not exceeding the size of box interior */ 87 | if (val > (height-3)) { 88 | val = height - 3; 89 | } 90 | 91 | /* Draw new bar - both black and white portions*/ 92 | glcd_draw_line(x+width-2,y+height-2,x+width-2,y+height-2-val,BLACK); 93 | glcd_draw_line(x+width-2,y+height-3-val,x+width-2,y+1,WHITE); 94 | 95 | /* Write to display */ 96 | glcd_write(); 97 | } 98 | 99 | void glcd_scrolling_bar_graph_timing(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t val, uint8_t line_width, uint16_t delay) 100 | { 101 | uint8_t n; 102 | if (line_width == 0) { 103 | line_width = 1; 104 | } 105 | 106 | /* Adjust graph line's width by just running glcd_scrolling_bar_graph() x number of times */ 107 | /* \todo This should be done differently! */ 108 | for (n=0; n 41 | #include 42 | 43 | #ifndef _BITHELPERS_ 44 | #define _BITHELPERS_ 45 | #define sbi(var, mask) ((var) |= _BV(mask)) 46 | #define cbi(var, mask) ((var) &= ~(_BV(mask))) 47 | #define DDR(x) (*(&x - 1)) 48 | #define PIN(x) (*(&x - 2)) 49 | #endif 50 | 51 | #define swap(a, b) { uint8_t t = a; a = b; b = t; } 52 | 53 | #if defined(GLCD_CONTROLLER_PCD8544) 54 | 55 | /** 56 | * \name SPI port and pins 57 | * @{ 58 | */ 59 | #define AVR_SS_PORT PORTB 60 | #define AVR_SS_PIN 0 61 | #define CONTROLLER_MOSI_PORT PORTB 62 | #define CONTROLLER_MOSI_PIN 2 63 | #define CONTROLLER_MISO_PORT PORTB 64 | #define CONTROLLER_MISO_PIN 3 65 | #define CONTROLLER_SCK_PORT PORTB 66 | #define CONTROLLER_SCK_PIN 1 67 | /**@}*/ 68 | 69 | /** 70 | * \name Other pins needed for serial LCD controller 71 | * @{ 72 | */ 73 | #define CONTROLLER_SS_PORT PORTA 74 | #define CONTROLLER_SS_PIN 5 75 | #define CONTROLLER_DC_PORT PORTB 76 | #define CONTROLLER_DC_PIN 5 77 | #define CONTROLLER_RST_PORT PORTB 78 | #define CONTROLLER_RST_PIN 4 79 | /**@}*/ 80 | 81 | #elif defined (GLCD_CONTROLLER_ST7565R) 82 | /** 83 | * \name SPI port and pins 84 | * @{ 85 | */ 86 | #define AVR_SS_PORT PORTB 87 | #define AVR_SS_PIN 0 88 | #define CONTROLLER_MOSI_PORT PORTB 89 | #define CONTROLLER_MOSI_PIN 2 90 | #define CONTROLLER_MISO_PORT PORTB 91 | #define CONTROLLER_MISO_PIN 3 92 | #define CONTROLLER_SCK_PORT PORTB 93 | #define CONTROLLER_SCK_PIN 1 94 | /**@}*/ 95 | 96 | /** 97 | * \name Other pins needed for serial LCD controller 98 | * @{ 99 | */ 100 | #define CONTROLLER_A0_PORT PORTC /**< Output port to GLCD A0 pin. */ 101 | #define CONTROLLER_A0_PIN 0 /**< Output pin number to GLCD A0 pin. */ 102 | #define CONTROLLER_SS_PORT PORTG 103 | #define CONTROLLER_SS_PIN 0 104 | #define CONTROLLER_RST_PORT PORTG 105 | #define CONTROLLER_RST_PIN 1 106 | /**@}*/ 107 | #else 108 | #error "Controller not supported by AVR8" 109 | #endif 110 | 111 | /** 112 | * \name Macros for control lines 113 | * @{ 114 | */ 115 | #define GLCD_SELECT() cbi(CONTROLLER_SS_PORT,CONTROLLER_SS_PIN) 116 | #define GLCD_DESELECT() sbi(CONTROLLER_SS_PORT,CONTROLLER_SS_PIN) 117 | #define GLCD_DC_LOW() cbi(CONTROLLER_DC_PORT,CONTROLLER_DC_PIN) 118 | #define GLCD_DC_HIGH() sbi(CONTROLLER_DC_PORT,CONTROLLER_DC_PIN) 119 | #define GLCD_RESET_LOW() cbi(CONTROLLER_RST_PORT,CONTROLLER_RST_PIN) 120 | #define GLCD_RESET_HIGH() sbi(CONTROLLER_RST_PORT,CONTROLLER_RST_PIN) 121 | 122 | #define GLCD_A0_LOW() cbi(CONTROLLER_A0_PORT,CONTROLLER_A0_PIN) 123 | #define GLCD_A0_HIGH() sbi(CONTROLLER_A0_PORT,CONTROLLER_A0_PIN) 124 | 125 | /**@}*/ 126 | 127 | #endif 128 | 129 | #endif /* GLCD_PINOUTS_AVR8_H_ */ 130 | -------------------------------------------------------------------------------- /glcd_text.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file glcd_text.h 3 | \brief GLCD Library - Text functions 4 | \author Andy Gock 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GLCD_TEXT_H 36 | #define GLCD_TEXT_H 37 | 38 | /** \addtogroup Text 39 | * Functions relating to using text fonts. 40 | * @{ 41 | */ 42 | 43 | /** \addtogroup StandardText Standard Text 44 | * Functions relating to using text fonts of all sizes. 45 | * @{ 46 | */ 47 | 48 | /** Set GLCD font to predefined font table. Only suitable for MikroElektronika font storage format. 49 | * 50 | * \param font_table pointer to font table to be used 51 | * \param width width of each character 52 | * \param height height of each character 53 | * \param start_char first character of font table 54 | * \param end_char last character of font table 55 | * \note Only suitable for MikroElektronika font storage format. For Stang format, use 56 | * glcd_tiny_set_font() 57 | * \see glcd_tiny_set_font() 58 | */ 59 | #if defined(GLCD_DEVICE_AVR8) 60 | void glcd_set_font(PGM_P font_table, uint8_t width, uint8_t height, char start_char, char end_char); 61 | #else 62 | void glcd_set_font(const char * font_table, uint8_t width, uint8_t height, char start_char, char end_char); 63 | #endif 64 | 65 | /** Set GLCD font to predefined font table. Suitable for different different types of font tables. 66 | * 67 | * \param font_table pointer to font table to be used 68 | * \param width width of each character 69 | * \param height height of each character 70 | * \param start_char first character of font table 71 | * \param end_char last character of font table 72 | * \param type font table type 73 | * \note Only suitable for MikroElektronika font storage format. For Stang format, use 74 | * glcd_tiny_set_font() 75 | * \see glcd_tiny_set_font() 76 | */ 77 | #if defined(GLCD_DEVICE_AVR8) 78 | void glcd_font(PGM_P font_table, uint8_t width, uint8_t height, char start_char, char end_char, font_table_type_t type); 79 | #else 80 | void glcd_font(const char * font_table, uint8_t width, uint8_t height, char start_char, char end_char, font_table_type_t type); 81 | #endif 82 | 83 | /** Draw a char at specified location. 84 | * \param x x location to place top-left of character frame 85 | * \param y y location to place top-left of character frame 86 | * \param c character to be drawn 87 | * \return width of character, 0 on error (e.g could not read font table) 88 | */ 89 | uint8_t glcd_draw_char_xy(uint8_t x, uint8_t y, char c); 90 | 91 | /** Draw a string at specified location. 92 | * \param x x location to place top-left of character frame 93 | * \param y y location to place top-left of character frame 94 | * \param c pointer to string to be drawn 95 | */ 96 | void glcd_draw_string_xy(uint8_t x, uint8_t y, char *c); 97 | 98 | /** Draw a string from program memory at specified location. 99 | * \param x x location to place top-left of character frame 100 | * \param y y location to place top-left of character frame 101 | * \param str pointer to string in program memory to be drawn 102 | */ 103 | void glcd_draw_string_xy_P(uint8_t x, uint8_t y, const char *str); 104 | 105 | /** @}*/ 106 | 107 | /** @}*/ 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /devices/PIC24H.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file PIC24H.c 3 | \brief Functions relating to Microchip PIC24H (16-bit). 4 | For use with xc16 compiler. 5 | \author Andy Gock 6 | */ 7 | /* 8 | Copyright (c) 2013, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef GLCD_PINOUTS_PIC24H_H_ 36 | #define GLCD_PINOUTS_PIC24H_H_ 37 | 38 | #if defined(GLCD_DEVICE_USER) 39 | #include "glcd_user_config.h" 40 | #include "glcd_user_config.c" 41 | #else 42 | 43 | #if defined(GLCD_DEVICE_PIC24H) 44 | 45 | #include 46 | #include 47 | #include 48 | 49 | #if defined(GLCD_CONTROLLER_PCD8544) 50 | 51 | /* Pin configuration for Microstick II board, PGE* switch in 'A' position */ 52 | 53 | /** 54 | * \name SPI port and pins. SPI1 port is used in \file PIC24H.c. Define 55 | * the TRIS and PIN registers. 56 | * @{ 57 | */ 58 | #define CONTROLLER_MOSI_TRIS _TRISB14 59 | #define CONTROLLER_MOSI_PIN _LATB14 60 | #define CONTROLLER_SCK_TRIS _TRISB15 61 | #define CONTROLLER_SCK_PIN _LATAB15 62 | 63 | /* Output mapping for SPI1 (should be the same as above pins) */ 64 | #define REGISTER_MAP_SPI_DO _RP14R 65 | #define REGISTER_MAP_SPI_SCK _RP15R 66 | 67 | /**@}*/ 68 | 69 | /** 70 | * \name Other pins needed for serial LCD controller 71 | * @{ 72 | */ 73 | #define CONTROLLER_SS_TRIS _TRISB2 74 | #define CONTROLLER_SS_PIN _LATB2 75 | #define CONTROLLER_DC_TRIS _TRISB3 76 | #define CONTROLLER_DC_PIN _LATB3 77 | #define CONTROLLER_RST_TRIS _TRISA2 78 | #define CONTROLLER_RST_PIN _LATA2 79 | /**@}*/ 80 | 81 | #elif defined(GLCD_CONTROLLER_ST7565R) 82 | 83 | //#error "ST7565R not supported on PIC24H" 84 | 85 | /** 86 | * \name SPI port and pins. SPI1 port is used in \file PIC24H.c. Define 87 | * the TRIS and PIN registers. 88 | * @{ 89 | */ 90 | #define CONTROLLER_MOSI_TRIS _TRISB14 91 | #define CONTROLLER_MOSI_PIN _LATB14 92 | #define CONTROLLER_SCK_TRIS _TRISB15 93 | #define CONTROLLER_SCK_PIN _LATB15 94 | 95 | /* Output mapping for SPI1 (should be the same as above pins) */ 96 | #define REGISTER_MAP_SPI_DO _RP14R 97 | #define REGISTER_MAP_SPI_SCK _RP15R 98 | 99 | /**@}*/ 100 | 101 | /** 102 | * \name Other pins needed for serial LCD controller 103 | * @{ 104 | */ 105 | #define CONTROLLER_SS_TRIS _TRISB2 106 | #define CONTROLLER_SS_PIN _LATB2 107 | #define CONTROLLER_A0_TRIS _TRISB3 108 | #define CONTROLLER_A0_PIN _LATB3 109 | #define CONTROLLER_RST_TRIS _TRISA2 110 | #define CONTROLLER_RST_PIN _LATA2 111 | /**@}*/ 112 | 113 | #else 114 | #error "Controller not supported or defined in PIC24H module" 115 | #endif 116 | 117 | /** 118 | * \name Macros for control lines 119 | * @{ 120 | */ 121 | #define GLCD_SELECT() CONTROLLER_SS_PIN = 0 122 | #define GLCD_DESELECT() CONTROLLER_SS_PIN = 1 123 | #define GLCD_DC_LOW() CONTROLLER_DC_PIN = 0 124 | #define GLCD_DC_HIGH() CONTROLLER_DC_PIN = 1 125 | #define GLCD_RESET_LOW() CONTROLLER_RST_PIN = 0 126 | #define GLCD_RESET_HIGH() CONTROLLER_RST_PIN = 1 127 | 128 | #define GLCD_A0_LOW() CONTROLLER_A0_PIN = 0 /* Command write */ 129 | #define GLCD_A0_HIGH() CONTROLLER_A0_PIN = 1 /* Write to display RAM */ 130 | 131 | /**@}*/ 132 | 133 | #endif /* GLCD_DEVICE_PIC24H */ 134 | 135 | #endif /* GLCD_DEVICE_USER */ 136 | 137 | #endif /* GLCD_PINOUTS_PIC24H_H_ */ 138 | -------------------------------------------------------------------------------- /doxygen_pages/MainPage.txt: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | \mainpage 4 | 5 | \section Introduction Introduction 6 | 7 | Welcome to GLCD, an open source graphic LCD library written by Andy Gock. 8 | 9 | Author's web site: https://agock.com/ 10 | 11 | GitHub repository: https://github.com/andygock/glcd 12 | 13 | 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. 14 | 15 | It is suitable for monochrome (black and white) LCDs with page by page data and command write style data transfer protocol. It is not cmopatible with color graphic LCDs. 16 | 17 | \section SupportedLCDChipsets Supported LCD Chipsets 18 | 19 | Current supported LCD controllers / chipsets: 20 | 21 | - PCD8544 based LCDs, e.g Nokia 3110 and 5110 LCDs 22 | - ST7565R serial interface (used in Newhaven Display NHD-C12864WC-FSW-FBW-3V3-M) 23 | - NT75451 parallel interface (used on NGX BlueBoards) 24 | 25 | The following graphic displays have been physically tested with and confirmed working: 26 | 27 | - NHD-C12864WC-FSW-FBW-3V3-M 28 | - NHD-C12864A1Z-FSW-FBW-HTT 29 | - NHD-C12832A1Z-FSW-FBW-3V3 30 | - ZOLEN-12864-FFSSWE-NAA 31 | 32 | \section SupportedMicrocontrollers Supported Microcontrollers 33 | 34 | Current supported devices / microcontrollers: 35 | 36 | 37 | - Atmel AVR 8-bit 38 | - NXP LPC111x ARM Cortex-M0 39 | - NXP LPC11Uxx ARM Cortex-M0 40 | - ST STM32 F0 ARM Cortex-M0 41 | - ST STM32 F4 ARM Cortex-M4 42 | - Microchip PIC24H (and probably other 16-bit MCUs) 43 | 44 | \section CompilerSetup Compiler Setup 45 | 46 | The following symbols need to be set for the compiler used: 47 | 48 | Pick microcontroller type (pick one only): 49 | 50 | GLCD_DEVICE_LPX111X 51 | GLCD_DEVICE_LPX11UXX 52 | GLCD_DEVICE_AVR8 53 | GLCD_DEVICE_STM32F0XX 54 | GLCD_DEVICE_STM32F4XX 55 | GLCD_DEVICE_PIC24H 56 | 57 | Pick LCD controller type (pick one only): 58 | 59 | GLCD_CONTROLLER_PCD8544 60 | GLCD_CONTROLLER_ST7565R 61 | GLCD_CONTROLLER_NT75451 62 | 63 | If using a parallel interface LCD (e.g NT75451 on NGX BlueBoard): 64 | 65 | GLCD_USE_PARALLEL 66 | 67 | When using SPI controllers: 68 | 69 | GLCD_USE_SPI 70 | 71 | Note the SPI symbol isn't checked by the compiler, and it is fine if it is not used. 72 | It is for forward compatibility only. 73 | 74 | For the Newhaven displays using ST7565 based controllers listed above which have been tested as working, there 75 | are certain initialisation sequences which should be followed, and this may vary 76 | from display to display. To force a certain (and tested) initialisation 77 | sequence, define one of the following: 78 | 79 | GLCD_INIT_NHD_C12832A1Z_FSW_FBW_3V3 80 | GLCD_INIT_NHD_C12864A1Z_FSW_FBW_HTT 81 | GLCD_INIT_NHD_C12864WC_FSW_FBW_3V3_M 82 | 83 | If you don't specify a NHD model, ST7565 controller selection will default to `GLCD_INIT_NHD_C12864WC_FSW_FBW_3V3_M` sequence. 84 | This however may change in the future. 85 | 86 | \section ResetTime Reset time 87 | 88 | To set a reset time, used by the glcd_reset() function, set GLCD_RESET_TIME to desired duration in milliseconds. 89 | 90 | \section Contrast Contrast 91 | 92 | 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. 93 | 94 | \section LcdDimensions LCD Dimensions 95 | 96 | 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. 97 | 98 | \section CompilerSetup Compiler setup 99 | 100 | These symbols above need to be set in the configuration options of your IDE, usually 101 | in the "defined symbols" section, or they can be defined in a makefile 102 | as -D options. 103 | 104 | e.g `-DGLCD_DEVICE_LPC111X` 105 | 106 | Also, we need to set the width and height of the LCD in glcd.h 107 | 108 | \section CustomFonts Custom Fonts 109 | 110 | Custom fonts can be generated using the free MikroElektronika GLCD Font Creator tool. The standard 5x7 tiny text font is included together with also a few extra custom fonts to get you started. 111 | 112 | http://www.mikroe.com/eng/products/view/683/glcd-font-creator/ 113 | 114 | There is a [tutorial on my web site](http://agock.com/2012/07/making-custom-fonts-for-glcd-library/) on how to use this software. 115 | 116 | I also have been in the progress of working on a dedicated piece of software for generating fonts and bitmaps called [glcd-utils](https://github.com/andygock/glcd-utils). This is not very active at the moment, and is written in Qt Creator. This is set up specifically for glcd and works a lot better. However it is not documented and not really fit for public distribution at the moment. 117 | 118 | https://github.com/andygock/glcd-utils 119 | 120 | */ -------------------------------------------------------------------------------- /devices/STM32F10x.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file STM32F10x.c 3 | * \brief Device implementation for ST STM32F10x ARM Cortex-M3 MCUs 4 | * Requires the use of ST's Standard Peripheral Library 5 | * \author Andy Gock 6 | * \todo Code is untested! 7 | */ 8 | 9 | /* 10 | Copyright (c) 2012, Andy Gock 11 | 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are met: 16 | * Redistributions of source code must retain the above copyright 17 | notice, this list of conditions and the following disclaimer. 18 | * Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | * Neither the name of Andy Gock nor the 22 | names of its contributors may be used to endorse or promote products 23 | derived from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 26 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 29 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | #if defined(GLCD_DEVICE_STM32F10X) 37 | 38 | /* Includes from CMSIS and Peripheral Library */ 39 | #include "stm32f10x.h" 40 | 41 | /* Includes from GLCD */ 42 | #include "../glcd.h" 43 | #include "inc/STM32F10x.h" 44 | 45 | void glcd_init(void) 46 | { 47 | 48 | /* Initialisation of GPIO and SPI */ 49 | 50 | GPIO_InitTypeDef GPIO_InitStructure; 51 | SPI_InitTypeDef SPI_InitStructure; 52 | 53 | /* Set up GPIO pins */ 54 | 55 | /* Need to make start up the correct peripheral clocks */ 56 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE); 57 | 58 | /* SS pin */ 59 | GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_SS_PIN; 60 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 61 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 62 | GPIO_Init(CONTROLLER_SPI_SS_PORT, &GPIO_InitStructure); 63 | 64 | /* DC pin */ 65 | GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_DC_PIN; 66 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 67 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 68 | GPIO_Init(CONTROLLER_SPI_DC_PORT, &GPIO_InitStructure); 69 | 70 | /* RESET pin */ 71 | GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_RST_PIN; 72 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 73 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 74 | GPIO_Init(CONTROLLER_SPI_RST_PORT, &GPIO_InitStructure); 75 | 76 | /* Make sure chip is de-selected by default */ 77 | GLCD_DESELECT(); 78 | 79 | /* Set up GPIO for SPI pins */ 80 | GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_SCK_PIN | CONTROLLER_SPI_MISO_PIN | CONTROLLER_SPI_MOSI_PIN; 81 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 82 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 83 | GPIO_Init(CONTROLLER_SPI_PORT, &GPIO_InitStructure); 84 | 85 | /* Initialise SPI */ 86 | SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; 87 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 88 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; 89 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; 90 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; 91 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; 92 | SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; /* Set clock speed! */ 93 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; 94 | SPI_InitStructure.SPI_CRCPolynomial = 7; 95 | SPI_Init(CONTROLLER_SPI_NUMBER, &SPI_InitStructure); 96 | 97 | /* 98 | SPI_I2S_ITConfig(CONTROLLER_SPI_NUMBER, SPI_I2S_IT_RXNE, ENABLE); 99 | */ 100 | 101 | /* Enable SPI */ 102 | SPI_Cmd(CONTROLLER_SPI_NUMBER, ENABLE); 103 | 104 | /* Send reset pulse to LCD */ 105 | glcd_reset(); 106 | delay_ms(1); 107 | 108 | #if defined(GLCD_CONTROLLER_PCD8544) 109 | glcd_PCD8544_init(); 110 | 111 | #elif defined(GLCD_CONTROLLER_ST7565R) 112 | glcd_ST7565R_init(); 113 | 114 | /* Set all dots black and hold for 0.5s, then clear it, we do this so we can visually check init sequence is working */ 115 | glcd_all_on(); 116 | delay_ms(500); 117 | glcd_normal(); 118 | 119 | glcd_set_start_line(0); 120 | glcd_clear_now(); 121 | 122 | #else 123 | #error "Controller not supported by STM32F10x" 124 | 125 | #endif 126 | 127 | glcd_select_screen(glcd_buffer,&glcd_bbox); 128 | glcd_clear(); 129 | 130 | } 131 | 132 | void glcd_spi_write(uint8_t c) 133 | { 134 | 135 | GLCD_SELECT(); 136 | SPI_I2S_SendData(CONTROLLER_SPI_NUMBER, (uint16_t) c); 137 | 138 | /* Wait until entire byte has been read (which we discard anyway) */ 139 | while( SPI_I2S_GetFlagStatus(CONTROLLER_SPI_NUMBER,SPI_I2S_FLAG_RXNE) != SET ); 140 | 141 | GLCD_SELECT(); 142 | } 143 | 144 | void glcd_reset(void) 145 | { 146 | GLCD_SELECT(); 147 | GLCD_RESET_LOW(); 148 | delay_ms(GLCD_RESET_TIME); 149 | GLCD_RESET_HIGH(); 150 | GLCD_DESELECT(); 151 | } 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /glcd.c: -------------------------------------------------------------------------------- 1 | /** 2 | \file glcd.c 3 | \author Andy Gock 4 | \brief Basic GLCD functions affecting bounding box manipulation, 5 | clearing of screen and buffers, and basic scroll functions. 6 | */ 7 | 8 | /* 9 | Copyright (c) 2012, Andy Gock 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without 14 | modification, are permitted provided that the following conditions are met: 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | * Neither the name of Andy Gock nor the 21 | names of its contributors may be used to endorse or promote products 22 | derived from this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | #include "glcd.h" 39 | 40 | /** \addtogroup GlobalVars Global Variables 41 | * @{ 42 | */ 43 | 44 | /** 45 | * Screen buffer 46 | * 47 | * Requires at least one bit for every pixel (e.g 504 bytes for 48x84 LCD) 48 | */ 49 | uint8_t glcd_buffer[GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8]; 50 | 51 | /** 52 | * Keeps track of bounding box of area on LCD which need to be 53 | * updated next reresh cycle 54 | */ 55 | glcd_BoundingBox_t glcd_bbox; 56 | 57 | /** 58 | * Pointer to screen buffer currently in use. 59 | */ 60 | uint8_t *glcd_buffer_selected; 61 | 62 | /** 63 | * Pointer to bounding box currently in use. 64 | */ 65 | glcd_BoundingBox_t *glcd_bbox_selected; 66 | 67 | /** @} */ 68 | 69 | void glcd_update_bbox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) 70 | { 71 | /* Keep and check bounding box within limits of LCD screen dimensions */ 72 | if (xmin > (GLCD_LCD_WIDTH-1)) { 73 | xmin = GLCD_LCD_WIDTH-1; 74 | } 75 | if (xmax > (GLCD_LCD_WIDTH-1)) { 76 | xmax = GLCD_LCD_WIDTH-1; 77 | } 78 | 79 | if (ymin > (GLCD_LCD_HEIGHT-1)) { 80 | ymin = GLCD_LCD_HEIGHT-1; 81 | } 82 | if (ymax > (GLCD_LCD_HEIGHT-1)) { 83 | ymax = GLCD_LCD_HEIGHT-1; 84 | } 85 | 86 | /* Update the bounding box size */ 87 | if (xmin < glcd_bbox_selected->x_min) { 88 | glcd_bbox_selected->x_min = xmin; 89 | } 90 | if (xmax > glcd_bbox_selected->x_max) { 91 | glcd_bbox_selected->x_max = xmax; 92 | } 93 | if (ymin < glcd_bbox_selected->y_min) { 94 | glcd_bbox_selected->y_min = ymin; 95 | } 96 | if (ymax > glcd_bbox_selected->y_max) { 97 | glcd_bbox_selected->y_max = ymax; 98 | } 99 | } 100 | 101 | void glcd_reset_bbox() 102 | { 103 | /* Used after physically writing to the LCD */ 104 | glcd_bbox_selected->x_min = GLCD_LCD_WIDTH - 1; 105 | glcd_bbox_selected->x_max = 0; 106 | glcd_bbox_selected->y_min = GLCD_LCD_HEIGHT -1; 107 | glcd_bbox_selected->y_max = 0; 108 | } 109 | 110 | void glcd_bbox_reset() { 111 | glcd_reset_bbox(); 112 | } 113 | 114 | void glcd_bbox_refresh() { 115 | /* Marks bounding box as entire screen, so on next glcd_write(), it writes the entire buffer to the LCD */ 116 | glcd_bbox_selected->x_min = 0; 117 | glcd_bbox_selected->x_max = GLCD_LCD_WIDTH - 1; 118 | glcd_bbox_selected->y_min = 0; 119 | glcd_bbox_selected->y_max = GLCD_LCD_HEIGHT -1; 120 | } 121 | 122 | void glcd_clear(void) { 123 | memset(glcd_buffer_selected, 0x00, GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8); 124 | glcd_update_bbox(0,0,GLCD_LCD_WIDTH - 1,GLCD_LCD_HEIGHT - 1); 125 | glcd_write(); 126 | } 127 | 128 | void glcd_clear_buffer(void) { 129 | memset(glcd_buffer_selected, 0x00, GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8); 130 | glcd_update_bbox(0,0,GLCD_LCD_WIDTH - 1,GLCD_LCD_HEIGHT - 1); 131 | } 132 | 133 | void glcd_select_screen(uint8_t *buffer, glcd_BoundingBox_t *bbox) 134 | { 135 | glcd_buffer_selected = buffer; 136 | glcd_bbox_selected = bbox; 137 | } 138 | 139 | void glcd_scroll(int8_t x, int8_t y) 140 | { 141 | /** \todo Skeleton */ 142 | 143 | uint8_t row; 144 | 145 | for (row=0; row<(GLCD_LCD_HEIGHT / 8); row++) { 146 | uint8_t x; 147 | for (x=0; x 41 | 42 | 43 | /* SPIx Communication boards Interface */ 44 | #define SPIx SPI3 45 | #define SPIx_CLK RCC_APB1Periph_SPI3 46 | #define SPIx_CLK_INIT RCC_APB1PeriphClockCmd 47 | #define SPIx_PRESCALLER SPI_BaudRatePrescaler_8 48 | 49 | #define SPIx_SCK_PIN GPIO_PIN_3 50 | #define SPIx_SCK_GPIO_PORT GPIOB 51 | #define SPIx_SCK_GPIO_CLK RCC_AHB1Periph_GPIOB 52 | #define SPIx_SCK_SOURCE GPIO_PinSource3 53 | #define SPIx_SCK_AF GPIO_AF_SPI3 54 | 55 | #if 0 // Not using MISO pin for this LCD. 56 | #define SPIx_MISO_PIN GPIO_PIN_4 57 | #define SPIx_MISO_GPIO_PORT GPIOB 58 | #define SPIx_MISO_GPIO_CLK RCC_AHB1Periph_GPIOB 59 | #define SPIx_MISO_SOURCE GPIO_PinSource4 60 | #define SPIx_MISO_AF GPIO_AF_SPI3 61 | #endif 62 | 63 | #define SPIx_MOSI_PIN GPIO_PIN_5 64 | #define SPIx_MOSI_GPIO_PORT GPIOB 65 | #define SPIx_MOSI_GPIO_CLK RCC_AHB1Periph_GPIOB 66 | #define SPIx_MOSI_SOURCE GPIO_PinSource5 67 | #define SPIx_MOSI_AF GPIO_AF_SPI3 68 | 69 | /* Backlight config */ 70 | /* Comment the following line if you just want to use an 71 | * ON and OFF backlight (no brightness control) */ 72 | #define USE_TIMER_PWM 73 | //define BACKLIGHT_INVERT_OUT // Uncoment if your backlight turn on with a low value. 74 | #define LCD_LED_PIN GPIO_PIN_15 // Should be and TIMx_CHx pin. 75 | #define LCD_LED_PORT GPIOA 76 | #define LCD_LED_GPIO_RCC RCC_AHB1Periph_GPIOA 77 | #ifdef USE_TIMER_PWM 78 | #define LCD_LED_PinSource GPIO_PinSource15 79 | #define LCD_TIM TIM2 80 | #define LCD_AF GPIO_AF_TIM2 81 | #define LCD_TIM_OCInit TIM_OC1Init 82 | #define LCD_TIM_OCPreload TIM_OC1PreloadConfig 83 | #define LCD_TIM_RCC RCC_APB1Periph_TIM2 84 | #define LCD_TIM_PeriphClockCmd RCC_APB1PeriphClockCmd 85 | #define LCD_TIM_SetCompare TIM_SetCompare1 86 | #define LCD_TIM_Sys_Prescaller 1 // Nucleo board TIM2 clock is the same of systemcoreclock 87 | #endif 88 | 89 | 90 | 91 | #define CONTROLLER_SPI_SS_PORT GPIOB 92 | #define CONTROLLER_SPI_SS_PIN GPIO_PIN_8 93 | #define CONTROLLER_SPI_SS_RCC RCC_AHB1Periph_GPIOB 94 | #define CONTROLLER_SPI_DC_PORT GPIOB 95 | #define CONTROLLER_SPI_DC_PIN GPIO_PIN_4 96 | #define CONTROLLER_SPI_DC_RCC RCC_AHB1Periph_GPIOB 97 | #define CONTROLLER_SPI_RST_PORT GPIOB 98 | #define CONTROLLER_SPI_RST_PIN GPIO_PIN_9 99 | #define CONTROLLER_SPI_RST_RCC RCC_AHB1Periph_GPIOB 100 | 101 | 102 | #define GLCD_SELECT() GPIO_ResetBits(CONTROLLER_SPI_SS_PORT,CONTROLLER_SPI_SS_PIN) 103 | #define GLCD_DESELECT() GPIO_SetBits(CONTROLLER_SPI_SS_PORT,CONTROLLER_SPI_SS_PIN) 104 | #define GLCD_A0_LOW() GPIO_ResetBits(CONTROLLER_SPI_DC_PORT,CONTROLLER_SPI_DC_PIN) 105 | #define GLCD_A0_HIGH() GPIO_SetBits(CONTROLLER_SPI_DC_PORT,CONTROLLER_SPI_DC_PIN) 106 | #define GLCD_RESET_LOW() GPIO_ResetBits(CONTROLLER_SPI_RST_PORT,CONTROLLER_SPI_RST_PIN) 107 | #define GLCD_RESET_HIGH() GPIO_SetBits(CONTROLLER_SPI_RST_PORT,CONTROLLER_SPI_RST_PIN) 108 | 109 | /* RTOS delay function 110 | * Enable the following define to use a RTOS. 111 | * Update the call to the millisecond delay with the one of 112 | * your RTOS and add the includes in STM32F4.c */ 113 | #define GLCD_USE_RTOS 114 | 115 | #ifdef GLCD_USE_RTOS 116 | #define GLCD_RTOS_DELAY_FCN DelayTask(ms); 117 | #endif 118 | /* Function prototypes: */ 119 | void glcd_enable_backlight(FunctionalState state); 120 | #ifdef USE_TIMER_PWM 121 | void glcd_change_backlight(uint8_t value); 122 | #endif 123 | #else 124 | #error "Controller not supported by STM32F4XX" 125 | #endif 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /devices/STM32F0xx.c: -------------------------------------------------------------------------------- 1 | /** 2 | \file STM32F0xx.c 3 | \author Andy Gock 4 | \brief Functions specific to STM32 F0 ARM Cortex-M0 devices. 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #if defined(GLCD_DEVICE_STM32F0XX) 36 | 37 | /* Includes from CMSIS and Peripheral Library */ 38 | #include "stm32f0xx.h" 39 | #include "stm32f0xx_gpio.h" 40 | #include "stm32f0xx_spi.h" 41 | #include "stm32f0xx_rcc.h" 42 | #include "stm32f0xx_misc.h" 43 | 44 | /* Includes from GLCD */ 45 | #include "../glcd.h" 46 | #include "inc/STM32F0xx.h" 47 | 48 | void glcd_init(void) 49 | { 50 | 51 | /* Declare GPIO and SPI init structures */ 52 | GPIO_InitTypeDef GPIO_InitStructure; 53 | SPI_InitTypeDef SPI_InitStructure; 54 | /* NVIC_InitTypeDef NVIC_InitStructure; */ 55 | 56 | /* Initialise structures (which we will overide later) */ 57 | GPIO_StructInit(&GPIO_InitStructure); 58 | SPI_StructInit(&SPI_InitStructure); 59 | 60 | /* Need to make start up the correct peripheral clocks */ 61 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); 62 | 63 | /* SS pin */ 64 | GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_SS_PIN; 65 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; 66 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; 67 | GPIO_Init(CONTROLLER_SPI_SS_PORT, &GPIO_InitStructure); 68 | 69 | /* DC pin */ 70 | GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_DC_PIN; 71 | GPIO_Init(CONTROLLER_SPI_DC_PORT, &GPIO_InitStructure); 72 | 73 | /* RESET pin */ 74 | GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_RST_PIN; 75 | GPIO_Init(CONTROLLER_SPI_RST_PORT, &GPIO_InitStructure); 76 | 77 | /* Make sure chip is de-selected by default */ 78 | GLCD_DESELECT(); 79 | 80 | /* Set up GPIO for SPI pins */ 81 | GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_SCK_PIN | CONTROLLER_SPI_MISO_PIN | CONTROLLER_SPI_MOSI_PIN; 82 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; 83 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 84 | GPIO_Init(CONTROLLER_SPI_PORT, &GPIO_InitStructure); 85 | 86 | /* Configure alternate function mode for SPI pins */ 87 | GPIO_PinAFConfig(GPIOA,CONTROLLER_SPI_SCK_PINSRC,GPIO_AF_0); 88 | GPIO_PinAFConfig(GPIOA,CONTROLLER_SPI_MOSI_PINSRC,GPIO_AF_0); 89 | GPIO_PinAFConfig(GPIOA,CONTROLLER_SPI_MISO_PINSRC,GPIO_AF_0); 90 | 91 | /* Initialise SPI */ 92 | SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; 93 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 94 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; 95 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; 96 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; 97 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; 98 | SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; /* Set clock speed! */ 99 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; 100 | SPI_InitStructure.SPI_CRCPolynomial = 7; 101 | SPI_Init(CONTROLLER_SPI_NUMBER, &SPI_InitStructure); 102 | 103 | /* Enable SPI interupts */ 104 | /* 105 | SPI_I2S_ITConfig(CONTROLLER_SPI_NUMBER, SPI_I2S_IT_TXE, ENABLE); 106 | NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn; 107 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 108 | NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00; 109 | NVIC_Init(&NVIC_InitStructure); 110 | */ 111 | 112 | /* Enable SPI */ 113 | SPI_Cmd(CONTROLLER_SPI_NUMBER, ENABLE); 114 | 115 | #if defined(GLCD_CONTROLLER_PCD8544) 116 | /* Initialisation for PCD8544 controller */ 117 | glcd_PCD8544_init(); 118 | 119 | #else 120 | #error "Controller not supported by STM32F0xx" 121 | #endif 122 | 123 | glcd_select_screen((uint8_t *)&glcd_buffer,&glcd_bbox); 124 | glcd_clear(); 125 | 126 | } 127 | 128 | void glcd_spi_write(uint8_t c) 129 | { 130 | 131 | GLCD_SELECT(); 132 | SPI_SendData8(CONTROLLER_SPI_NUMBER, (uint16_t) c); 133 | 134 | /* Wait until entire byte has been read (which we discard anyway) */ 135 | while(SPI_I2S_GetFlagStatus(CONTROLLER_SPI_NUMBER, SPI_I2S_FLAG_BSY) != RESET); 136 | 137 | GLCD_DESELECT(); 138 | } 139 | 140 | void glcd_reset(void) 141 | { 142 | /* Toggle RST low to reset. Minimum pulse 100ns on datasheet. */ 143 | GLCD_SELECT(); 144 | GLCD_RESET_LOW(); 145 | delay_ms(GLCD_RESET_TIME); 146 | GLCD_RESET_HIGH(); 147 | GLCD_DESELECT(); 148 | } 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /devices/LPC11Uxx.c: -------------------------------------------------------------------------------- 1 | /** 2 | \file LPC11Uxx.c 3 | \author Andy Gock 4 | \brief Functions specific to LPC11Uxx devices. 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "../glcd.h" 36 | #include "LPC11Uxx.h" 37 | 38 | #if defined(GLCD_DEVICE_LPC11UXX) 39 | 40 | void glcd_init(void) 41 | { 42 | 43 | #if defined(GLCD_CONTROLLER_PCD8544) 44 | /* 45 | * Set up SPI (SSP) 46 | * Note: Max allowed SPI clock is 4 MHz from datasheet. 47 | */ 48 | 49 | /* Select SSP/SPI port */ 50 | SSP_IOConfig( CONTROLLER_SPI_PORT_NUMBER ); 51 | 52 | /* Initialise SSP/SPI port */ 53 | SSP_Init( CONTROLLER_SPI_PORT_NUMBER ); 54 | 55 | /* Above functions take care of SPI pins */ 56 | 57 | /* Set SS, DC and RST pins to output */ 58 | CONTROLLER_SS_PORT->DIR |= (1 << CONTROLLER_SS_PIN); 59 | CONTROLLER_DC_PORT->DIR |= (1 << CONTROLLER_DC_PIN); 60 | CONTROLLER_RST_PORT->DIR |= (1 << CONTROLLER_RST_PIN); 61 | 62 | /* Deselect LCD */ 63 | GLCD_DESELECT(); 64 | 65 | glcd_PCD8544_init(); 66 | 67 | glcd_select_screen(glcd_buffer,&glcd_bbox); 68 | 69 | glcd_clear(); 70 | 71 | #elif defined(GLCD_CONTROLLER_NT75451) 72 | /* Parallel interface controller used on NGX BlueBoards */ 73 | 74 | /* Set 4x control lines pins as output */ 75 | LPC_GPIO->DIR[CONTROLLER_LCD_EN_PORT] |= (1U<DIR[CONTROLLER_LCD_RW_PORT] |= (1U<DIR[CONTROLLER_LCD_RS_PORT] |= (1U<DIR[CONTROLLER_LCD_CS_PORT] |= (1U<DIR[CONTROLLER_LCD_D0_PORT] |= GLCD_PARALLEL_MASK; 85 | #else 86 | #error "Support of parallel data pins on different ports not supported." 87 | #endif 88 | 89 | glcd_NT75451_init(); 90 | 91 | /* Select default screen buffer */ 92 | glcd_select_screen(glcd_buffer,&glcd_bbox); 93 | 94 | /* Clear the screen buffer */ 95 | glcd_clear(); 96 | 97 | #else /* GLCD_CONTROLLER_PCD8544 */ 98 | #error "Controller not supported by LPC111x" 99 | #endif 100 | 101 | } 102 | 103 | #if defined(GLCD_USE_PARALLEL) 104 | 105 | /** Write byte via parallel interface */ 106 | void glcd_parallel_write(uint8_t c) 107 | { 108 | 109 | uint32_t port_output = \ 110 | ( ( (1U << 0) & c ? 1 : 0 ) << CONTROLLER_LCD_D0_PIN ) | \ 111 | ( ( (1U << 1) & c ? 1 : 0 ) << CONTROLLER_LCD_D1_PIN ) | \ 112 | ( ( (1U << 2) & c ? 1 : 0 ) << CONTROLLER_LCD_D2_PIN ) | \ 113 | ( ( (1U << 3) & c ? 1 : 0 ) << CONTROLLER_LCD_D3_PIN ) | \ 114 | ( ( (1U << 4) & c ? 1 : 0 ) << CONTROLLER_LCD_D4_PIN ) | \ 115 | ( ( (1U << 5) & c ? 1 : 0 ) << CONTROLLER_LCD_D5_PIN ) | \ 116 | ( ( (1U << 6) & c ? 1 : 0 ) << CONTROLLER_LCD_D6_PIN ) | \ 117 | ( ( (1U << 7) & c ? 1 : 0 ) << CONTROLLER_LCD_D7_PIN ); 118 | 119 | /* Perform the write */ 120 | 121 | /* Clear data bits to zero and set required bits as needed */ 122 | LPC_GPIO->CLR[CONTROLLER_LCD_D0_PORT] |= GLCD_PARALLEL_MASK; 123 | LPC_GPIO->SET[CONTROLLER_LCD_D0_PORT] |= port_output; 124 | 125 | GLCD_RW_LOW(); 126 | GLCD_CS_LOW(); 127 | GLCD_EN_HIGH(); 128 | 129 | /* Must hold for minimum 80 ns = ~12.5 MHz pulse */ 130 | 131 | /* Do whatever is needed for your MCU */ 132 | //glcd_delay(1); 133 | 134 | GLCD_EN_LOW(); 135 | GLCD_CS_HIGH(); 136 | GLCD_RW_HIGH(); 137 | 138 | } 139 | 140 | #else 141 | 142 | void glcd_spi_write(uint8_t c) 143 | { 144 | GLCD_SELECT(); 145 | SSP_Send(CONTROLLER_SPI_PORT_NUMBER,&c,1); 146 | GLCD_DESELECT(); 147 | } 148 | 149 | #endif /* GLCD_USE_PARALLEL */ 150 | 151 | void glcd_reset(void) 152 | { 153 | #if defined(GLCD_CONTROLLER_PCD8544) 154 | /* Toggle RST low to reset. Minimum pulse 100ns on datasheet. */ 155 | GLCD_SELECT(); 156 | GLCD_RESET_LOW(); 157 | delay_ms(GLCD_RESET_TIME); 158 | GLCD_RESET_HIGH(); 159 | GLCD_DESELECT(); 160 | 161 | #elif defined(GLCD_CONTROLLER_NT75451) 162 | /* No firmware reset possible with our test board (BlueBoard) */ 163 | 164 | #endif /* GLCD_CONTROLLER_PCD8544 */ 165 | } 166 | 167 | void glcd_delay(uint32_t count) 168 | { 169 | uint16_t j=0,i=0; 170 | 171 | for(j=0;jDATA &= ~(1 << CONTROLLER_SS_PIN) 67 | #define GLCD_DESELECT() CONTROLLER_SS_PORT->DATA |= (1 << CONTROLLER_SS_PIN) 68 | #define GLCD_DC_LOW() CONTROLLER_DC_PORT->DATA &= ~(1 << CONTROLLER_DC_PIN) 69 | #define GLCD_DC_HIGH() CONTROLLER_DC_PORT->DATA |= (1 << CONTROLLER_DC_PIN) 70 | #define GLCD_RESET_LOW() CONTROLLER_RST_PORT->DATA &= ~(1 << CONTROLLER_RST_PIN) 71 | #define GLCD_RESET_HIGH() CONTROLLER_RST_PORT->DATA |= (1 << CONTROLLER_RST_PIN) 72 | 73 | #else 74 | /* Parallel interface */ 75 | 76 | #define CONTROLLER_LCD_EN_PORT 0 77 | #define CONTROLLER_LCD_EN_PIN 12 /**< Read write enable pin */ 78 | #define CONTROLLER_LCD_RW_PORT 0 79 | #define CONTROLLER_LCD_RW_PIN 13 /**< Read write signal pin */ 80 | #define CONTROLLER_LCD_RS_PORT 0 81 | #define CONTROLLER_LCD_RS_PIN 14 /**< Command data select pin */ 82 | #define CONTROLLER_LCD_CS_PORT 1 83 | #define CONTROLLER_LCD_CS_PIN 13 /**< Chip select pin */ 84 | 85 | #define CONTROLLER_LCD_D0_PORT 1 86 | #define CONTROLLER_LCD_D1_PORT 1 87 | #define CONTROLLER_LCD_D2_PORT 1 88 | #define CONTROLLER_LCD_D3_PORT 1 89 | #define CONTROLLER_LCD_D4_PORT 1 90 | #define CONTROLLER_LCD_D5_PORT 1 91 | #define CONTROLLER_LCD_D6_PORT 1 92 | #define CONTROLLER_LCD_D7_PORT 1 93 | 94 | #define CONTROLLER_LCD_D0_PIN 19 95 | #define CONTROLLER_LCD_D1_PIN 20 96 | #define CONTROLLER_LCD_D2_PIN 21 97 | #define CONTROLLER_LCD_D3_PIN 22 98 | #define CONTROLLER_LCD_D4_PIN 26 99 | #define CONTROLLER_LCD_D5_PIN 27 100 | #define CONTROLLER_LCD_D6_PIN 28 101 | #define CONTROLLER_LCD_D7_PIN 31 102 | 103 | #if (CONTROLLER_LCD_D1_PORT == CONTROLLER_LCD_D0_PORT) && \ 104 | (CONTROLLER_LCD_D2_PORT == CONTROLLER_LCD_D0_PORT) && \ 105 | (CONTROLLER_LCD_D3_PORT == CONTROLLER_LCD_D0_PORT) && \ 106 | (CONTROLLER_LCD_D4_PORT == CONTROLLER_LCD_D0_PORT) && \ 107 | (CONTROLLER_LCD_D5_PORT == CONTROLLER_LCD_D0_PORT) && \ 108 | (CONTROLLER_LCD_D6_PORT == CONTROLLER_LCD_D0_PORT) && \ 109 | (CONTROLLER_LCD_D7_PORT == CONTROLLER_LCD_D0_PORT) 110 | /* All data pins are on the same port */ 111 | #define CONTROLLER_LCD_DATA_PORT 1 112 | 113 | #define GLCD_PARALLEL_MASK ( \ 114 | (1U<CLR[CONTROLLER_LCD_EN_PORT] |= (1U<SET[CONTROLLER_LCD_EN_PORT] |= (1U<CLR[CONTROLLER_LCD_RW_PORT] |= (1U<SET[CONTROLLER_LCD_RW_PORT] |= (1U<CLR[CONTROLLER_LCD_RS_PORT] |= (1U<SET[CONTROLLER_LCD_RS_PORT] |= (1U<CLR[CONTROLLER_LCD_CS_PORT] |= (1U<SET[CONTROLLER_LCD_CS_PORT] |= (1U<= 8) { 57 | return; 58 | } 59 | if (c < font_current.start_char || c > font_current.end_char) { 60 | c = '.'; 61 | } 62 | if ( line >= GLCD_LCD_HEIGHT / (font_current.height + 1) ) { 63 | return; 64 | } 65 | if ( (x+font_current.width) >= GLCD_LCD_WIDTH ) { 66 | return; 67 | } 68 | 69 | glcd_update_bbox(x, line*(font_current.height + 1), x+font_current.width, line*(font_current.height + 1) + (font_current.height + 1)); 70 | 71 | for ( i = 0; i < font_current.width; i++ ) { 72 | #if defined(GLCD_DEVICE_AVR8) 73 | glcd_buffer_selected[x + (line * GLCD_LCD_WIDTH)] = pgm_read_byte( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); 74 | #else 75 | glcd_buffer_selected[x + (line * GLCD_LCD_WIDTH)] = *( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); 76 | #endif 77 | x++; 78 | } 79 | } 80 | 81 | void glcd_tiny_draw_string(uint8_t x, uint8_t line, char *str) 82 | { 83 | if (font_current.height >= 8) { 84 | return; 85 | } 86 | while (*str) { 87 | glcd_tiny_draw_char(x, line, *str++); 88 | x += (font_current.width + 1); 89 | if ((x + font_current.width + 1) > GLCD_LCD_WIDTH) { 90 | x = 0; /* Ran out of this line */ 91 | line++; 92 | } 93 | if (line >= (GLCD_LCD_HEIGHT/(font_current.height + 1))) 94 | return; /* Ran out of space :( */ 95 | } 96 | } 97 | 98 | #if defined(GLCD_DEVICE_AVR8) 99 | void glcd_tiny_draw_string_P(uint8_t x, uint8_t line, PGM_P str) 100 | #else 101 | void glcd_tiny_draw_string_P(uint8_t x, uint8_t line, const char *str) 102 | #endif 103 | { 104 | if (font_current.height >= 8) { 105 | return; 106 | } 107 | while (1) { 108 | #if defined(GLCD_DEVICE_AVR8) 109 | char c = pgm_read_byte(str++); 110 | #else 111 | char c = *(str++); 112 | #endif 113 | if (!c) 114 | return; 115 | 116 | glcd_tiny_draw_char(x, line, c); 117 | 118 | x += (font_current.width + 1); 119 | if ((x + font_current.width + 1) > GLCD_LCD_WIDTH) { 120 | x = 0; /* Ran out of this line */ 121 | line++; 122 | } 123 | if (line >= (GLCD_LCD_HEIGHT/(font_current.height + 1))) 124 | return; /* Ran out of space :( */ 125 | } 126 | } 127 | 128 | void glcd_tiny_draw_string_ammend(char *str) { 129 | glcd_scroll_line(); 130 | glcd_tiny_draw_string(0, (GLCD_LCD_HEIGHT/8-1), str); 131 | glcd_write(); 132 | } 133 | 134 | void glcd_tiny_draw_string_ammend_P(const char *str) { 135 | glcd_scroll_line(); 136 | glcd_tiny_draw_string_P(0, (GLCD_LCD_HEIGHT/8-1), str); 137 | glcd_write(); 138 | } 139 | 140 | void glcd_tiny_invert_line(uint8_t line) 141 | { 142 | glcd_invert_area(0,line*8,GLCD_LCD_WIDTH-1,8); 143 | } 144 | 145 | void glcd_tiny_draw_char_xy(uint8_t x, uint8_t y, char c) 146 | { 147 | uint8_t i; 148 | uint8_t xvar, yvar; 149 | uint8_t dat; 150 | 151 | /* Only works for fonts < 8 bits in height */ 152 | 153 | /* Check all important bounds requirements are okay */ 154 | if ( (y >= GLCD_LCD_HEIGHT) || ((x+font_current.width) >= GLCD_LCD_WIDTH) || (font_current.height >= 8) || font_current.table_type != STANG) { 155 | return; 156 | } 157 | if (c < font_current.start_char || c > font_current.end_char) { 158 | c = '.'; 159 | } 160 | 161 | xvar = x; 162 | 163 | for ( i = 0; i < font_current.width; i++ ) { 164 | #if defined(GLCD_DEVICE_AVR8) 165 | dat = pgm_read_byte( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); 166 | #else 167 | dat = *( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); 168 | #endif 169 | for (yvar = 0; yvar < font_current.height; yvar++) { 170 | glcd_set_pixel(xvar,y+yvar, (dat & (1< 63) { 31 | glcd_command(63); 32 | } else { 33 | glcd_command(val); 34 | } 35 | return; 36 | } 37 | 38 | void glcd_power_down(void) 39 | { 40 | /* Command sequence as in ST7565 datasheet */ 41 | glcd_command(0xac); // Static indicator off 42 | glcd_command(0x00); // Static indicator register, not blinking 43 | glcd_command(0xae); // Display OFF 44 | glcd_command(0xa5); // Display all points ON 45 | 46 | /* Display is now in sleep mode */ 47 | } 48 | 49 | void glcd_power_up(void) 50 | { 51 | glcd_command(0xa4); // Display all points OFF 52 | glcd_command(0xad); // Static indicator ON 53 | glcd_command(0x00); // Static indicator register, not Blinking 54 | glcd_command(0xaf); 55 | 56 | return; 57 | } 58 | 59 | void glcd_set_y_address(uint8_t y) 60 | { 61 | glcd_command(ST7565R_PAGE_ADDRESS_SET | (0x0F & y)); /* 0x0F = 0b00001111 */ 62 | } 63 | 64 | void glcd_set_x_address(uint8_t x) 65 | { 66 | glcd_set_column_upper(x); 67 | glcd_set_column_lower(x); 68 | } 69 | 70 | void glcd_all_on(void) 71 | { 72 | glcd_command(ST7565R_DISPLAY_ALL_ON); 73 | } 74 | 75 | void glcd_normal(void) 76 | { 77 | glcd_command(ST7565R_DISPLAY_NORMAL); 78 | } 79 | 80 | void glcd_set_column_upper(uint8_t addr) 81 | { 82 | glcd_command(ST7565R_COLUMN_ADDRESS_SET_UPPER | (addr >> 4)); 83 | } 84 | 85 | void glcd_set_column_lower(uint8_t addr) 86 | { 87 | glcd_command(ST7565R_COLUMN_ADDRESS_SET_LOWER | (0x0f & addr)); 88 | } 89 | 90 | void glcd_set_start_line(uint8_t addr) 91 | { 92 | glcd_command( ST7565R_SET_START_LINE | (0x3F & addr)); /* 0x3F == 0b00111111 */ 93 | } 94 | 95 | /** Clear the display immediately, does not buffer */ 96 | void glcd_clear_now(void) 97 | { 98 | uint8_t page; 99 | for (page = 0; page < GLCD_NUMBER_OF_BANKS; page++) { 100 | uint8_t col; 101 | glcd_set_y_address(page); 102 | glcd_set_x_address(0); 103 | for (col = 0; col < GLCD_NUMBER_OF_COLS; col++) { 104 | glcd_data(0); 105 | } 106 | } 107 | } 108 | 109 | void glcd_pattern(void) 110 | { 111 | uint8_t page; 112 | for (page = 0; page < GLCD_NUMBER_OF_BANKS; page++) { 113 | uint8_t col; 114 | glcd_set_y_address(page); 115 | glcd_set_x_address(0); 116 | for (col = 0; col < GLCD_NUMBER_OF_COLS; col++) { 117 | glcd_data( (col / 8 + 2) % 2 == 1 ? 0xff : 0x00 ); 118 | } 119 | } 120 | } 121 | 122 | void glcd_write() 123 | { 124 | 125 | uint8_t bank; 126 | 127 | for (bank = 0; bank < GLCD_NUMBER_OF_BANKS; bank++) { 128 | /* Each bank is a single row 8 bits tall */ 129 | uint8_t column; 130 | 131 | if (glcd_bbox_selected->y_min >= (bank+1)*8) { 132 | continue; /* Skip the entire bank */ 133 | } 134 | 135 | if (glcd_bbox_selected->y_max < bank*8) { 136 | break; /* No more banks need updating */ 137 | } 138 | 139 | glcd_set_y_address(bank); 140 | glcd_set_x_address(glcd_bbox_selected->x_min); 141 | 142 | for (column = glcd_bbox_selected->x_min; column <= glcd_bbox_selected->x_max; column++) 143 | { 144 | glcd_data( glcd_buffer_selected[GLCD_NUMBER_OF_COLS * bank + column] ); 145 | } 146 | } 147 | 148 | glcd_reset_bbox(); 149 | 150 | } 151 | 152 | void glcd_ST7565R_init(void) { 153 | 154 | #if defined(GLCD_INIT_NHD_C12832A1Z_FSW_FBW_3V3) 155 | 156 | /* Init sequence based on datasheet example code for NHD-C12832A1Z-FSW-FBW-3V3 */ 157 | /* Datasheet says max SCK frequency 20MHz for this LCD */ 158 | /* We use "reverse direction" for common output mode, as opposed to datasheet specifying "normal direction" */ 159 | 160 | glcd_command(0xa0); /* ADC select in normal mode */ 161 | glcd_command(0xae); /* Display OFF */ 162 | glcd_command(0xc8); /* Common output mode select: reverse direction (last 3 bits are ignored) */ 163 | glcd_command(0xa2); /* LCD bias set at 1/9 */ 164 | glcd_command(0x2f); /* Power control set to operating mode: 7 */ 165 | glcd_command(0x21); /* Internal resistor ratio, set to: 1 */ 166 | glcd_set_contrast(40); /* Set contrast, value experimentally determined, can set to 6-bit value, 0 to 63 */ 167 | glcd_command(0xaf); /* Display on */ 168 | 169 | #elif defined(GLCD_INIT_NHD_C12864A1Z_FSW_FBW_HTT) 170 | 171 | /* Init sequence based on datasheet example code for NHD-C12864A1Z-FSW-FBW-HTT */ 172 | /* Datasheet says max SCK frequency 2.5MHz for this LCD */ 173 | /* We use "reverse direction" for common output mode, as opposed to datasheet specifying "normal direction" */ 174 | 175 | glcd_command(0xa0); /* ADC select in normal mode */ 176 | glcd_command(0xae); /* Display OFF */ 177 | glcd_command(0xc8); /* Common output mode select: reverse direction (last 3 bits are ignored) */ 178 | glcd_command(0xa2); /* LCD bias set at 1/9 */ 179 | glcd_command(0x2f); /* Power control set to operating mode: 7 */ 180 | glcd_command(0x26); /* Internal resistor ratio, set to: 6 */ 181 | glcd_set_contrast(20); /* Set contrast, value experimentally determined */ 182 | glcd_command(0xaf); /* Display on */ 183 | 184 | #elif defined(GLCD_INIT_NHD_C12864WC_FSW_FBW_3V3_M) 185 | 186 | /* Init sequence for NHD-C12864WC-FSW-FBW-3V3-M */ 187 | 188 | glcd_command(ST7565R_RESET); /* Internal reset */ 189 | glcd_command(0xa2); /* 1/9 bias */ 190 | glcd_command(0xa0); /* ADC select, normal */ 191 | glcd_command(0xc8); /* Com output reverse */ 192 | glcd_command(0xa4); /* Display all points normal */ 193 | glcd_command(0x40); /* Display start line set */ 194 | glcd_command(0x25); /* Internal resistor ratio */ 195 | glcd_set_contrast(45); /* Set contrast value, experimentally determined, value 0 to 63 */ 196 | glcd_command(0x2f); /* Power controller set */ 197 | glcd_command(0xaf); /* Display on */ 198 | 199 | #elif defined(GLCD_INIT_ZOLEN_12864_FFSSWE_NAA) 200 | /* Init sequence for Zolen 128x64 module with 201 | * size 40x35mm. Chip ST7567 */ 202 | 203 | glcd_command(0xa0); /* ADC select in normal mode */ 204 | glcd_command(0xae); /* Display OFF */ 205 | glcd_command(0xc8); /* Common output mode select: reverse direction (last 3 bits are ignored) */ 206 | glcd_command(0xa3); /* LCD bias set at 1/9 */ 207 | glcd_command(0x2f); /* Power control set to operating mode: 7 */ 208 | glcd_command(0x24); /* Internal resistor ratio, set to: 6 */ 209 | glcd_set_contrast(20); /* Set contrast, value experimentally determined, value 0 to 63 */ 210 | glcd_command(0xaf); /* Display on */ 211 | 212 | #else 213 | 214 | /* Default init sequence */ 215 | /* Currently just set the same as GLCD_INIT_NHD_C12864A1Z_FSW_FBW_HTT */ 216 | 217 | glcd_command(0xa0); /* ADC select in normal mode */ 218 | glcd_command(0xae); /* Display OFF */ 219 | glcd_command(0xc8); /* Common output mode select: reverse direction (last 3 bits are ignored) */ 220 | glcd_command(0xa2); /* LCD bias set at 1/9 */ 221 | glcd_command(0x2f); /* Power control set to operating mode: 7 */ 222 | glcd_command(0x26); /* Internal resistor ratio, set to: 6 */ 223 | glcd_set_contrast(20); /* Set contrast, value experimentally determined, value 0 to 63 */ 224 | glcd_command(0xaf); /* Display on */ 225 | 226 | #endif 227 | 228 | } 229 | #endif /* defined(GLCD_CONTROLLER_ST7565R) */ 230 | -------------------------------------------------------------------------------- /devices/PIC24H.c: -------------------------------------------------------------------------------- 1 | /** 2 | \file PIC24H.c 3 | \brief Functions relating to Microchip PIC24H (16-bit). 4 | For use with xc16 compiler. 5 | \author Andy Gock 6 | */ 7 | 8 | /* 9 | Copyright (c) 2013, Andy Gock 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without 14 | modification, are permitted provided that the following conditions are met: 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | * Neither the name of Andy Gock nor the 21 | names of its contributors may be used to endorse or promote products 22 | derived from this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | #include "../glcd.h" 36 | 37 | #if defined(GLCD_DEVICE_USER) 38 | #include "glcd_user_config.h" 39 | #include "glcd_user_config.c" 40 | #else 41 | 42 | #include "PIC24H.h" 43 | 44 | #if defined(GLCD_DEVICE_PIC24H) 45 | 46 | void glcd_init(void) 47 | { 48 | 49 | #if defined(GLCD_CONTROLLER_PCD8544) 50 | 51 | /* Set up remappable outputs for PIC24H, SPI: DO and SCK */ 52 | OSCCONbits.IOLOCK = 0; 53 | REGISTER_MAP_SPI_DO = 0b00111; /* Set as SPI DO */ 54 | REGISTER_MAP_SPI_SCK = 0b01000; /* Set as SCK */ 55 | OSCCONbits.IOLOCK = 1; 56 | 57 | /* Set DO and SCK pins as output */ 58 | CONTROLLER_MOSI_TRIS = 0; 59 | CONTROLLER_SCK_TRIS = 0; 60 | 61 | /* If the pins is also an ADC port, set these as digital mode */ 62 | // Do we really need to do this, or will setting RPxR deal with this 63 | //_PCFG9 = 1; 64 | //_PCFG10 = 1; 65 | 66 | /* Set SS, DC and RST pins as output */ 67 | CONTROLLER_SS_TRIS = 0; 68 | CONTROLLER_DC_TRIS = 0; 69 | CONTROLLER_RST_TRIS = 0; 70 | 71 | /* Deselect LCD */ 72 | GLCD_DESELECT(); 73 | 74 | /* SPI setup based on sample code from datasheet */ 75 | /* The following code shows the SPI register configuration for Master mode */ 76 | IFS0bits.SPI1IF = 0; /* Clear the Interrupt Flag */ 77 | IEC0bits.SPI1IE = 0; /* Disable the Interrupt */ 78 | 79 | /* SPI1CON1 Register Settings */ 80 | SPI1CON1bits.DISSCK = 0; /* Internal Serial Clock is Enabled */ 81 | SPI1CON1bits.DISSDO = 0; /* SDOx pin is controlled by the module */ 82 | SPI1CON1bits.MODE16 = 0; /* Communication is word-wide (16 bits) */ 83 | SPI1CON1bits.SMP = 0; /* Input data is sampled at the middle of data */ 84 | SPI1CON1bits.CKE = 0; /* Serial output data changes on transition */ 85 | SPI1CON1bits.CKP = 0; /* Idle state for clock is a low level */ 86 | SPI1CON1bits.PPRE = 0b11; /* Primary prescale = 1:1 */ 87 | SPI1CON1bits.SPRE = 0b001; /* Secondary prescale = 4:1 */ 88 | SPI1CON1bits.MSTEN = 1; /* Master mode Enabled */ 89 | SPI1STATbits.SPIEN = 1; /* Enable SPI module */ 90 | 91 | /* Interrupt Controller Settings */ 92 | // we're not using interrupts to handle SPI 93 | //IFS0bits.SPI1IF = 0; /* Clear the Interrupt Flag */ 94 | //IEC0bits.SPI1IE = 1; /* Enable the Interrupt */ 95 | 96 | /* Send reset pulse to LCD */ 97 | glcd_reset(); 98 | 99 | /* Initialise the display */ 100 | glcd_PCD8544_init(); 101 | 102 | /* Select screen buffer */ 103 | glcd_select_screen(glcd_buffer,&glcd_bbox); 104 | 105 | /* Clear screen, we are now ready to go */ 106 | glcd_clear(); 107 | 108 | #elif defined(GLCD_CONTROLLER_ST7565R) 109 | 110 | /* Code tested with Newhaven Display NHD-C12832A1Z-FSW-FBW-3V3 */ 111 | 112 | /* Set up remappable outputs for PIC24H, SPI: DO and SCK */ 113 | OSCCONbits.IOLOCK = 0; 114 | REGISTER_MAP_SPI_DO = 0b00111; /* Set as SPI DO */ 115 | REGISTER_MAP_SPI_SCK = 0b01000; /* Set as SCK */ 116 | OSCCONbits.IOLOCK = 1; 117 | 118 | /* Set DO and SCK pins as output */ 119 | CONTROLLER_MOSI_TRIS = 0; 120 | CONTROLLER_SCK_TRIS = 0; 121 | 122 | /* Set SS, DC and A0 pins as output */ 123 | CONTROLLER_SS_TRIS = 0; 124 | CONTROLLER_A0_TRIS = 0; 125 | CONTROLLER_RST_TRIS = 0; 126 | 127 | /* Deselect LCD */ 128 | GLCD_DESELECT(); 129 | 130 | /* SPI setup based on sample code from datasheet */ 131 | /* The following code shows the SPI register configuration for Master mode */ 132 | IFS0bits.SPI1IF = 0; /* Clear the Interrupt Flag */ 133 | IEC0bits.SPI1IE = 0; /* Disable the Interrupt */ 134 | 135 | /* SPI1CON1 Register Settings */ 136 | SPI1CON1bits.DISSCK = 0; /* Internal Serial Clock is Enabled */ 137 | SPI1CON1bits.DISSDO = 0; /* SDOx pin is controlled by the module */ 138 | SPI1CON1bits.MODE16 = 0; /* Communication is word-wide (16 bits) */ 139 | SPI1CON1bits.SMP = 0; /* Input data is sampled at the middle of data */ 140 | SPI1CON1bits.CKE = 0; /* Serial output data changes on transition */ 141 | SPI1CON1bits.CKP = 0; /* Idle state for clock is a low level */ 142 | 143 | /* Set SPI prescale, this is important make sure SPI click is below datasheets specified max clock speed */ 144 | 145 | #if defined(GLCD_INIT_NHD_C12832A1Z_FSW_FBW_3V3) 146 | /* Total prescale = 1x7 = 7 */ 147 | /* This LCD can handle fairly high clocks, but you'll need to check your FCY and adjust as required */ 148 | SPI1CON1bits.PPRE = 0b11; 149 | SPI1CON1bits.SPRE = 0b001; 150 | #else 151 | /* Total prescale = 4x3 = 12 */ 152 | SPI1CON1bits.PPRE = 0b10; /* Primary prescale 0b11=1:1, 0b10=4:1, 0b01=16:1, 0b00=64:1 */ 153 | SPI1CON1bits.SPRE = 0b101; /* Secondary prescale 0b111=1:1 0b110=2:1 ... 0b001=7:1, 0b000=8:1 */ 154 | #endif 155 | 156 | SPI1CON1bits.MSTEN = 1; /* Master mode Enabled */ 157 | SPI1STATbits.SPIEN = 1; /* Enable SPI module */ 158 | 159 | /* Send reset pulse to LCD */ 160 | glcd_reset(); 161 | delay_ms(1); 162 | 163 | /* Begin sending data for initialisation sequence */ 164 | glcd_ST7565R_init(); 165 | 166 | /* Set all dots black and hold for 0.5s, then clear it, we do this so we can visually check init sequence is working */ 167 | glcd_all_on(); 168 | delay_ms(500); 169 | glcd_normal(); 170 | 171 | glcd_set_start_line(0); 172 | glcd_clear_now(); 173 | 174 | glcd_select_screen(glcd_buffer,&glcd_bbox); 175 | 176 | glcd_clear(); 177 | 178 | #else 179 | #error "Controller not supported" 180 | #endif /* GLCD_CONTROLLER_* */ 181 | 182 | } 183 | 184 | void glcd_spi_write(uint8_t c) 185 | { 186 | GLCD_SELECT(); 187 | 188 | while (SPI1STATbits.SPITBF); /* Loop until TX buffer is empty */ 189 | SPI1BUF = (c & 0x00FF); /* Write data to be transmitted */ 190 | while(!SPI1STATbits.SPIRBF); /* Wait until TX finished */ 191 | 192 | uint8_t read; 193 | read = SPI1BUF; /* Throw away the data (not sure if this is neccesary, to force reading of SPI1BUF) */ 194 | 195 | GLCD_DESELECT(); 196 | } 197 | 198 | void glcd_reset(void) 199 | { 200 | /* Toggle RST low to reset. Minimum pulse 100ns on datasheet. */ 201 | GLCD_SELECT(); 202 | GLCD_RESET_LOW(); 203 | __delay_ms(GLCD_RESET_TIME); 204 | GLCD_RESET_HIGH(); 205 | GLCD_DESELECT(); 206 | } 207 | 208 | #endif /* defined(GLCD_DEVICE_PIC24H) */ 209 | 210 | #endif /* GLCD_DEVICE_USER */ 211 | -------------------------------------------------------------------------------- /fonts/Bebas_Neue20x36_Bold_Numbers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Bebas_Neue20x36_Numbers.h 3 | * 4 | * Created: 30/03/2012 1:51:48 AM 5 | * Author: andy 6 | */ 7 | 8 | 9 | #ifndef BEBAS_NEUE20X36_BOLD_NUMBERS_H_ 10 | #define BEBAS_NEUE20X36_BOLD_NUMBERS_H_ 11 | 12 | 13 | //WARNING: This Font Require X-GLCD Lib. 14 | // You can not use it with MikroE GLCD Lib. 15 | 16 | //Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0 17 | //MikroElektronika 2011 18 | //http://www.mikroe.com 19 | 20 | //GLCD FontName : Bebas_Neue20x36 21 | //GLCD FontSize : 20 x 36 22 | 23 | static const char Bebas_Neue20x36_Bold_Numbers[] PROGMEM = { 24 | 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char . 25 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x00, 0xFC, 0x07, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xF8, 0xFF, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x00, 0xE0, 0xFF, 0x3F, 0x00, 0x00, 0xF8, 0xFF, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x00, 0xC0, 0xFF, 0x7F, 0x00, 0x00, 0xF8, 0xFF, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0xFE, 0x7F, 0x00, 0x00, 0x00, 0xFE, 0x0F, 0x00, 0x00, 0x00, 0xFE, 0x03, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, // Code for char / 26 | 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x7F, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0x01, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x3F, 0x00, 0x00, 0xC0, 0x0F, 0x1F, 0x00, 0x00, 0x80, 0x0F, 0x3F, 0x00, 0x00, 0xC0, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0xF8, 0xFF, 0xFF, 0xFF, 0x01, 0xE0, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 0 27 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 1 28 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0xF0, 0x07, 0xF8, 0x0F, 0x00, 0xFE, 0x07, 0xFC, 0x0F, 0x00, 0xFF, 0x07, 0xFE, 0x0F, 0xC0, 0xFF, 0x07, 0xFE, 0x0F, 0xE0, 0xFF, 0x07, 0xFE, 0x0F, 0xF0, 0xFF, 0x07, 0xFF, 0x0F, 0xF8, 0xFF, 0x07, 0x3F, 0x00, 0xFE, 0xCF, 0x07, 0x1F, 0x00, 0xFF, 0xC3, 0x07, 0x1F, 0x80, 0xFF, 0xC1, 0x07, 0x3F, 0xF0, 0x7F, 0xC0, 0x07, 0xFF, 0xFF, 0x3F, 0xC0, 0x07, 0xFF, 0xFF, 0x1F, 0xC0, 0x07, 0xFE, 0xFF, 0x0F, 0xC0, 0x07, 0xFE, 0xFF, 0x03, 0xC0, 0x07, 0xFC, 0xFF, 0x01, 0xC0, 0x07, 0xF8, 0x7F, 0x00, 0xC0, 0x07, 0xE0, 0x0F, 0x00, 0x00, 0x00, // Code for char 2 29 | 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x7F, 0x00, 0xF8, 0x07, 0x00, 0xFF, 0x01, 0xFC, 0x07, 0x00, 0xFF, 0x03, 0xFE, 0x07, 0x00, 0xFF, 0x07, 0xFE, 0x07, 0x00, 0xFF, 0x07, 0xFF, 0x87, 0x0F, 0xFF, 0x0F, 0xFF, 0x87, 0x0F, 0xFF, 0x0F, 0x3F, 0x80, 0x0F, 0xC0, 0x0F, 0x1F, 0x80, 0x0F, 0x80, 0x0F, 0x3F, 0xC0, 0x1F, 0xC0, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFC, 0xFF, 0xFD, 0xFF, 0x03, 0xF8, 0xFF, 0xF8, 0xFF, 0x01, 0xE0, 0x1F, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 3 30 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1F, 0x00, 0x00, 0x00, 0xF0, 0x1F, 0x00, 0x00, 0x00, 0xFC, 0x1F, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0xF8, 0xFF, 0x1F, 0x00, 0x00, 0xFF, 0xFF, 0x1F, 0x00, 0xC0, 0xFF, 0x3F, 0x1F, 0x00, 0xF0, 0xFF, 0x0F, 0x1F, 0x00, 0xFE, 0xFF, 0x03, 0x1F, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, // Code for char 4 31 | 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x7E, 0x00, 0xFE, 0xFF, 0x1F, 0xFE, 0x01, 0xFE, 0xFF, 0x1F, 0xFE, 0x03, 0xFE, 0xFF, 0x1F, 0xFE, 0x07, 0xFE, 0xFF, 0x1F, 0xFE, 0x07, 0xFE, 0xFF, 0x1F, 0xFE, 0x0F, 0xFE, 0xFF, 0x1F, 0xFE, 0x0F, 0xFE, 0xE7, 0x03, 0xC0, 0x0F, 0x3E, 0xF0, 0x01, 0x80, 0x0F, 0x3E, 0xF0, 0x03, 0xC0, 0x0F, 0x3E, 0xF0, 0xFF, 0xFF, 0x0F, 0x3E, 0xF0, 0xFF, 0xFF, 0x0F, 0x3E, 0xF0, 0xFF, 0xFF, 0x07, 0x3E, 0xE0, 0xFF, 0xFF, 0x07, 0x3E, 0xE0, 0xFF, 0xFF, 0x03, 0x3E, 0xC0, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 5 32 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x7F, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0x01, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x3F, 0xC0, 0x07, 0xC0, 0x0F, 0x1F, 0xE0, 0x03, 0x80, 0x0F, 0x3F, 0xE0, 0x07, 0xC0, 0x0F, 0x3F, 0xE0, 0xFF, 0xFF, 0x0F, 0xFF, 0xE3, 0xFF, 0xFF, 0x0F, 0xFE, 0xE3, 0xFF, 0xFF, 0x07, 0xFE, 0xC3, 0xFF, 0xFF, 0x07, 0xFE, 0xC3, 0xFF, 0xFF, 0x03, 0xFC, 0x83, 0xFF, 0xFF, 0x01, 0xF8, 0x03, 0xFE, 0x7F, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, // Code for char 6 33 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x06, 0x3E, 0x00, 0x00, 0xE0, 0x07, 0x3E, 0x00, 0x00, 0xFE, 0x07, 0x3E, 0x00, 0xE0, 0xFF, 0x07, 0x3E, 0x00, 0xFC, 0xFF, 0x07, 0x3E, 0xC0, 0xFF, 0xFF, 0x07, 0x3E, 0xFC, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0x3F, 0x00, 0xFE, 0xFF, 0xFF, 0x03, 0x00, 0xFE, 0xFF, 0x3F, 0x00, 0x00, 0xFE, 0xFF, 0x07, 0x00, 0x00, 0xFE, 0x7F, 0x00, 0x00, 0x00, 0xFE, 0x07, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, // Code for char 7 34 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x1F, 0xC0, 0x3F, 0x00, 0xF8, 0x7F, 0xF8, 0xFF, 0x01, 0xFC, 0xFF, 0xFD, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x7F, 0xC0, 0x3F, 0xC0, 0x0F, 0x1F, 0x80, 0x0F, 0x80, 0x0F, 0x1F, 0x80, 0x0F, 0x80, 0x0F, 0x1F, 0x80, 0x0F, 0x80, 0x0F, 0x7F, 0xC0, 0x3F, 0xE0, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFC, 0xFF, 0xFD, 0xFF, 0x03, 0xF8, 0x7F, 0xF8, 0xFF, 0x01, 0xC0, 0x1F, 0xC0, 0x3F, 0x00, // Code for char 8 35 | 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0xE0, 0xFF, 0x07, 0xFC, 0x01, 0xF8, 0xFF, 0x1F, 0xFC, 0x03, 0xFC, 0xFF, 0x3F, 0xFC, 0x07, 0xFE, 0xFF, 0x3F, 0xFC, 0x07, 0xFE, 0xFF, 0x7F, 0xFC, 0x07, 0xFF, 0xFF, 0x7F, 0xFC, 0x0F, 0xFF, 0xFF, 0x7F, 0xC0, 0x0F, 0x3F, 0x00, 0x7E, 0xC0, 0x0F, 0x1F, 0x00, 0x7C, 0x80, 0x0F, 0x3F, 0x00, 0x3E, 0xC0, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0xF8, 0xFF, 0xFF, 0xFF, 0x01, 0xE0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Code for char 9 36 | }; 37 | 38 | 39 | 40 | 41 | 42 | #endif /* BEBAS_NEUE20X36_NUMBERS_H_ */ 43 | -------------------------------------------------------------------------------- /graphics.c: -------------------------------------------------------------------------------- 1 | /** 2 | \file graphics.c 3 | \brief Functions relating to graphics. e.g drawing lines, rectangles, circles etc. 4 | \author Andy Gock 5 | 6 | Some functions based on Limor Fried's PCD8544 Arduino library. 7 | 8 | */ 9 | 10 | /* 11 | Copyright (c) 2012, Andy Gock 12 | 13 | Copyright (c) 2012, Adafruit Industries 14 | 15 | All rights reserved. 16 | 17 | Redistribution and use in source and binary forms, with or without 18 | modification, are permitted provided that the following conditions are met: 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | * Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in the 23 | documentation and/or other materials provided with the distribution. 24 | * Neither the name of Andy Gock nor the 25 | names of its contributors may be used to endorse or promote products 26 | derived from this software without specific prior written permission. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 29 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 30 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 32 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 33 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 35 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include "glcd.h" 44 | 45 | /* Based on PCD8544 library by Limor Fried */ 46 | void glcd_set_pixel(uint8_t x, uint8_t y, uint8_t color) { 47 | if (x > (GLCD_LCD_WIDTH-1) || y > (GLCD_LCD_HEIGHT-1)) { 48 | /* don't do anything if x/y is outside bounds of display size */ 49 | return; 50 | } 51 | 52 | if (color) { 53 | /* Set black */ 54 | glcd_buffer[x+ (y/8)*GLCD_LCD_WIDTH] |= ( 1 << (y%8)); 55 | } else { 56 | /* Set white */ 57 | glcd_buffer[x+ (y/8)*GLCD_LCD_WIDTH] &= ~ (1 << (y%8)); 58 | } 59 | 60 | glcd_update_bbox(x,y,x,y); 61 | } 62 | 63 | /* Based on PCD8544 library by Limor Fried */ 64 | uint8_t glcd_get_pixel(uint8_t x, uint8_t y) { 65 | if ((x >= GLCD_LCD_WIDTH) || (y >= GLCD_LCD_HEIGHT)) { 66 | return 0; 67 | } 68 | 69 | if ( glcd_buffer[x+ (y/8)*GLCD_LCD_WIDTH] & ( 1 << (y%8)) ) { 70 | return 1; 71 | } else { 72 | return 0; 73 | } 74 | } 75 | 76 | void glcd_invert_pixel(uint8_t x, uint8_t y) { 77 | if ((x >= GLCD_LCD_WIDTH) || (y >= GLCD_LCD_HEIGHT)) { 78 | return; 79 | } 80 | glcd_update_bbox(x,y,x,y); 81 | glcd_buffer[x+ (y/8)*GLCD_LCD_WIDTH] ^= ( 1 << (y%8)); 82 | } 83 | 84 | /* Bresenham's algorithm - based on PCD8544 library Limor Fried */ 85 | void glcd_draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color) { 86 | uint8_t steep = abs(y1 - y0) > abs(x1 - x0); 87 | uint8_t dx, dy; 88 | int8_t err; 89 | int8_t ystep; 90 | 91 | if (steep) { 92 | swap(x0, y0); 93 | swap(x1, y1); 94 | } 95 | 96 | if (x0 > x1) { 97 | swap(x0, x1); 98 | swap(y0, y1); 99 | } 100 | 101 | glcd_update_bbox( x0, y0, x1, y1 ); 102 | 103 | dx = x1 - x0; 104 | dy = abs(y1 - y0); 105 | 106 | err = dx / 2; 107 | 108 | if (y0 < y1) { 109 | ystep = 1; 110 | } else { 111 | ystep = -1; 112 | } 113 | 114 | for (; x0<=x1; x0++) { 115 | if (steep) { 116 | glcd_set_pixel(y0, x0, color); 117 | } else { 118 | glcd_set_pixel(x0, y0, color); 119 | } 120 | err -= dy; 121 | if (err < 0) { 122 | y0 += ystep; 123 | err += dx; 124 | } 125 | } 126 | } 127 | 128 | void glcd_fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) 129 | { 130 | int16_t i; 131 | for (i=x; i= 0) { 208 | y--; 209 | ddF_y += 2; 210 | f += ddF_y; 211 | } 212 | x++; 213 | ddF_x += 2; 214 | f += ddF_x; 215 | 216 | glcd_set_pixel(x0 + x, y0 + y, color); 217 | glcd_set_pixel(x0 - x, y0 + y, color); 218 | glcd_set_pixel(x0 + x, y0 - y, color); 219 | glcd_set_pixel(x0 - x, y0 - y, color); 220 | 221 | glcd_set_pixel(x0 + y, y0 + x, color); 222 | glcd_set_pixel(x0 - y, y0 + x, color); 223 | glcd_set_pixel(x0 + y, y0 - x, color); 224 | glcd_set_pixel(x0 - y, y0 - x, color); 225 | 226 | } 227 | } 228 | 229 | void glcd_fill_circle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color) 230 | { 231 | 232 | int8_t f = 1 - r; 233 | int8_t ddF_x = 1; 234 | int8_t ddF_y = -2 * r; 235 | int8_t x = 0; 236 | int8_t y = r; 237 | 238 | int16_t i; 239 | 240 | glcd_update_bbox(x0-r, y0-r, x0+r, y0+r); 241 | 242 | for (i=y0-r; i<=y0+r; i++) { 243 | glcd_set_pixel(x0, i, color); 244 | } 245 | 246 | while (x < y) { 247 | if (f >= 0) { 248 | y--; 249 | ddF_y += 2; 250 | f += ddF_y; 251 | } 252 | x++; 253 | ddF_x += 2; 254 | f += ddF_x; 255 | 256 | for (i=y0-y; i<=y0+y; i++) { 257 | glcd_set_pixel(x0+x, i, color); 258 | glcd_set_pixel(x0-x, i, color); 259 | } 260 | for (i=y0-x; i<=y0+x; i++) { 261 | glcd_set_pixel(x0+y, i, color); 262 | glcd_set_pixel(x0-y, i, color); 263 | } 264 | } 265 | } 266 | 267 | void glcd_invert_area(uint8_t x, uint8_t y, uint8_t w, uint8_t h) 268 | { 269 | uint8_t xx, yy; 270 | for (xx = x; xx < (x+w); xx++) { 271 | /* Loop through each partial column */ 272 | for (yy = y; yy < (y+h); yy++) { 273 | /* Go down and invert every pixel */ 274 | glcd_invert_pixel(xx,yy); 275 | } 276 | } 277 | } 278 | 279 | void glcd_draw_bitmap(const unsigned char *data) 280 | { 281 | 282 | #if 0 283 | /* Testing purposes only: Writing to the LCD right away (not for AVR) */ 284 | /* Normally, we do not do this, we just write to the screen buffer */ 285 | uint8_t *original_buffer; 286 | 287 | /* Save the location of original screen buffer */ 288 | original_buffer = glcd_buffer_selected; 289 | 290 | /* Use bitmap location as screen buffer (this won't work when using AVR8 PGM_P) */ 291 | glcd_select_screen((uint8_t *)data, glcd_bbox_selected); 292 | 293 | /* Make sure we write the entre display */ 294 | glcd_bbox_refresh(); 295 | glcd_write(); 296 | 297 | /* Restore the screen buffer back to original */ 298 | glcd_select_screen(original_buffer, glcd_bbox_selected); 299 | #endif 300 | 301 | /* Copy bitmap data to the screen buffer */ 302 | #if defined(GLCD_DEVICE_AVR8) 303 | memcpy_P(glcd_buffer_selected, data, (GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8)); 304 | #else 305 | memcpy(glcd_buffer_selected, data, (GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8)); 306 | #endif 307 | 308 | glcd_bbox_refresh(); 309 | } 310 | -------------------------------------------------------------------------------- /fonts/Liberation_Sans17x17_Alpha.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Liberation_Sans17x17_Alpha.h 3 | * 4 | * Created: 30/03/2012 1:29:55 AM 5 | * Author: andy 6 | */ 7 | 8 | 9 | #ifndef LIBERATION_SANS17X17_ALPHA_H_ 10 | #define LIBERATION_SANS17X17_ALPHA_H_ 11 | 12 | //WARNING: This Font Require X-GLCD Lib. 13 | // You can not use it with MikroE GLCD Lib. 14 | 15 | //Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0 16 | //MikroElektronika 2011 17 | //http://www.mikroe.com 18 | 19 | //GLCD FontName : Liberation_Sans17x17 46 to 90 20 | //GLCD FontSize : 17 x 17 21 | 22 | static const char Liberation_Sans17x17_Alpha[] PROGMEM = { 23 | 0x0D, 0x00, 0x10, 0x00, 0x00, 0x1E, 0x00, 0xC0, 0x1F, 0x00, 0xF8, 0x0F, 0x00, 0xFF, 0x03, 0x00, 0x1F, 0x03, 0x00, 0x03, 0x03, 0x00, 0x1F, 0x03, 0x00, 0xFF, 0x03, 0x00, 0xF8, 0x0F, 0x00, 0xC0, 0x1F, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char A 24 | 0x0D, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0xFF, 0x1C, 0x00, 0xFE, 0x1F, 0x00, 0xDE, 0x0F, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char B 25 | 0x0D, 0x00, 0x00, 0x00, 0xF8, 0x01, 0x00, 0xFC, 0x07, 0x00, 0xFE, 0x0F, 0x00, 0x0F, 0x0E, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x07, 0x1C, 0x00, 0x0E, 0x0E, 0x00, 0x0E, 0x0E, 0x00, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char C 26 | 0x0D, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x07, 0x1C, 0x00, 0x0E, 0x0E, 0x00, 0xFE, 0x0F, 0x00, 0xFC, 0x07, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char D 27 | 0x0C, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x63, 0x18, 0x00, 0x03, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char E 28 | 0x0B, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char F 29 | 0x0E, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x00, 0xFC, 0x07, 0x00, 0xFE, 0x0F, 0x00, 0x0E, 0x0E, 0x00, 0x07, 0x1C, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0xC3, 0x18, 0x00, 0xC3, 0x18, 0x00, 0xC7, 0x1C, 0x00, 0xCE, 0x0F, 0x00, 0xCE, 0x0F, 0x00, 0xC4, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char G 30 | 0x0C, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x60, 0x00, 0x00, 0x60, 0x00, 0x00, 0x60, 0x00, 0x00, 0x60, 0x00, 0x00, 0x60, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char H 31 | 0x04, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char I 32 | 0x0A, 0x00, 0x06, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x1C, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x03, 0x1C, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x0F, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char J 33 | 0x0E, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xE0, 0x00, 0x00, 0x60, 0x00, 0x00, 0x70, 0x00, 0x00, 0xF8, 0x01, 0x00, 0xDC, 0x03, 0x00, 0x8E, 0x07, 0x00, 0x07, 0x0E, 0x00, 0x03, 0x1C, 0x00, 0x01, 0x18, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char K 34 | 0x0B, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char L 35 | 0x10, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x0F, 0x00, 0x00, 0x7E, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x80, 0x1F, 0x00, 0x00, 0x1C, 0x00, 0x80, 0x1F, 0x00, 0xF0, 0x03, 0x00, 0x7E, 0x00, 0x00, 0x0F, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, // Code for char M 36 | 0x0C, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x1F, 0x00, 0x00, 0x7C, 0x00, 0x00, 0xF0, 0x01, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x1E, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char N 37 | 0x0E, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x00, 0xFC, 0x07, 0x00, 0xFE, 0x0F, 0x00, 0x0E, 0x0E, 0x00, 0x07, 0x1C, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x03, 0x18, 0x00, 0x07, 0x1C, 0x00, 0x0E, 0x0E, 0x00, 0xFE, 0x0F, 0x00, 0xFC, 0x07, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char O 38 | 0x0C, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char P 39 | 0x0E, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0xFC, 0x07, 0x00, 0xFE, 0x0F, 0x00, 0x0E, 0x1E, 0x00, 0x07, 0x1C, 0x00, 0x03, 0x38, 0x00, 0x03, 0xF8, 0x00, 0x03, 0xF8, 0x01, 0x07, 0xDC, 0x01, 0x0E, 0x9E, 0x01, 0xFE, 0x8F, 0x01, 0xFC, 0x87, 0x01, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Q 40 | 0x0D, 0x00, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0x63, 0x00, 0x00, 0xE3, 0x00, 0x00, 0xE3, 0x03, 0x00, 0xBF, 0x0F, 0x00, 0x3E, 0x1F, 0x00, 0x1C, 0x1C, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char R 41 | 0x0C, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x1C, 0x0E, 0x00, 0x3E, 0x0E, 0x00, 0x7F, 0x1C, 0x00, 0x73, 0x18, 0x00, 0x63, 0x18, 0x00, 0xE3, 0x18, 0x00, 0xE7, 0x18, 0x00, 0xCF, 0x1F, 0x00, 0xCE, 0x0F, 0x00, 0x8C, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char S 42 | 0x0C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char T 43 | 0x0C, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0xFF, 0x0F, 0x00, 0xFF, 0x0F, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x1C, 0x00, 0xFF, 0x0F, 0x00, 0xFF, 0x0F, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char U 44 | 0x0D, 0x03, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x7F, 0x00, 0x00, 0xFC, 0x01, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x18, 0x00, 0x00, 0x1F, 0x00, 0xE0, 0x0F, 0x00, 0xF8, 0x01, 0x00, 0x7F, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char V 45 | 0x11, 0x07, 0x00, 0x00, 0x7F, 0x00, 0x00, 0xFF, 0x07, 0x00, 0xF0, 0x1F, 0x00, 0x00, 0x1E, 0x00, 0xC0, 0x1F, 0x00, 0xFC, 0x0F, 0x00, 0xFF, 0x00, 0x00, 0x07, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0xC0, 0x1F, 0x00, 0x00, 0x1E, 0x00, 0xF0, 0x1F, 0x00, 0xFF, 0x07, 0x00, 0x7F, 0x00, 0x00, 0x07, 0x00, 0x00, // Code for char W 46 | 0x0D, 0x01, 0x10, 0x00, 0x03, 0x18, 0x00, 0x07, 0x1C, 0x00, 0x1E, 0x0F, 0x00, 0xBC, 0x07, 0x00, 0xF0, 0x01, 0x00, 0xE0, 0x00, 0x00, 0xF0, 0x01, 0x00, 0xBC, 0x07, 0x00, 0x1E, 0x0F, 0x00, 0x0F, 0x1E, 0x00, 0x03, 0x18, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char X 47 | 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x7C, 0x00, 0x00, 0xF0, 0x1F, 0x00, 0xC0, 0x1F, 0x00, 0xF0, 0x1F, 0x00, 0x7C, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Y 48 | 0x0A, 0x00, 0x00, 0x00, 0x03, 0x1C, 0x00, 0x03, 0x1E, 0x00, 0x83, 0x1F, 0x00, 0xC3, 0x1B, 0x00, 0xF3, 0x19, 0x00, 0x7B, 0x18, 0x00, 0x3F, 0x18, 0x00, 0x0F, 0x18, 0x00, 0x07, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Code for char Z 49 | }; 50 | 51 | 52 | 53 | 54 | #endif /* LIBERATION_SANS17X17_ALPHA_H_ */ 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # glcd - Graphic LCD Library 2 | 3 | by [Andy Gock](https://gock.net/) 4 | 5 | ## Documentation 6 | 7 | For up to date documentation, please see the [doxygen](http://www.stack.nl/~dimitri/doxygen/) pages under the `doxygen_pages` directory and within the source code. 8 | 9 | A online version can also be seen at: 10 | 11 | 12 | 13 | However the above site may not always be up to date. 14 | 15 | ## Introduction 16 | 17 | Welcome to GLCD, an open source graphic LCD library written by [Andy Gock](https://gock.net/). 18 | 19 | - [Author's web site](https://gock.net/) 20 | - [GitHub repository](https://github.com/andygock/glcd) 21 | 22 | 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. 23 | 24 | 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. 25 | 26 | ## Features 27 | 28 | - 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. 29 | - Can write text from SRAM and Flash memory. 30 | - Scrolling text. 31 | - Draw vertical or horizontal bar graphs, with or without borders. 32 | - Draw circles, lines, rectangles - filled or unfilled. 33 | - Draw individual pixels in any color (black or white). 34 | - 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. 35 | - 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. 36 | 37 | ## Supported devices 38 | 39 | ### Controllers and chipsets 40 | 41 | Works with: 42 | 43 | - [PCD8544](https://andygock.github.io/datasheets/philips_pcd8544.pdf) based LCDs, e.g Nokia 3110 and 5110 LCDs 44 | - [ST7565R](https://andygock.github.io/datasheets/sitronix_st7565r.pdf) / ST7565P serial interface 45 | - [NT75451](https://www.crystalfontz.com/controllers/Novatek/NT75451) parallel interface (used on NGX BlueBoards) 46 | 47 | The following graphic displays have been physically tested with and confirmed working: 48 | 49 | - NHD-C12864WC-FSW-FBW-3V3-M 50 | - NHD-C12864A1Z-FSW-FBW-HTT 51 | - NHD-C12832A1Z-FSW-FBW-3V3 52 | - ZOLEN-12864-FFSSWE-NAA 53 | 54 | ### Microcontrollers 55 | 56 | #### MCUs supported 57 | 58 | - Atmel AVR 8-bit 59 | - NXP LPC111x ARM Cortex-M0 60 | - NXP LPC11Uxx ARM Cortex-M0 61 | - ST STM32 F0 ARM Cortex-M0 62 | - ST STM32 F4 ARM Cortex-M4 63 | - Microchip PIC24H (and probably other 16-bit MCUs) 64 | 65 | #### Development boards tested on (with on-board LCD) 66 | 67 | - NGX BlueBoard LPC11U37 (with on-board NT75451 graphic LCD) 68 | 69 | #### Development boards tested on (without on-board LCD) 70 | 71 | - Microstick II with PIC24H and Nokia 3310/5110 LCD, ST7565R and ST7565P 72 | - ST Nucleo F401RE 73 | 74 | ### Special note 75 | 76 | 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. 77 | 78 | ## Setup of symbols for compiler 79 | 80 | The following symbols need to be defined for the compiler: 81 | 82 | ### Select microcontroller 83 | 84 | Pick microcontroller type (pick one only): 85 | 86 | GLCD_DEVICE_LPX111X 87 | GLCD_DEVICE_LPX11UXX 88 | GLCD_DEVICE_AVR8 89 | GLCD_DEVICE_STM32F0XX 90 | GLCD_DEVICE_STM32F4XX 91 | GLCD_DEVICE_PIC24H 92 | 93 | ### Select LCD controller 94 | Pick LCD controller type (pick one only): 95 | 96 | GLCD_CONTROLLER_PCD8544 97 | GLCD_CONTROLLER_ST7565R 98 | GLCD_CONTROLLER_NT75451 99 | 100 | For ST7565P controllers, treat as ST7565R. For most if not all parts here, they behave the same way. 101 | 102 | ### Select SPI or parallel interface 103 | 104 | If using a parallel interface LCD (e.g NT75451 on NGX BlueBoard): 105 | 106 | GLCD_USE_PARALLEL 107 | 108 | When using SPI controllers: 109 | 110 | GLCD_USE_SPI 111 | 112 | 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. 113 | 114 | ### Initialisation sequence 115 | 116 | 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: 117 | 118 | GLCD_INIT_NHD_C12832A1Z_FSW_FBW_3V3 119 | GLCD_INIT_NHD_C12864A1Z_FSW_FBW_HTT 120 | GLCD_INIT_NHD_C12864WC_FSW_FBW_3V3_M 121 | GLCD_INIT_ZOLEN_12864_FFSSWE_NAA 122 | 123 | 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. 124 | 125 | ### Reset time 126 | 127 | To set a reset time, used by the `glcd_reset()` function, set `GLCD_RESET_TIME` to desired duration in milliseconds. 128 | 129 | ### Contrast 130 | 131 | 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. 132 | 133 | ### LCD dimensions 134 | 135 | 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. 136 | 137 | ### Compiler setup 138 | 139 | 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. 140 | 141 | Example: 142 | 143 | -DGLCD_DEVICE_LPC111X 144 | 145 | ### Delay Timing 146 | 147 | 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. 148 | 149 | #### AVR devices 150 | 151 | 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: 152 | 153 | GLCD_USE_AVR_DELAY 154 | __DELAY_BACKWARD_COMPATIBLE__ 155 | 156 | `F_CPU` must be set to your clock frequency for the above [AVR built-in delay](http://www.nongnu.org/avr-libc/user-manual/group__util__delay.html) routine to work. 157 | 158 | ## Sample applications and videos 159 | 160 | - STM32F0 Discovery with PCD8544 Nokia 5110 LCD - [Download](https://andygock.github.io/glcd-samples/GLCD_STM32F0_PCD8544.zip) Keil MDK project 161 | - Custom PCB with Atmel ATMEGA2560 and ST7565R Newhaven 128×64 display - [Download](https://andygock.github.io/glcd-samples/as6_mega2560_st7565r.zip) Atmel Studio 6 project 162 | - Atmel AT90USBKEY board with PCD8544 Nokia 5110 LCD - [Download](https://andygock.github.io/glcd-samples/glcd-example-at90usbkey-avrstudio.zip) Atmel Studio 5 project 163 | - ZERO Z111xP Cortex-M0 LPC1114 board with PCD8544 Nokia 5110 LCD - [Download](https://andygock.github.io/glcd-samples/glcd-example-LPC1114-CooCox.zip) CooCox CoIDE project or watch [video](http://www.youtube.com/watch?v=mWsTbLW5Hm4) 164 | - NGX LPC11U37 BlueBoard with built in NT75451 parallel chipset LCD - [Download](https://andygock.github.io/glcd-samples/glcd-example-LPC11U37-BlueBoard-Keil.zip) Keil MDK project 165 | - Microstick II development board, with PIC24H and Newhaven ST7565R display NHD-C12864A1Z-FSW-FBW-HTT - [Download](https://andygock.github.io/glcd-samples/demo-microstick_PIC24HJ128_ST7565R.zip) MPLAB X project or watch [video](http://www.youtube.com/watch?v=1ocUWbEOs5Y) 166 | - Microstick II development board, with PIC24H and Newhaven ST7565P display NHD-C12832A1Z-FSW-FBW-3V3 - [Download](https://andygock.github.io/glcd-samples/demo-microstick_PIC24HJ128_ST7565P.zip) MPLAB X project or watch [video](http://www.youtube.com/watch?v=j7bQ-8SIgYc) 167 | - Microstick II development board, with PIC24H and PCD8544 Nokia 5110 display - [Download](https://andygock.github.io/glcd-samples/demo-microstick_PIC24HJ128_PCD8544.zip) MPLAB X project 168 | - Pinguino development board, with PIC32MX440F256H and PCD8544 Nokia 5110 display - [Download](https://andygock.github.io/glcd-samples/PIC32_PINGUINO_OTG_AND_NOKIA_5110.X.zip) MPLAB X project (Thanks to [Joris Putcuyps](https://github.com/jputcu)) 169 | 170 | 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. 171 | 172 | ## Display bitmap images 173 | 174 | Bitmap images can be converted into a byte array using [LCD Assistant](http://en.radzio.dxp.pl/bitmap_converter/) 175 | 176 | When using this software, we need to set 8 pixels per byte with vertical byte orientation. Do not include size. 177 | -------------------------------------------------------------------------------- /glcd.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file glcd.h 3 | \brief GLCD Library main header file. This file must be included into project. 4 | \author Andy Gock 5 | */ 6 | 7 | /* 8 | Copyright (c) 2012, Andy Gock 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * Neither the name of Andy Gock nor the 20 | names of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _GLCD_H 36 | #define _GLCD_H 37 | 38 | #if defined(GLCD_DEVICE_AVR8) 39 | #include 40 | #include 41 | #include 42 | #include "devices/AVR8.h" 43 | 44 | #if !defined(GLCD_USE_AVR_DELAY) 45 | extern void delay_ms(uint32_t ms); 46 | #else 47 | /* Use AVR __delay_ms() function */ 48 | #include 49 | #define delay_ms(t) _delay_ms(t) 50 | #endif 51 | 52 | #elif defined(GLCD_DEVICE_LPC111X) 53 | #include 54 | #include "devices/LPC111x.h" 55 | extern void delay_ms(uint32_t ms); 56 | #define PROGMEM 57 | 58 | #elif defined(GLCD_DEVICE_LPC11UXX) 59 | #include 60 | #include "devices/LPC11Uxx.h" 61 | extern void delay_ms(uint32_t ms); 62 | #define PROGMEM 63 | 64 | #elif defined(GLCD_DEVICE_STM32F0XX) 65 | #include 66 | #include 67 | #include "devices/inc/STM32F0xx.h" 68 | extern void delay_ms(uint32_t ms); 69 | #define PROGMEM 70 | 71 | #elif defined(GLCD_DEVICE_STM32F10X) 72 | #include 73 | #include 74 | #include "devices/inc/STM32F10x.h" 75 | extern void delay_ms(uint32_t ms); 76 | #define PROGMEM 77 | 78 | #elif defined(GLCD_DEVICE_STM32F4XX) 79 | #include 80 | #include "devices/STM32F4.h" 81 | extern void delay_ms(uint32_t ms); 82 | #define PROGMEM 83 | 84 | #elif defined(GLCD_DEVICE_PIC24H) 85 | #define FCY (FOSC/2) 86 | #include 87 | #include 88 | #include 89 | #include "devices/PIC24H.h" 90 | #define PROGMEM 91 | #define delay_ms(t) __delay_ms(t) 92 | #elif defined(GLCD_DEVICE_PIC32) 93 | #include "devices/PIC32.h" 94 | #define PROGMEM 95 | extern void delay_ms(unsigned int ms); 96 | #else 97 | #error "Device not supported or defined" 98 | 99 | #endif 100 | 101 | #if defined(GLCD_CONTROLLER_PCD8544) 102 | #include "controllers/PCD8544.h" 103 | 104 | #elif defined(GLCD_CONTROLLER_ST7565R) 105 | #include "controllers/ST7565R.h" 106 | 107 | #elif defined(GLCD_CONTROLLER_NT75451) 108 | #include "controllers/NT75451.h" 109 | 110 | #else 111 | #error "Controller not supported or defined" 112 | 113 | #endif 114 | 115 | /* Macros */ 116 | 117 | #define swap(a, b) { uint8_t t = a; a = b; b = t; } 118 | 119 | /* Defining new types */ 120 | 121 | /** 122 | * Font table type 123 | */ 124 | typedef enum { 125 | STANG, 126 | MIKRO, 127 | GLCD_UTILS 128 | } font_table_type_t; 129 | 130 | /** 131 | * Bounding box for pixels that need to be updated 132 | */ 133 | typedef struct { 134 | uint8_t x_min; 135 | uint8_t y_min; 136 | uint8_t x_max; 137 | uint8_t y_max; 138 | } glcd_BoundingBox_t; 139 | 140 | #include 141 | #include "glcd_devices.h" 142 | #include "glcd_controllers.h" 143 | #include "glcd_graphics.h" 144 | #include "glcd_graphs.h" 145 | #include "glcd_text_tiny.h" 146 | #include "glcd_text.h" 147 | #include "unit_tests.h" 148 | 149 | /** 150 | * \name Colour Constants 151 | * @{ 152 | */ 153 | #define BLACK 1 154 | #define WHITE 0 155 | /**@}*/ 156 | 157 | /** 158 | * \name LCD Dimensions 159 | * @{ 160 | */ 161 | 162 | /* 163 | * Set to custom value, or leave at 0 for automatic assignment. 164 | * For custom dimensions, users can define this in their compiler options. 165 | */ 166 | 167 | #if !defined(GLCD_LCD_WIDTH) || !defined(GLCD_LCD_HEIGHT) 168 | 169 | /** 170 | * User specified GLCD width in pixels 171 | * Set to 0 for automatic assignment based on controller. 172 | */ 173 | #define GLCD_LCD_WIDTH 0 174 | 175 | /** 176 | * User specified GLCD height in pixels 177 | * Set to 0 for automatic assignment based on controller. 178 | */ 179 | 180 | #define GLCD_LCD_HEIGHT 0 181 | 182 | /* Automatic assignment of width and height, if required. */ 183 | #if !GLCD_LCD_WIDTH && !GLCD_LCD_HEIGHT 184 | #undef GLCD_LCD_WIDTH 185 | #undef GLCD_LCD_HEIGHT 186 | #if defined(GLCD_CONTROLLER_PCD8544) 187 | /* 84x48 is standard for the popular Nokia LCD */ 188 | #define GLCD_LCD_WIDTH 84 189 | #define GLCD_LCD_HEIGHT 48 190 | #elif defined(GLCD_CONTROLLER_ST7565R) || defined(GLCD_CONTROLLER_NT75451) 191 | /* 128x64 is the most popular for this, so we'll use that as default */ 192 | #define GLCD_LCD_WIDTH 128 193 | #define GLCD_LCD_HEIGHT 64 194 | #else 195 | #define GLCD_LCD_WIDTH 128 196 | #define GLCD_LCD_HEIGHT 64 197 | #endif 198 | #endif 199 | 200 | #endif /* !defined(GLCD_LCD_WIDTH) || !defined(GLCD_LCD_HEIGHT) */ 201 | 202 | /* 203 | * GLCD_NUMBER_OF_BANKS is typically GLCD_LCD_HEIGHT/8 204 | * Don't adjust these below unless required. 205 | */ 206 | #define GLCD_NUMBER_OF_BANKS (GLCD_LCD_WIDTH / 8) 207 | #define GLCD_NUMBER_OF_COLS GLCD_LCD_WIDTH 208 | 209 | /**@}*/ 210 | 211 | #if !defined(GLCD_RESET_TIME) 212 | /** Reset duration by glcd_reset(), in milliseconds */ 213 | #define GLCD_RESET_TIME 1 214 | #endif 215 | 216 | /* Global variables used for GLCD library */ 217 | extern uint8_t glcd_buffer[GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8]; 218 | extern glcd_BoundingBox_t glcd_bbox; 219 | extern uint8_t *glcd_buffer_selected; 220 | extern glcd_BoundingBox_t *glcd_bbox_selected; 221 | 222 | /** \name Base Functions 223 | * @{ 224 | */ 225 | 226 | /** 227 | * Update bounding box. 228 | * 229 | * The bounding box defines a rectangle in which needs to be refreshed next time 230 | * glcd_write() is called. glcd_write() only writes to those pixels inside the bounding box plus any 231 | * surrounding pixels which are required according to the bank/column write method of the controller. 232 | * 233 | * Define a rectangle here, and it will be added to the existing bounding box. 234 | * 235 | * \param xmin Minimum x value of rectangle 236 | * \param ymin Minimum y value of rectangle 237 | * \param xmax Maximum x value of rectangle 238 | * \param ymax Maximum y value of rectangle 239 | * \see glcd_bbox 240 | * \see glcd_bbox_selected 241 | */ 242 | void glcd_update_bbox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax); 243 | 244 | /** 245 | * Reset the bounding box. 246 | * After resetting the bounding box, no pixels are marked as needing refreshing. 247 | */ 248 | void glcd_reset_bbox(void); 249 | 250 | /** 251 | * Same as glcd_reset_bbox() 252 | */ 253 | void glcd_bbox_reset(void); 254 | 255 | /** 256 | * Marks the entire display for re-writing. 257 | */ 258 | void glcd_bbox_refresh(void); 259 | 260 | /** 261 | * Clear the display. This will clear the buffer and physically write and commit it to the LCD 262 | */ 263 | void glcd_clear(void); 264 | 265 | /** 266 | * Clear the display buffer only. This does not physically write the changes to the LCD 267 | */ 268 | void glcd_clear_buffer(void); 269 | 270 | /** 271 | * Select screen buffer and bounding box structure. 272 | * This should be selected at initialisation. There are future plans to support multiple screen buffers 273 | * but this not yet available. 274 | * \param buffer Pointer to screen buffer 275 | * \param bbox Pointer to bounding box object. 276 | * \see glcd_BoundingBox_t 277 | */ 278 | void glcd_select_screen(uint8_t *buffer, glcd_BoundingBox_t *bbox); 279 | 280 | /** 281 | * Scroll entire screne buffer by x and y pixels. (not implemented yet) 282 | * \note Items scrolled off the extents of the display dimensions will be lost. 283 | * 284 | * \param x X distance to scroll 285 | * \param y Y distance to scroll 286 | */ 287 | void glcd_scroll(int8_t x, int8_t y); 288 | 289 | /** 290 | * Scroll screen buffer up by 8 pixels. 291 | * This is designed to be used in conjunciton with tiny text functions which are 8 bits high. 292 | * \see Tiny Text 293 | */ 294 | void glcd_scroll_line(void); 295 | 296 | /** @}*/ 297 | 298 | typedef struct { 299 | const char *font_table; 300 | uint8_t width; 301 | uint8_t height; 302 | char start_char; 303 | char end_char; 304 | font_table_type_t table_type; 305 | } glcd_FontConfig_t; 306 | 307 | extern uint8_t *glcd_buffer_selected; 308 | extern glcd_BoundingBox_t *glcd_bbox_selected; 309 | extern glcd_FontConfig_t font_current; 310 | 311 | #endif 312 | --------------------------------------------------------------------------------