Version 2.1 of TextLCD_SB1602E (forked).

Dependents:   BME280_environmental_recorder kids_workshop

Fork of SB1602E by Tedd OKANO

Committer:
okano
Date:
Mon Oct 20 12:54:53 2014 +0000
Revision:
0:995f80348e02
Child:
1:fce3e353410c
version 2.0 of TextLCD_SB1602E

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:995f80348e02 1 /** Text LCD module "SB1602E" class library
okano 0:995f80348e02 2 *
okano 0:995f80348e02 3 * @author Tedd OKANO & Masato YAMANISHI
okano 0:995f80348e02 4 * @version 2.0
okano 0:995f80348e02 5 * @date 20-Oct-2014
okano 0:995f80348e02 6 *
okano 0:995f80348e02 7 * SB1602E is an I2C based low voltage text LCD panel (based Sitronix ST7032 chip)
okano 0:995f80348e02 8 * The module by StrawberryLinux
okano 0:995f80348e02 9 * http://strawberry-linux.com/catalog/items?code=27002 (Online shop page (Japanese))
okano 0:995f80348e02 10 * http://strawberry-linux.com/pub/ST7032i.pdf (datasheet of the chip)
okano 0:995f80348e02 11 *
okano 0:995f80348e02 12 * This is a library to operate this module easy.
okano 0:995f80348e02 13 *
okano 0:995f80348e02 14 * Released under the Apache 2 license License
okano 0:995f80348e02 15 *
okano 0:995f80348e02 16 * revision history (class lib name was "TextLCD_SB1602E")
okano 0:995f80348e02 17 * revision 1.0 22-Jan-2010 a. 1st release
okano 0:995f80348e02 18 * revision 1.1 23-Jan-2010 a. class name has been changed from lcd_SB1602E to TextLCD_SB1602E
okano 0:995f80348e02 19 * b. printf() added
okano 0:995f80348e02 20 * c. copyright notice added
okano 0:995f80348e02 21 * revision 1.3 02-May-2014 a. puticon() added (for SB1602B) by Masato YAMANISHI san
okano 0:995f80348e02 22 * revision 2.0 20-Oct-2014 a. class name is changed and published as "SB1602E"
okano 0:995f80348e02 23 * b. re-written for better usability
okano 0:995f80348e02 24 */
okano 0:995f80348e02 25
okano 0:995f80348e02 26 #ifndef MBED_SB1602E
okano 0:995f80348e02 27 #define MBED_SB1602E
okano 0:995f80348e02 28
okano 0:995f80348e02 29 #include <stdarg.h>
okano 0:995f80348e02 30 #include "mbed.h"
okano 0:995f80348e02 31 #include "SB1602E.h"
okano 0:995f80348e02 32
okano 0:995f80348e02 33
okano 0:995f80348e02 34 /** PCA9629A class
okano 0:995f80348e02 35 *
okano 0:995f80348e02 36 * This is a driver code for the PCA9629A stepper motor controller.
okano 0:995f80348e02 37 * This class provides interface for PCA9629A operation and accessing its registers.
okano 0:995f80348e02 38 * Detail information is available on next URL.
okano 0:995f80348e02 39 * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_bus_controller_and_bridge_ics/PCA9629APW.html
okano 0:995f80348e02 40 *
okano 0:995f80348e02 41 * Example:
okano 0:995f80348e02 42 * @code
okano 0:995f80348e02 43 * #include "mbed.h"
okano 0:995f80348e02 44 * #include "SB1602E.h"
okano 0:995f80348e02 45 *
okano 0:995f80348e02 46 * SB1602E lcd( p9, p10 ); // SDA, SCL
okano 0:995f80348e02 47 *
okano 0:995f80348e02 48 * int main() {
okano 0:995f80348e02 49 * lcd.printf( 0, "Hello world!" ); // line# (0 or 1), string
okano 0:995f80348e02 50 * lcd.printf( 1, "pi = %.6f", 3.14159265 );
okano 0:995f80348e02 51 * }
okano 0:995f80348e02 52 * @endcode
okano 0:995f80348e02 53 */
okano 0:995f80348e02 54
okano 0:995f80348e02 55 #define DEFAULT_CONTRAST 0x35
okano 0:995f80348e02 56
okano 0:995f80348e02 57 class SB1602E
okano 0:995f80348e02 58 {
okano 0:995f80348e02 59 public:
okano 0:995f80348e02 60
okano 0:995f80348e02 61 /** Create a SB1602E instance which is connected to specified I2C pins with specified address
okano 0:995f80348e02 62 *
okano 0:995f80348e02 63 * @param I2C_sda I2C-bus SDA pin
okano 0:995f80348e02 64 * @param I2C_scl I2C-bus SCL pin
okano 0:995f80348e02 65 * @param init_massage string to initialize the LCD
okano 0:995f80348e02 66 */
okano 0:995f80348e02 67 SB1602E( PinName I2C_sda, PinName I2C_scl, char *init_massage = NULL );
okano 0:995f80348e02 68
okano 0:995f80348e02 69 /** Create a PCA9629A instance connected to specified I2C pins with specified address
okano 0:995f80348e02 70 *
okano 0:995f80348e02 71 * @param I2C object (instance)
okano 0:995f80348e02 72 * @param init_massage string to initialize the LCD
okano 0:995f80348e02 73 */
okano 0:995f80348e02 74 SB1602E( I2C &i2c_, char *init_massage = NULL );
okano 0:995f80348e02 75
okano 0:995f80348e02 76 /** Destractor
okano 0:995f80348e02 77 */
okano 0:995f80348e02 78 ~SB1602E();
okano 0:995f80348e02 79
okano 0:995f80348e02 80 /** Printf
okano 0:995f80348e02 81 *
okano 0:995f80348e02 82 * pirntf function with line number.
okano 0:995f80348e02 83 * it can be used like
okano 0:995f80348e02 84 *
okano 0:995f80348e02 85 * lcd.printf( 0, "Hello world!" );
okano 0:995f80348e02 86 * lcd.printf( 1, "pi = %.6f", 3.14159265 );
okano 0:995f80348e02 87 *
okano 0:995f80348e02 88 * @param line line# (0 for upper, 1 for lower)
okano 0:995f80348e02 89 * @param format following parameters are compatible to stdout's printf
okano 0:995f80348e02 90 */
okano 0:995f80348e02 91 void printf( char line, char *format, ... );
okano 0:995f80348e02 92
okano 0:995f80348e02 93 /** Put character : "putc()"
okano 0:995f80348e02 94 *
okano 0:995f80348e02 95 * @param line line# (0 for upper, 1 for lower)
okano 0:995f80348e02 96 * @param c character code
okano 0:995f80348e02 97 */
okano 0:995f80348e02 98 void putc( char line, char c );
okano 0:995f80348e02 99
okano 0:995f80348e02 100 /** Put string : "puts()"
okano 0:995f80348e02 101 *
okano 0:995f80348e02 102 * @param line line# (0 for upper, 1 for lower)
okano 0:995f80348e02 103 * @param s pointer to a string data
okano 0:995f80348e02 104 */
okano 0:995f80348e02 105 void puts( char line, char *s );
okano 0:995f80348e02 106
okano 0:995f80348e02 107 /** Put character into specified screen position
okano 0:995f80348e02 108 *
okano 0:995f80348e02 109 * @param c character code
okano 0:995f80348e02 110 * @param x horizontal character position on the LCD
okano 0:995f80348e02 111 * @param y vertical character position on the LCD
okano 0:995f80348e02 112 */
okano 0:995f80348e02 113 void putcxy( char c, char x, char y );
okano 0:995f80348e02 114
okano 0:995f80348e02 115 /** Clear the LCD
okano 0:995f80348e02 116 */
okano 0:995f80348e02 117 void clear( void );
okano 0:995f80348e02 118
okano 0:995f80348e02 119 /** Contrast adjustment
okano 0:995f80348e02 120 *
okano 0:995f80348e02 121 * @param contrast value (from 0x00 to 0x3E)
okano 0:995f80348e02 122 */
okano 0:995f80348e02 123 void contrast( char contrast );
okano 0:995f80348e02 124
okano 0:995f80348e02 125 /** Put a custom character given as bitmap data
okano 0:995f80348e02 126 *
okano 0:995f80348e02 127 * @param c_code character code
okano 0:995f80348e02 128 * @param cg pointer to bitmap data (array of 8 bytes)
okano 0:995f80348e02 129 * @param x horizontal character position on the LCD
okano 0:995f80348e02 130 * @param y vertical character position on the LCD
okano 0:995f80348e02 131 */
okano 0:995f80348e02 132 void put_custom_char( char c_code, const char *cg, char x, char y );
okano 0:995f80348e02 133
okano 0:995f80348e02 134 /** Set CGRAM (set custom bitmap as a character)
okano 0:995f80348e02 135 *
okano 0:995f80348e02 136 * @param c_code character code
okano 0:995f80348e02 137 * @param cg pointer to bitmap data (array of 8 bytes)
okano 0:995f80348e02 138 */
okano 0:995f80348e02 139 void set_CGRAM( char char_code, const char* cg );
okano 0:995f80348e02 140
okano 0:995f80348e02 141 /** Set CGRAM (set custom bitmap as a character)
okano 0:995f80348e02 142 *
okano 0:995f80348e02 143 * @param c_code character code
okano 0:995f80348e02 144 * @param v bitmap data (5 bit pattern in this variable are copied to all row of a character bitmap)
okano 0:995f80348e02 145 */
okano 0:995f80348e02 146 void set_CGRAM( char char_code, char v );
okano 0:995f80348e02 147
okano 0:995f80348e02 148 /** Icon operation (for SB1602B)
okano 0:995f80348e02 149 *
okano 0:995f80348e02 150 * @param flg bitpattern to choose ICON
okano 0:995f80348e02 151 */
okano 0:995f80348e02 152 void puticon( unsigned short flg );
okano 0:995f80348e02 153
okano 0:995f80348e02 154 private:
okano 0:995f80348e02 155 char curs[2];
okano 0:995f80348e02 156 void init( char *init_massage );
okano 0:995f80348e02 157 void clear_lest_of_line( char line );
okano 0:995f80348e02 158 int lcd_write( char first, char second );
okano 0:995f80348e02 159 int lcd_command( char command );
okano 0:995f80348e02 160 int lcd_data( char data );
okano 0:995f80348e02 161 I2C *i2c_p;
okano 0:995f80348e02 162 I2C &i2c;
okano 0:995f80348e02 163 char i2c_addr;
okano 0:995f80348e02 164
okano 0:995f80348e02 165 private:
okano 0:995f80348e02 166 typedef enum {
okano 0:995f80348e02 167 #ifdef INIT_VALUE_DATASHEET_ORIGINAL
okano 0:995f80348e02 168 Comm_FunctionSet_Normal = 0x38,
okano 0:995f80348e02 169 Comm_FunctionSet_Extended = 0x39,
okano 0:995f80348e02 170 Comm_InternalOscFrequency = 0x14,
okano 0:995f80348e02 171 Comm_ContrastSet = 0x78,
okano 0:995f80348e02 172 Comm_PwrIconContrast = 0x5E,
okano 0:995f80348e02 173 Comm_FollowerCtrl = 0x6A,
okano 0:995f80348e02 174 Comm_DisplayOnOff = 0x0C,
okano 0:995f80348e02 175 Comm_ClearDisplay = 0x01,
okano 0:995f80348e02 176 Comm_EntryModeSet = 0x06,
okano 0:995f80348e02 177 #else
okano 0:995f80348e02 178 Comm_FunctionSet_Normal = 0x38,
okano 0:995f80348e02 179 Comm_FunctionSet_Extended = 0x39,
okano 0:995f80348e02 180 Comm_InternalOscFrequency = 0x14,
okano 0:995f80348e02 181 Comm_ContrastSet = 0x70,
okano 0:995f80348e02 182 Comm_PwrIconContrast = 0x5C,
okano 0:995f80348e02 183 Comm_FollowerCtrl = 0x60,
okano 0:995f80348e02 184 Comm_DisplayOnOff = 0x0C,
okano 0:995f80348e02 185 Comm_ClearDisplay = 0x01,
okano 0:995f80348e02 186 Comm_EntryModeSet = 0x04,
okano 0:995f80348e02 187 Comm_ReturnHome = 0x02,
okano 0:995f80348e02 188 #endif
okano 0:995f80348e02 189 Comm_SetCGRAM = 0x40
okano 0:995f80348e02 190 } _commands;
okano 0:995f80348e02 191
okano 0:995f80348e02 192 typedef enum {
okano 0:995f80348e02 193 MaxCharsInALine = 0x10, // buffer depth for one line (no scroll function used)
okano 0:995f80348e02 194 COMMAND = 0x00,
okano 0:995f80348e02 195 DATA = 0x40
okano 0:995f80348e02 196 } _constants;
okano 0:995f80348e02 197 }
okano 0:995f80348e02 198 ;
okano 0:995f80348e02 199
okano 0:995f80348e02 200 #endif
okano 0:995f80348e02 201
okano 0:995f80348e02 202
okano 0:995f80348e02 203
okano 0:995f80348e02 204
okano 0:995f80348e02 205
okano 0:995f80348e02 206
okano 0:995f80348e02 207
okano 0:995f80348e02 208