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 Jan 31 20:25:57 2014 +0000
Revision:
5:c37e5454bdb2
Parent:
4:82917c164f2b
Child:
6:cd44333c061b
Added Power On/Off; Added Inverse Mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
medvdv 0:0a6619901f2e 1 //
medvdv 0:0a6619901f2e 2 // 5110 LCD Driver
medvdv 4:82917c164f2b 3 // (c) 2012 @medvdv - Alexander Medvedev
medvdv 0:0a6619901f2e 4 //
medvdv 0:0a6619901f2e 5
medvdv 2:65df20ffef51 6 //
medvdv 2:65df20ffef51 7 // Proportional font with 8px height
medvdv 2:65df20ffef51 8 //
medvdv 2:65df20ffef51 9
medvdv 0:0a6619901f2e 10 typedef struct {
medvdv 0:0a6619901f2e 11
medvdv 0:0a6619901f2e 12 char first_code;
medvdv 0:0a6619901f2e 13 char glyphs_total;
medvdv 0:0a6619901f2e 14 const char* widths;
medvdv 0:0a6619901f2e 15 const char** glyphs;
medvdv 0:0a6619901f2e 16
medvdv 0:0a6619901f2e 17 } lcd5110font;
medvdv 0:0a6619901f2e 18
medvdv 2:65df20ffef51 19 // Contrast value depends of voltage and other factors
medvdv 5:c37e5454bdb2 20 #define DEFAULT_CONTRAST 30
medvdv 2:65df20ffef51 21
medvdv 2:65df20ffef51 22 //
medvdv 2:65df20ffef51 23 // Nokia 5110 LCD Interface Class
medvdv 2:65df20ffef51 24 //
medvdv 2:65df20ffef51 25
medvdv 0:0a6619901f2e 26 class lcd5110 {
medvdv 0:0a6619901f2e 27
medvdv 2:65df20ffef51 28 // SPI and other pin's
medvdv 0:0a6619901f2e 29 SPI* spi;
medvdv 0:0a6619901f2e 30 DigitalOut* rst;
medvdv 0:0a6619901f2e 31 DigitalOut* sce;
medvdv 0:0a6619901f2e 32 DigitalOut* dc;
medvdv 2:65df20ffef51 33
medvdv 2:65df20ffef51 34 // Current font
medvdv 0:0a6619901f2e 35 lcd5110font font;
medvdv 0:0a6619901f2e 36
medvdv 2:65df20ffef51 37 // Contrast value for next reset
medvdv 0:0a6619901f2e 38 char contrast;
medvdv 0:0a6619901f2e 39
medvdv 2:65df20ffef51 40 // Invert and bold flags
medvdv 0:0a6619901f2e 41 bool invert;
medvdv 0:0a6619901f2e 42 bool bold;
medvdv 0:0a6619901f2e 43
medvdv 2:65df20ffef51 44 // current write position
medvdv 0:0a6619901f2e 45 int X, Y;
medvdv 0:0a6619901f2e 46
medvdv 2:65df20ffef51 47 // Generic SPI writer
medvdv 0:0a6619901f2e 48 void write(char byte, bool cmd = false);
medvdv 0:0a6619901f2e 49
medvdv 0:0a6619901f2e 50 public:
medvdv 0:0a6619901f2e 51
medvdv 2:65df20ffef51 52 // Supply LCD connected pin's here for your design
medvdv 0:0a6619901f2e 53 lcd5110(PinName mosi= p11, PinName sclk = p13, PinName dc = p10, PinName sce = p8, PinName rst = p9);
medvdv 0:0a6619901f2e 54
medvdv 2:65df20ffef51 55 void Reset(); // Reset LCD, configure defaults and contrast
medvdv 2:65df20ffef51 56 void Clear(char pattern = 0); // Clear - fill all by 8bit line 'pattern'
medvdv 5:c37e5454bdb2 57 void Power(bool power = true); // LCD power off / wake up
medvdv 5:c37e5454bdb2 58 void InverseMode(bool inverse = true); // Inverse mode for all LCD
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 4:82917c164f2b 73 // Character drawing
medvdv 4:82917c164f2b 74 void Character(char chr); // Draw one font character (with invert and bold opt-s)
medvdv 4:82917c164f2b 75 // ! automaticaly does next line if char is wider then space left
medvdv 4:82917c164f2b 76 int CharacterWidth(char chr); // Calculate one character width (with bold opt-n)
medvdv 0:0a6619901f2e 77
medvdv 2:65df20ffef51 78 // String drawing
medvdv 2:65df20ffef51 79 void String(char* str); // Draw string proportionally
medvdv 2:65df20ffef51 80 int StringWidth(char* str); // Calculate string width in px
medvdv 0:0a6619901f2e 81
medvdv 2:65df20ffef51 82 void Row(int Y, char* str = ""); // Clear one text row and draw string on it
medvdv 0:0a6619901f2e 83
medvdv 2:65df20ffef51 84 ~lcd5110(); // destruct pin's
medvdv 0:0a6619901f2e 85
medvdv 0:0a6619901f2e 86 };
medvdv 0:0a6619901f2e 87