This is library for PCD8544 LCD controller. This lcd has been used in Nokia 5110/3310 phones. They are almost free on Ebay and are nice size to be used in your projects.
Features
- Resolution 84 x 48px
- Display string
- 2 font sizes 5 x 7 and 3 x 5
- Graphic library for lines, rectangles and circles
- algorithm to update only changed area of display to increase speed
- driven with SPI
- Software selectable contrast
Connection to Discovery board
LCD board | Discovery | Description |
---|---|---|
RST | PC15 | Reset pin for LCD |
CE | PC13 | Chip enable for SPI2 |
DC | PC14 | Data/Command pin |
DIN | PC3 | MOSI pin for SPI2 |
CLK | PB10 | CLOCK pin for SPI2 |
VCC | 3.3V | VCC Power |
LIGHT | GND | If you connect this to GND, backlight is turned on |
GND | GND | Ground |
Enums
Here are listed public enums, which are used in public functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/** * Used for pixel "color" * LCD is 1 bit, so pixel can be just set or clear */ typedef enum { PCD8544_Pixel_Clear = 0, PCD8544_Pixel_Set = !PCD8544_Pixel_Clear } PCD8544_Pixel_t; /** * Font size for text * There are 2 sizes included */ typedef enum { PCD8544_FontSize_5x7 = 0, PCD8544_FontSize_3x5 = !PCD8544_FontSize_5x7 } PCD8544_FontSize_t; /** * Used to invert pixels */ typedef enum { PCD8544_Invert_Yes, PCD8544_Invert_No } PCD8544_Invert_t; |
Functions
Only public functions are described here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
/** * Initialize LCD * * Parameters * - unsigned char contrast: Contrast can be software selectable, from 0x00 to 0x7F */ extern void PCD8544_Init(unsigned char contrast); /** * Set contrast for LCD * * Parameters * - unsigned char contrast: Contrast can be software selectable, from 0x00 to 0x7F */ extern void PCD8544_SetContrast(unsigned char contrast); /** * Invert LCD * * Parameters * - PCD8544_Invert_t invert * - PCD8544_Invert_Yes: Invert pixels on lcd * - PCD8544_Invert_No: Return pixels to orignal */ extern void PCD8544_Invert(PCD8544_Invert_t invert); /** * Clear lcd */ extern void PCD8544_Clear(void); /** * Set/clear pixel at specific location * * Parameters * - unsigned char x: x position of pixel * - unsigned char y: y position of pixel * - PCD8544_PCD8544_Pixel_t pixel: Set or clear pixel * - PCD8544_Pixel_Set * - PCD8544_Pixel_Clear */ extern void PCD8544_DrawPixel(unsigned char x, unsigned char y, PCD8544_Pixel_t pixel); /** * Set cursor on lcd at 0, 0 location */ extern void PCD8544_Home(void); /** * Put data from internal buffer to lcd */ extern void PCD8544_Refresh(void); /** * Set cursor to desired position * * Parameters: * - unsigned char x: x from 0 to 83 * - unsigned char y: y from 0 to 47 */ extern void PCD8544_GotoXY(unsigned char x, unsigned char y); /** * Put character on LCD * * Parameters: * - char c: char to display * - PCD8544_FontSize_t size: Font size * - PCD8544_FontSize_5x7 * - PCD8544_FontSize_3x5 * - PCD8544_PCD8544_Pixel_t color * - PCD8544_Pixel_Set * - PCD8544_Pixel_Clear */ extern void PCD8544_Putc(char c, PCD8544_Pixel_t color, PCD8544_FontSize_t size); /** * Put string on LCD * * Parameters: * - char *c: pointer to first character of string * - PCD8544_FontSize_t size: Font size * - PCD8544_FontSize_5x7 * - PCD8544_FontSize_3x5 * - PCD8544_PCD8544_Pixel_t color * - PCD8544_Pixel_Set * - PCD8544_Pixel_Clear */ extern void PCD8544_Puts(char *c, PCD8544_Pixel_t color, PCD8544_FontSize_t size); /** * Draw line on LCD * * Parameters: * - unsigned char x0: X coordinate of starting point * - unsigned char y0: Y coordinate of starting point * - unsigned char x1: X coordinate of ending point * - unsigned char y1: Y coordinate of ending point * - PCD8544_PCD8544_Pixel_t color * - PCD8544_Pixel_Set * - PCD8544_Pixel_Clear */ extern void PCD8544_DrawLine(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, PCD8544_Pixel_t color); /** * Draw rectangle on LCD * * Parameters: * - unsigned char x0: X coordinate of top left point * - unsigned char y0: Y coordinate of top left point * - unsigned char x1: X coordinate of bottom right point * - unsigned char y1: Y coordinate of bottom right point * - PCD8544_PCD8544_Pixel_t color * - PCD8544_Pixel_Set * - PCD8544_Pixel_Clear */ extern void PCD8544_DrawRectangle(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, PCD8544_Pixel_t color); /** * Draw filled rectangle on LCD * * Parameters: * - unsigned char x0: X coordinate of top left point * - unsigned char y0: Y coordinate of top left point * - unsigned char x1: X coordinate of bottom right point * - unsigned char y1: Y coordinate of bottom right point * - PCD8544_PCD8544_Pixel_t color * - PCD8544_Pixel_Set * - PCD8544_Pixel_Clear */ extern void PCD8544_DrawFilledRectangle(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, PCD8544_Pixel_t color); /** * Draw circle on LCD * * Parameters: * - char x0: X coordinate of center circle point * - char y0: Y coordinate of center circle point * - char r: circle radius * - PCD8544_PCD8544_Pixel_t color * - PCD8544_Pixel_Set * - PCD8544_Pixel_Clear */ extern void PCD8544_DrawCircle(char x0, char y0, char r, PCD8544_Pixel_t color); /** * Draw filled circle on LCD * * Parameters: * - char x0: X coordinate of center circle point * - char y0: Y coordinate of center circle point * - char r: circle radius * - PCD8544_PCD8544_Pixel_t color * - PCD8544_Pixel_Set * - PCD8544_Pixel_Clear */ extern void PCD8544_DrawFilledCircle(char x0, char y0, char r, PCD8544_Pixel_t color); |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/** * PCD8544 LCD controller driver example * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision */ #include "defines.h" #include "stm32f4xx.h" #include "tm_stm32f4_pcd8544.h" int main(void) { //180MHz SystemInit(); //Initialize LCD with 0x38 software contrast PCD8544_Init(0x38); //Go to x=14, y=3 position PCD8544_GotoXY(14, 3); //Print data with Pixel Set mode and Fontsize of 5x7px PCD8544_Puts("STM32F429", PCD8544_Pixel_Set, PCD8544_FontSize_5x7); PCD8544_GotoXY(15, 13); PCD8544_Puts("Discovery", PCD8544_Pixel_Set, PCD8544_FontSize_5x7); PCD8544_GotoXY(30, 26); PCD8544_Puts("2014", PCD8544_Pixel_Set, PCD8544_FontSize_5x7); PCD8544_GotoXY(45, 42); //Put string with Pixel set mode and Fontsize of 3x5 PCD8544_Puts("majerle.eu", PCD8544_Pixel_Set, PCD8544_FontSize_3x5); //Display data on LCD PCD8544_Refresh(); while (1) { } } |
Upload code to discovery board. If you did everything correct, then something similar to image on the left should be displayed.
Project is available on Github, download library below.
Recent comments