light text library for 5110 nokia lcd * easy to modify * proportional font, bold / inverse modes * easy to add / change fonts * fixed rows for fast update
Library finished! :-) If you use 5110 and need fast menus - try this library. No overhead - small and robust, optimized for this display type only, fast update. Nice looking font. Power management. Displays from 5110 and 3110 are cheap as dirt :-)
medvdv5110.h@2:65df20ffef51, 2012-12-07 (annotated)
- Committer:
- medvdv
- Date:
- Fri Dec 07 21:41:54 2012 +0000
- Revision:
- 2:65df20ffef51
- Parent:
- 0:0a6619901f2e
- Child:
- 3:03c7cb24222d
Now commented =)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
medvdv | 0:0a6619901f2e | 1 | // |
medvdv | 0:0a6619901f2e | 2 | // 5110 LCD Driver |
medvdv | 0:0a6619901f2e | 3 | // (c) 2012 medvdv.com |
medvdv | 0:0a6619901f2e | 4 | // Alexander Medvedev |
medvdv | 0:0a6619901f2e | 5 | // |
medvdv | 0:0a6619901f2e | 6 | |
medvdv | 2:65df20ffef51 | 7 | // depends of voltage and other factors |
medvdv | 2:65df20ffef51 | 8 | #define DEFAULT_CONTRAST 50 |
medvdv | 2:65df20ffef51 | 9 | |
medvdv | 2:65df20ffef51 | 10 | // |
medvdv | 2:65df20ffef51 | 11 | // Proportional font with 8px height |
medvdv | 2:65df20ffef51 | 12 | // |
medvdv | 2:65df20ffef51 | 13 | |
medvdv | 0:0a6619901f2e | 14 | typedef struct { |
medvdv | 0:0a6619901f2e | 15 | |
medvdv | 0:0a6619901f2e | 16 | char first_code; |
medvdv | 0:0a6619901f2e | 17 | char glyphs_total; |
medvdv | 0:0a6619901f2e | 18 | const char* widths; |
medvdv | 0:0a6619901f2e | 19 | const char** glyphs; |
medvdv | 0:0a6619901f2e | 20 | |
medvdv | 0:0a6619901f2e | 21 | } lcd5110font; |
medvdv | 0:0a6619901f2e | 22 | |
medvdv | 2:65df20ffef51 | 23 | // Contrast value depends of voltage and other factors |
medvdv | 2:65df20ffef51 | 24 | #define DEFAULT_CONTRAST 50 |
medvdv | 2:65df20ffef51 | 25 | |
medvdv | 2:65df20ffef51 | 26 | // |
medvdv | 2:65df20ffef51 | 27 | // Nokia 5110 LCD Interface Class |
medvdv | 2:65df20ffef51 | 28 | // |
medvdv | 2:65df20ffef51 | 29 | |
medvdv | 0:0a6619901f2e | 30 | class lcd5110 { |
medvdv | 0:0a6619901f2e | 31 | |
medvdv | 2:65df20ffef51 | 32 | // SPI and other pin's |
medvdv | 0:0a6619901f2e | 33 | SPI* spi; |
medvdv | 0:0a6619901f2e | 34 | DigitalOut* rst; |
medvdv | 0:0a6619901f2e | 35 | DigitalOut* sce; |
medvdv | 0:0a6619901f2e | 36 | DigitalOut* dc; |
medvdv | 2:65df20ffef51 | 37 | |
medvdv | 2:65df20ffef51 | 38 | // Current font |
medvdv | 0:0a6619901f2e | 39 | lcd5110font font; |
medvdv | 0:0a6619901f2e | 40 | |
medvdv | 2:65df20ffef51 | 41 | // Contrast value for next reset |
medvdv | 0:0a6619901f2e | 42 | char contrast; |
medvdv | 0:0a6619901f2e | 43 | |
medvdv | 2:65df20ffef51 | 44 | // Invert and bold flags |
medvdv | 0:0a6619901f2e | 45 | bool invert; |
medvdv | 0:0a6619901f2e | 46 | bool bold; |
medvdv | 0:0a6619901f2e | 47 | |
medvdv | 2:65df20ffef51 | 48 | // current write position |
medvdv | 0:0a6619901f2e | 49 | int X, Y; |
medvdv | 0:0a6619901f2e | 50 | |
medvdv | 2:65df20ffef51 | 51 | // Generic SPI writer |
medvdv | 0:0a6619901f2e | 52 | void write(char byte, bool cmd = false); |
medvdv | 0:0a6619901f2e | 53 | |
medvdv | 0:0a6619901f2e | 54 | public: |
medvdv | 0:0a6619901f2e | 55 | |
medvdv | 2:65df20ffef51 | 56 | // Supply LCD connected pin's here for your design |
medvdv | 0:0a6619901f2e | 57 | lcd5110(PinName mosi= p11, PinName sclk = p13, PinName dc = p10, PinName sce = p8, PinName rst = p9); |
medvdv | 0:0a6619901f2e | 58 | |
medvdv | 2:65df20ffef51 | 59 | void Reset(); // Reset LCD, configure defaults and contrast |
medvdv | 2:65df20ffef51 | 60 | void Clear(char pattern = 0); // Clear - fill all by 8bit line 'pattern' |
medvdv | 2:65df20ffef51 | 61 | void PowerOff(); // LCD power off |
medvdv | 2:65df20ffef51 | 62 | |
medvdv | 2:65df20ffef51 | 63 | void Contrast(char contrast = DEFAULT_CONTRAST ); // Change contrast |
medvdv | 0:0a6619901f2e | 64 | |
medvdv | 2:65df20ffef51 | 65 | void Invert(bool invert = true); // Switch inverting of chars |
medvdv | 2:65df20ffef51 | 66 | void Bold(bool bold = true); // Switch bold mode (repeat each char row twice) |
medvdv | 0:0a6619901f2e | 67 | |
medvdv | 2:65df20ffef51 | 68 | void XY(int x = 0, int y = 0); // Change write position X in pixels [0..83], Y in rows [0..5] |
medvdv | 0:0a6619901f2e | 69 | |
medvdv | 2:65df20ffef51 | 70 | // Row write |
medvdv | 2:65df20ffef51 | 71 | void Write(char byte); // One 8bit row |
medvdv | 2:65df20ffef51 | 72 | void Write(char byte, int count); // One 8bit row * 'count' times |
medvdv | 2:65df20ffef51 | 73 | void Write(char* data, int size); // 'size' 8bit rows |
medvdv | 2:65df20ffef51 | 74 | void Write2(char* data, int size); // Bold: 'size' 8bit rows * 2 |
medvdv | 0:0a6619901f2e | 75 | |
medvdv | 2:65df20ffef51 | 76 | // Character drawing |
medvdv | 2:65df20ffef51 | 77 | void Character(char chr); // Draw one font character with invert and bold opt-s |
medvdv | 2:65df20ffef51 | 78 | int CharacterWidth(char chr); // Calculate one character width with bold opt-n |
medvdv | 0:0a6619901f2e | 79 | |
medvdv | 2:65df20ffef51 | 80 | // String drawing |
medvdv | 2:65df20ffef51 | 81 | void String(char* str); // Draw string proportionally |
medvdv | 2:65df20ffef51 | 82 | int StringWidth(char* str); // Calculate string width in px |
medvdv | 0:0a6619901f2e | 83 | |
medvdv | 2:65df20ffef51 | 84 | void Row(int Y, char* str = ""); // Clear one text row and draw string on it |
medvdv | 0:0a6619901f2e | 85 | |
medvdv | 2:65df20ffef51 | 86 | ~lcd5110(); // destruct pin's |
medvdv | 0:0a6619901f2e | 87 | |
medvdv | 0:0a6619901f2e | 88 | }; |
medvdv | 0:0a6619901f2e | 89 |