Version 2.0 of TextLCD_SB1602E. The old class driver has been rewritten in more common manner of I2C devices.
Dependents: SB1602E_Hello BME280_LCD PreHeater PreHeater ... more
SB1602E.h
00001 /** Text LCD module "SB1602E" class library 00002 * 00003 * @author Tedd OKANO, Masato YAMANISHI & Toyomasa Watarai 00004 * @version 2.1 00005 * @date 07-April-2015 00006 * 00007 * SB1602E is an I2C based low voltage text LCD panel (based Sitronix ST7032 chip) 00008 * The module by StrawberryLinux 00009 * http://strawberry-linux.com/catalog/items?code=27002 (Online shop page (Japanese)) 00010 * http://strawberry-linux.com/pub/ST7032i.pdf (datasheet of the chip) 00011 * 00012 * This is a library to operate this module easy. 00013 * 00014 * Released under the Apache 2 license License 00015 * 00016 * revision history (class lib name was "TextLCD_SB1602E") 00017 * revision 1.0 22-Jan-2010 a. 1st release 00018 * revision 1.1 23-Jan-2010 a. class name has been changed from lcd_SB1602E to TextLCD_SB1602E 00019 * b. printf() added 00020 * c. copyright notice added 00021 * revision 1.3 02-May-2014 a. puticon() added (for SB1602B) by Masato YAMANISHI san 00022 * revision 2.0 20-Oct-2014 a. class name is changed and published as "SB1602E" 00023 * b. re-written for better usability 00024 * revision 2.1 07-Apl-2015 a. add printf() with X and Y position 00025 * b. add setter for number of chars in a line (e.g. 8x2 LCD support) 00026 */ 00027 00028 #ifndef MBED_SB1602E 00029 #define MBED_SB1602E 00030 00031 #include <stdarg.h> 00032 #include "mbed.h" 00033 #include "SB1602E.h" 00034 00035 00036 /** SB1602E class 00037 * 00038 * This is a driver code for the SB1602E LCD module. 00039 * This class provides interface for ST7032 operation and accessing its registers. 00040 * 00041 * Example: 00042 * @code 00043 * #include "mbed.h" 00044 * #include "SB1602E.h" 00045 * 00046 * SB1602E lcd( p9, p10 ); // SDA, SCL 00047 * 00048 * int main() { 00049 * lcd.printf( 0, "Hello world!" ); // line# (0 or 1), string 00050 * lcd.printf( 1, "pi = %.6f", 3.14159265 ); 00051 * } 00052 * @endcode 00053 */ 00054 class SB1602E 00055 { 00056 public: 00057 00058 /** Create a SB1602E instance which is connected to specified I2C pins with specified address 00059 * 00060 * @param I2C_sda I2C-bus SDA pin 00061 * @param I2C_scl I2C-bus SCL pin 00062 * @param init_massage string to initialize the LCD 00063 */ 00064 SB1602E( PinName I2C_sda, PinName I2C_scl, char *init_massage = NULL ); 00065 00066 /** Create a PCA9629A instance connected to specified I2C pins with specified address 00067 * 00068 * @param I2C object (instance) 00069 * @param init_massage string to initialize the LCD 00070 */ 00071 SB1602E( I2C &i2c_, char *init_massage = NULL ); 00072 00073 /** Destractor 00074 */ 00075 ~SB1602E(); 00076 00077 /** Printf 00078 * 00079 * printf function with line number. 00080 * it can be used like 00081 * 00082 * lcd.printf( 0, "Hello world!" ); 00083 * lcd.printf( 1, "pi = %.6f", 3.14159265 ); 00084 * 00085 * @param line line# (0 for upper, 1 for lower) 00086 * @param format following parameters are compatible to stdout's printf 00087 */ 00088 void printf( char line, char *format, ... ); 00089 00090 /** Printf 00091 * 00092 * printf function with X and Y character position on the LCD. 00093 * it can be used like 00094 * 00095 * lcd.printf( 0, 0, "Hello world!" ); 00096 * lcd.printf( 4, 1, "pi = %.6f", 3.14159265 ); 00097 * 00098 * @param x X horizontal character position on the LCD 00099 * @param y Y vertical character position on the LCD 00100 * @param format following parameters are compatible to stdout's printf 00101 */ 00102 void printf( char x, char y, char *format, ... ); 00103 00104 /** Put character : "putc()" 00105 * 00106 * @param line line# (0 for upper, 1 for lower) 00107 * @param c character code 00108 */ 00109 void putc( char line, char c ); 00110 00111 /** Put string : "puts()" 00112 * 00113 * @param line line# (0 for upper, 1 for lower) 00114 * @param s pointer to a string data 00115 */ 00116 void puts( char line, char *s ); 00117 00118 /** Put character into specified screen position 00119 * 00120 * @param c character code 00121 * @param x horizontal character position on the LCD 00122 * @param y vertical character position on the LCD 00123 */ 00124 void putcxy( char c, char x, char y ); 00125 00126 /** Clear the LCD 00127 */ 00128 void clear( void ); 00129 00130 /** Contrast adjustment 00131 * 00132 * @param contrast value (from 0x00 to 0x3E) 00133 */ 00134 void contrast( char contrast ); 00135 00136 /** Put a custom character given as bitmap data 00137 * 00138 * @param c_code character code 00139 * @param cg pointer to bitmap data (array of 8 bytes) 00140 * @param x horizontal character position on the LCD 00141 * @param y vertical character position on the LCD 00142 */ 00143 void put_custom_char( char c_code, const char *cg, char x, char y ); 00144 00145 /** Set CGRAM (set custom bitmap as a character) 00146 * 00147 * @param c_code character code 00148 * @param cg pointer to bitmap data (array of 8 bytes) 00149 */ 00150 void set_CGRAM( char char_code, const char* cg ); 00151 00152 /** Set CGRAM (set custom bitmap as a character) 00153 * 00154 * @param c_code character code 00155 * @param v bitmap data (5 bit pattern in this variable are copied to all row of a character bitmap) 00156 */ 00157 void set_CGRAM( char char_code, char v ); 00158 00159 /** Icon operation (for SB1602B) 00160 * 00161 * @param flg bitpattern to choose ICON 00162 */ 00163 void puticon( unsigned short flg ); 00164 00165 /** Set number of charactors in a line 00166 * 00167 * @param ch number of charactors in a line 00168 */ 00169 void setCharsInLine( char ch ) { charsInLine = ch; }; 00170 00171 private: 00172 char curs[2]; 00173 void init( char *init_massage ); 00174 void clear_lest_of_line( char line ); 00175 int lcd_write( char first, char second ); 00176 int lcd_command( char command ); 00177 int lcd_data( char data ); 00178 I2C *i2c_p; 00179 I2C &i2c; 00180 char i2c_addr; 00181 char charsInLine; 00182 00183 private: 00184 typedef enum { 00185 #ifdef INIT_VALUE_DATASHEET_ORIGINAL 00186 Comm_FunctionSet_Normal = 0x38, 00187 Comm_FunctionSet_Extended = 0x39, 00188 Comm_InternalOscFrequency = 0x14, 00189 Comm_ContrastSet = 0x78, 00190 Comm_PwrIconContrast = 0x5E, 00191 Comm_FollowerCtrl = 0x6A, 00192 Comm_DisplayOnOff = 0x0C, 00193 Comm_ClearDisplay = 0x01, 00194 Comm_EntryModeSet = 0x06, 00195 #else 00196 Comm_FunctionSet_Normal = 0x38, 00197 Comm_FunctionSet_Extended = 0x39, 00198 Comm_InternalOscFrequency = 0x14, 00199 Comm_ContrastSet = 0x70, 00200 Comm_PwrIconContrast = 0x5C, 00201 Comm_FollowerCtrl = 0x60, 00202 Comm_DisplayOnOff = 0x0C, 00203 Comm_ClearDisplay = 0x01, 00204 Comm_EntryModeSet = 0x04, 00205 Comm_ReturnHome = 0x02, 00206 #endif 00207 Comm_SetCGRAM = 0x40 00208 } _commands; 00209 00210 typedef enum { 00211 MaxCharsInALine = 0x10, // buffer depth for one line (no scroll function used) 00212 COMMAND = 0x00, 00213 DATA = 0x40 00214 } _constants; 00215 } 00216 ; 00217 00218 #endif 00219 00220 00221 00222 00223 00224 00225 00226
Generated on Fri Jul 15 2022 01:39:23 by 1.7.2