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

Revision:
4:1bd241d1fad0
Parent:
3:c0e409cda493
Child:
5:ff31feb7d966
diff -r c0e409cda493 -r 1bd241d1fad0 lcd128lib.cpp
--- a/lcd128lib.cpp	Wed Feb 05 00:59:14 2014 +0000
+++ b/lcd128lib.cpp	Mon May 26 20:14:58 2014 +0000
@@ -14,15 +14,17 @@
 //
 
 // SPI writer with command / data switch
+
 void lcd128::write(char data, bool cmd)
 {
-    a0  =  cmd ? 0:1;
+    a0  =  cmd ? 0 : 1;
     cs  = 0;
     spi.write(data);
     cs  = 1;
 }
  
-// Constructor  
+// Constructor, SPI setup and defaults  
+
 lcd128::lcd128(PinName mosi, PinName sclk, PinName p_a0, PinName p_cs, PinName p_rst):
 spi(mosi, NC, sclk), rst(p_rst), cs(p_cs), a0(p_a0)
 {
@@ -41,31 +43,37 @@
     underline = false;   
 } 
  
- // Start inverting chars
+// Inverting chars on / off
+
 void lcd128::Invert(bool invert)
 {
     this -> invert = invert;
 }
 
-// Start bold mode (repeat twice wide)
+// Bold mode (twice wide chars) on / off
+
 void lcd128::Bold(bool bold)
 {
     this -> bold = bold;
 }
 
-// Start bold mode (repeat twice wide)
+// Underline mode on / off
+
 void lcd128::Underline(bool underline)
 {
     this -> underline = underline;
 }
 
 // Reset LCD, configure defaults and contrast
+
 void lcd128::Reset()
 {
     a0  = 0;
     cs  = 1;
     rst = 0;
+    
     wait_us(50); 
+    
     rst = 1;
     
     wait_ms(5);
@@ -90,7 +98,8 @@
     Update();
 }
 
-// LCD power off
+// LCD power on / off
+
 void lcd128::Power(bool power)
 {
     if (!power) {
@@ -102,6 +111,8 @@
     }
 }
 
+// Invert LCD on / off
+
 void lcd128::InverseMode(bool invert)
 {
     if (!invert) 
@@ -111,6 +122,7 @@
 }
 
 // Update buffer to LCD
+
 void lcd128::Update()
 {   
     char* p = buffer;
@@ -124,14 +136,14 @@
 }
 
 // Clear all buffer or just one row
+
 void lcd128::Clear(int row)
 {
     if(row == -1) 
         memset(buffer, 0, sizeof(buffer));
     else {
         if(row<0) row=0;
-        if(row>LCD_Y) row=0;
-        
+        if(row>LCD_Y) row=0;  
         memset(buffer+row*LCD_X, 0, LCD_X);
     }
 
@@ -141,6 +153,7 @@
 // Change current output position
 // X in pixels [0..LCD_X-1]
 // Y in rows   [0..LCD_Y-1]
+
 void lcd128::XY(int x, int y)
 {
     if (x<0)  x=0;
@@ -154,6 +167,7 @@
 
 // Write one 8bit row 
 // with inversion and XY update
+
 void lcd128::Write(char byte)
 {
     if (underline) byte |= 0x80;
@@ -166,12 +180,14 @@
 }
 
 // Write array of 8bit rows
+
 void lcd128::Write(char* data, int size)
 {
     for (int i=0; i<size; i++) Write(data[i]);
 }
 
 // Write array of 8bit rows, twice each
+
 void lcd128::Write2(char* data, int size)
 {
     for (int i=0; i<size; i++) {
@@ -181,6 +197,7 @@
 }
 
 // Write 8bit row 'count' times
+
 void lcd128::Write(char byte, int count)
 {
     for (int i=0; i<count; i++) Write(byte);
@@ -188,6 +205,7 @@
 
 // Draw one proportional font character
 // Jump to next line if empty space is not enought
+
 void lcd128::Character(char chr)
 {
     if( chr < font.first_code ) return;
@@ -218,6 +236,7 @@
 
 // Calculate width of concrete character 
 // takes into account bold setting 
+
 int lcd128::CharacterWidth(char chr)
 {
     if( chr < font.first_code ) return 0;
@@ -232,12 +251,14 @@
 }
 
 // Write string
+
 void lcd128::String(char* str)
 {
     while(*str) Character(*str++);
 }
 
 // Predict string width
+
 int lcd128::StringWidth(char* str)
 {
     int width = 0;
@@ -249,6 +270,7 @@
 
 // Clear one line, 
 // then write string from it's begin 
+
 void lcd128::Row(int Y, char* str)
 {
     Clear(Y);
@@ -256,6 +278,8 @@
     String(str);
 }
 
+// Same, but center text
+
 void lcd128::RowCenter(int Y, char* str)
 {
     Clear(Y);
@@ -263,6 +287,9 @@
     String(str);
 }   
 
+// Draw progress bar
+// fill from 0.0f to 1.0f
+
 void lcd128::Bar(int width, float fill)
 {
     if (width < 2) return;
@@ -276,5 +303,4 @@
     Write(LCD_BAR_F, a);
     Write(LCD_BAR_U, b);
     Write(LCD_BAR_E);
-
 }
\ No newline at end of file