Lightweight proportional text library for C12832 LCD. Easy to modify, fast, robust and compact. Nice font, good for text driven menus, messages, etc. Fell free to use and modify in any projects.

Dependents:   app-board-lcd128

Documentation will be here later.

Usage sample:

Import programapp-board-lcd128

Sample usage of lightweight C12832 LCD library

Committer:
medvdv
Date:
Wed May 28 10:09:01 2014 +0000
Revision:
5:ff31feb7d966
Parent:
4:1bd241d1fad0
Child:
6:5cd32671a837
"unsigned char" where we have bit rows, 5 new characters for interface - checkbox on/off, radio button on/off, selector arrow

Who changed what in which revision?

UserRevisionLine numberNew contents of line
medvdv 0:6ac8f630d9a0 1 //
medvdv 0:6ac8f630d9a0 2 // MBED Application Board
medvdv 0:6ac8f630d9a0 3 // Lightweight C12832 LCD library
medvdv 0:6ac8f630d9a0 4 // 2014, Alexander Medvedev, @medvdv
medvdv 0:6ac8f630d9a0 5 //
medvdv 0:6ac8f630d9a0 6
medvdv 0:6ac8f630d9a0 7 //
medvdv 0:6ac8f630d9a0 8 // BC12832 LCD
medvdv 0:6ac8f630d9a0 9 // Base geometry: 128 x 32 px
medvdv 0:6ac8f630d9a0 10 // X - [0..127] pixels
medvdv 0:6ac8f630d9a0 11 // Y - [0..3] 8 bit rows
medvdv 0:6ac8f630d9a0 12 // 512 byte total buffer size
medvdv 0:6ac8f630d9a0 13 //
medvdv 0:6ac8f630d9a0 14
medvdv 5:ff31feb7d966 15 #define LCD_X 128 // In pixels
medvdv 5:ff31feb7d966 16 #define LCD_Y 4 // In rows by 8 pixels each
medvdv 5:ff31feb7d966 17 #define LCD_SIZE 512 // In bytes, = LCD_X*LCD_Y
medvdv 1:17443d6d2740 18
medvdv 0:6ac8f630d9a0 19 //
medvdv 0:6ac8f630d9a0 20 // Proportional font
medvdv 0:6ac8f630d9a0 21 //
medvdv 0:6ac8f630d9a0 22
medvdv 0:6ac8f630d9a0 23 typedef struct {
medvdv 5:ff31feb7d966 24 unsigned char first_code, glyphs_total;
medvdv 5:ff31feb7d966 25 const unsigned char* widths;
medvdv 5:ff31feb7d966 26 const unsigned char** glyphs;
medvdv 0:6ac8f630d9a0 27 } lcd128font;
medvdv 0:6ac8f630d9a0 28
medvdv 1:17443d6d2740 29 //
medvdv 1:17443d6d2740 30 // Progress bar shape
medvdv 1:17443d6d2740 31 // Drawed as BFFF...FFUU...UUUE
medvdv 1:17443d6d2740 32 // B - Begin one
medvdv 1:17443d6d2740 33 // F - Filled zone
medvdv 1:17443d6d2740 34 // U - Empty zone
medvdv 1:17443d6d2740 35 // E - End one
medvdv 1:17443d6d2740 36 //
medvdv 1:17443d6d2740 37
medvdv 5:ff31feb7d966 38 #define LCD_BAR_B 0x1c
medvdv 5:ff31feb7d966 39 #define LCD_BAR_F 0x3e
medvdv 5:ff31feb7d966 40 #define LCD_BAR_U 0x22
medvdv 5:ff31feb7d966 41 #define LCD_BAR_E 0x1c
medvdv 5:ff31feb7d966 42
medvdv 5:ff31feb7d966 43 //
medvdv 5:ff31feb7d966 44 // Special Glyphs for menu / interface
medvdv 5:ff31feb7d966 45 //
medvdv 5:ff31feb7d966 46
medvdv 5:ff31feb7d966 47 #define LCD_RADIO_OFF 128
medvdv 5:ff31feb7d966 48 #define LCD_RADIO_ON 129
medvdv 5:ff31feb7d966 49 #define LCD_CHECKBOX_OFF 130
medvdv 5:ff31feb7d966 50 #define LCD_CHECKBOX_ON 131
medvdv 5:ff31feb7d966 51 #define LCD_SELECTOR 132
medvdv 1:17443d6d2740 52
medvdv 1:17443d6d2740 53 //
medvdv 0:6ac8f630d9a0 54 // lcd128 class
medvdv 0:6ac8f630d9a0 55 //
medvdv 0:6ac8f630d9a0 56
medvdv 0:6ac8f630d9a0 57 class lcd128 {
medvdv 0:6ac8f630d9a0 58
medvdv 0:6ac8f630d9a0 59 // Interface with lcd
medvdv 0:6ac8f630d9a0 60 SPI spi;
medvdv 0:6ac8f630d9a0 61 DigitalOut rst, cs, a0;
medvdv 0:6ac8f630d9a0 62
medvdv 0:6ac8f630d9a0 63 // Current font
medvdv 0:6ac8f630d9a0 64 lcd128font font;
medvdv 0:6ac8f630d9a0 65
medvdv 1:17443d6d2740 66 // Write options
medvdv 0:6ac8f630d9a0 67 bool invert;
medvdv 0:6ac8f630d9a0 68 bool bold;
medvdv 1:17443d6d2740 69 bool underline;
medvdv 0:6ac8f630d9a0 70
medvdv 0:6ac8f630d9a0 71 // buffer
medvdv 5:ff31feb7d966 72 unsigned char buffer[LCD_SIZE];
medvdv 0:6ac8f630d9a0 73
medvdv 0:6ac8f630d9a0 74 // Cursor position
medvdv 0:6ac8f630d9a0 75 int X, Y;
medvdv 0:6ac8f630d9a0 76
medvdv 4:1bd241d1fad0 77 // SPI writer with data / command
medvdv 5:ff31feb7d966 78 void write(unsigned char byte, bool cmd = false);
medvdv 0:6ac8f630d9a0 79
medvdv 0:6ac8f630d9a0 80 public:
medvdv 0:6ac8f630d9a0 81
medvdv 0:6ac8f630d9a0 82 // Supply LCD connected pin's here for your design
medvdv 0:6ac8f630d9a0 83 lcd128(PinName mosi= p5, PinName sclk = p7, PinName a0 = p8, PinName cs = p11, PinName rst = p6);
medvdv 0:6ac8f630d9a0 84
medvdv 0:6ac8f630d9a0 85 // LCD control
medvdv 0:6ac8f630d9a0 86 void Reset(); // Reset LCD, configure defaults
medvdv 0:6ac8f630d9a0 87 void Power(bool power = true); // Power off / on
medvdv 0:6ac8f630d9a0 88 void InverseMode(bool inverse = true); // Invert LCD off / on
medvdv 0:6ac8f630d9a0 89
medvdv 0:6ac8f630d9a0 90 // Buffer -> LCD
medvdv 4:1bd241d1fad0 91 void Update(); // Update LCD from buffer, actually shows drawed
medvdv 3:c0e409cda493 92 void Clear(int row = -1); // Clear all buffer or one concrete row
medvdv 0:6ac8f630d9a0 93
medvdv 0:6ac8f630d9a0 94 // Write mode
medvdv 0:6ac8f630d9a0 95 void Invert(bool invert = true); // Switch inverting of chars
medvdv 0:6ac8f630d9a0 96 void Bold(bool bold = true); // Switch bold mode (repeat each char row twice)
medvdv 1:17443d6d2740 97 void Underline(bool underline = true); // Switch underline mode (last pixel of row always on)
medvdv 0:6ac8f630d9a0 98
medvdv 0:6ac8f630d9a0 99 // Cursor
medvdv 0:6ac8f630d9a0 100 void XY(int x = 0, int y = 0); // Change write position X in pixels, Y in rows
medvdv 0:6ac8f630d9a0 101
medvdv 4:1bd241d1fad0 102 // Vertical 8bit pixel row
medvdv 5:ff31feb7d966 103 void Write(unsigned char byte); // One 8bit row
medvdv 5:ff31feb7d966 104 void Write(unsigned char byte, int count); // One 8bit row * 'count' times
medvdv 5:ff31feb7d966 105 void Write(unsigned char * data, int size); // 'size' 8bit rows
medvdv 5:ff31feb7d966 106 void Write2(unsigned char * data, int size); // Bold: 'size' 8bit rows * 2
medvdv 0:6ac8f630d9a0 107
medvdv 0:6ac8f630d9a0 108 // Character drawing
medvdv 0:6ac8f630d9a0 109 void Character(char chr); // Draw one font character (with invert and bold opt-s)
medvdv 0:6ac8f630d9a0 110 // ! automaticaly does next line if char is wider then space left
medvdv 0:6ac8f630d9a0 111 int CharacterWidth(char chr); // Calculate one character width (with bold opt-n)
medvdv 0:6ac8f630d9a0 112
medvdv 0:6ac8f630d9a0 113 // String drawing
medvdv 0:6ac8f630d9a0 114 void String(char* str); // Draw string proportionally
medvdv 0:6ac8f630d9a0 115 int StringWidth(char* str); // Calculate string width in px
medvdv 0:6ac8f630d9a0 116
medvdv 1:17443d6d2740 117 // Higher level drawers
medvdv 3:c0e409cda493 118 void Row(int Y, char* str = ""); // Clear one text row and draw string on it (left aligned)
medvdv 3:c0e409cda493 119 void RowCenter(int Y, char* str = ""); // Clear one text row and draw string on it (center aligned)
medvdv 1:17443d6d2740 120 void Bar(int width, float fill = 0.0); // Progress bar - one row, width pixels, fill - 0.0..1.0
medvdv 0:6ac8f630d9a0 121 };