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 :-)

Committer:
medvdv
Date:
Fri Dec 07 21:53:31 2012 +0000
Revision:
3:03c7cb24222d
Parent:
2:65df20ffef51
Child:
4:82917c164f2b
bit more

Who changed what in which revision?

UserRevisionLine numberNew 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 //
medvdv 2:65df20ffef51 8 // Proportional font with 8px height
medvdv 2:65df20ffef51 9 //
medvdv 2:65df20ffef51 10
medvdv 0:0a6619901f2e 11 typedef struct {
medvdv 0:0a6619901f2e 12
medvdv 0:0a6619901f2e 13 char first_code;
medvdv 0:0a6619901f2e 14 char glyphs_total;
medvdv 0:0a6619901f2e 15 const char* widths;
medvdv 0:0a6619901f2e 16 const char** glyphs;
medvdv 0:0a6619901f2e 17
medvdv 0:0a6619901f2e 18 } lcd5110font;
medvdv 0:0a6619901f2e 19
medvdv 2:65df20ffef51 20 // Contrast value depends of voltage and other factors
medvdv 3:03c7cb24222d 21 #define DEFAULT_CONTRAST 36
medvdv 2:65df20ffef51 22
medvdv 2:65df20ffef51 23 //
medvdv 2:65df20ffef51 24 // Nokia 5110 LCD Interface Class
medvdv 2:65df20ffef51 25 //
medvdv 2:65df20ffef51 26
medvdv 0:0a6619901f2e 27 class lcd5110 {
medvdv 0:0a6619901f2e 28
medvdv 2:65df20ffef51 29 // SPI and other pin's
medvdv 0:0a6619901f2e 30 SPI* spi;
medvdv 0:0a6619901f2e 31 DigitalOut* rst;
medvdv 0:0a6619901f2e 32 DigitalOut* sce;
medvdv 0:0a6619901f2e 33 DigitalOut* dc;
medvdv 2:65df20ffef51 34
medvdv 2:65df20ffef51 35 // Current font
medvdv 0:0a6619901f2e 36 lcd5110font font;
medvdv 0:0a6619901f2e 37
medvdv 2:65df20ffef51 38 // Contrast value for next reset
medvdv 0:0a6619901f2e 39 char contrast;
medvdv 0:0a6619901f2e 40
medvdv 2:65df20ffef51 41 // Invert and bold flags
medvdv 0:0a6619901f2e 42 bool invert;
medvdv 0:0a6619901f2e 43 bool bold;
medvdv 0:0a6619901f2e 44
medvdv 2:65df20ffef51 45 // current write position
medvdv 0:0a6619901f2e 46 int X, Y;
medvdv 0:0a6619901f2e 47
medvdv 2:65df20ffef51 48 // Generic SPI writer
medvdv 0:0a6619901f2e 49 void write(char byte, bool cmd = false);
medvdv 0:0a6619901f2e 50
medvdv 0:0a6619901f2e 51 public:
medvdv 0:0a6619901f2e 52
medvdv 2:65df20ffef51 53 // Supply LCD connected pin's here for your design
medvdv 0:0a6619901f2e 54 lcd5110(PinName mosi= p11, PinName sclk = p13, PinName dc = p10, PinName sce = p8, PinName rst = p9);
medvdv 0:0a6619901f2e 55
medvdv 2:65df20ffef51 56 void Reset(); // Reset LCD, configure defaults and contrast
medvdv 2:65df20ffef51 57 void Clear(char pattern = 0); // Clear - fill all by 8bit line 'pattern'
medvdv 2:65df20ffef51 58 void PowerOff(); // LCD power off
medvdv 2:65df20ffef51 59
medvdv 2:65df20ffef51 60 void Contrast(char contrast = DEFAULT_CONTRAST ); // Change contrast
medvdv 0:0a6619901f2e 61
medvdv 2:65df20ffef51 62 void Invert(bool invert = true); // Switch inverting of chars
medvdv 2:65df20ffef51 63 void Bold(bool bold = true); // Switch bold mode (repeat each char row twice)
medvdv 0:0a6619901f2e 64
medvdv 2:65df20ffef51 65 void XY(int x = 0, int y = 0); // Change write position X in pixels [0..83], Y in rows [0..5]
medvdv 0:0a6619901f2e 66
medvdv 2:65df20ffef51 67 // Row write
medvdv 2:65df20ffef51 68 void Write(char byte); // One 8bit row
medvdv 2:65df20ffef51 69 void Write(char byte, int count); // One 8bit row * 'count' times
medvdv 2:65df20ffef51 70 void Write(char* data, int size); // 'size' 8bit rows
medvdv 2:65df20ffef51 71 void Write2(char* data, int size); // Bold: 'size' 8bit rows * 2
medvdv 0:0a6619901f2e 72
medvdv 2:65df20ffef51 73 // Character drawing
medvdv 2:65df20ffef51 74 void Character(char chr); // Draw one font character with invert and bold opt-s
medvdv 2:65df20ffef51 75 int CharacterWidth(char chr); // Calculate one character width with bold opt-n
medvdv 0:0a6619901f2e 76
medvdv 2:65df20ffef51 77 // String drawing
medvdv 2:65df20ffef51 78 void String(char* str); // Draw string proportionally
medvdv 2:65df20ffef51 79 int StringWidth(char* str); // Calculate string width in px
medvdv 0:0a6619901f2e 80
medvdv 2:65df20ffef51 81 void Row(int Y, char* str = ""); // Clear one text row and draw string on it
medvdv 0:0a6619901f2e 82
medvdv 2:65df20ffef51 83 ~lcd5110(); // destruct pin's
medvdv 0:0a6619901f2e 84
medvdv 0:0a6619901f2e 85 };
medvdv 0:0a6619901f2e 86