Version 2.1 of TextLCD_SB1602E (forked).
Dependents: BME280_environmental_recorder kids_workshop
Fork of SB1602E by
SB1602E.h@4:f2fb19e5486f, 2016-07-23 (annotated)
- Committer:
- MACRUM
- Date:
- Sat Jul 23 14:27:20 2016 +0000
- Revision:
- 4:f2fb19e5486f
- Parent:
- 2:baf578069dfc
Add reset sequence
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:995f80348e02 | 1 | /** Text LCD module "SB1602E" class library |
okano | 0:995f80348e02 | 2 | * |
MACRUM | 2:baf578069dfc | 3 | * @author Tedd OKANO, Masato YAMANISHI & Toyomasa Watarai |
MACRUM | 2:baf578069dfc | 4 | * @version 2.1 |
MACRUM | 2:baf578069dfc | 5 | * @date 07-April-2015 |
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 |
MACRUM | 2:baf578069dfc | 24 | * revision 2.1 07-Apl-2015 a. add printf() with X and Y position |
MACRUM | 2:baf578069dfc | 25 | * b. add setter for number of chars in a line (e.g. 8x2 LCD support) |
okano | 0:995f80348e02 | 26 | */ |
okano | 0:995f80348e02 | 27 | |
okano | 0:995f80348e02 | 28 | #ifndef MBED_SB1602E |
okano | 0:995f80348e02 | 29 | #define MBED_SB1602E |
okano | 0:995f80348e02 | 30 | |
okano | 0:995f80348e02 | 31 | #include <stdarg.h> |
okano | 0:995f80348e02 | 32 | #include "mbed.h" |
okano | 0:995f80348e02 | 33 | #include "SB1602E.h" |
okano | 0:995f80348e02 | 34 | |
okano | 0:995f80348e02 | 35 | |
MACRUM | 2:baf578069dfc | 36 | /** SB1602E class |
okano | 0:995f80348e02 | 37 | * |
MACRUM | 2:baf578069dfc | 38 | * This is a driver code for the SB1602E LCD module. |
MACRUM | 2:baf578069dfc | 39 | * This class provides interface for ST7032 operation and accessing its registers. |
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 | class SB1602E |
okano | 0:995f80348e02 | 55 | { |
okano | 0:995f80348e02 | 56 | public: |
okano | 0:995f80348e02 | 57 | |
okano | 0:995f80348e02 | 58 | /** Create a SB1602E instance which is connected to specified I2C pins with specified address |
okano | 0:995f80348e02 | 59 | * |
okano | 0:995f80348e02 | 60 | * @param I2C_sda I2C-bus SDA pin |
okano | 0:995f80348e02 | 61 | * @param I2C_scl I2C-bus SCL pin |
okano | 0:995f80348e02 | 62 | * @param init_massage string to initialize the LCD |
okano | 0:995f80348e02 | 63 | */ |
MACRUM | 4:f2fb19e5486f | 64 | SB1602E( PinName I2C_sda, PinName I2C_scl, PinName reset, char *init_massage = NULL ); |
okano | 0:995f80348e02 | 65 | |
okano | 0:995f80348e02 | 66 | /** Create a PCA9629A instance connected to specified I2C pins with specified address |
okano | 0:995f80348e02 | 67 | * |
okano | 0:995f80348e02 | 68 | * @param I2C object (instance) |
okano | 0:995f80348e02 | 69 | * @param init_massage string to initialize the LCD |
okano | 0:995f80348e02 | 70 | */ |
okano | 0:995f80348e02 | 71 | SB1602E( I2C &i2c_, char *init_massage = NULL ); |
okano | 0:995f80348e02 | 72 | |
okano | 0:995f80348e02 | 73 | /** Destractor |
okano | 0:995f80348e02 | 74 | */ |
okano | 0:995f80348e02 | 75 | ~SB1602E(); |
okano | 0:995f80348e02 | 76 | |
okano | 0:995f80348e02 | 77 | /** Printf |
okano | 0:995f80348e02 | 78 | * |
MACRUM | 2:baf578069dfc | 79 | * printf function with line number. |
okano | 0:995f80348e02 | 80 | * it can be used like |
okano | 0:995f80348e02 | 81 | * |
okano | 0:995f80348e02 | 82 | * lcd.printf( 0, "Hello world!" ); |
okano | 0:995f80348e02 | 83 | * lcd.printf( 1, "pi = %.6f", 3.14159265 ); |
okano | 0:995f80348e02 | 84 | * |
okano | 0:995f80348e02 | 85 | * @param line line# (0 for upper, 1 for lower) |
okano | 0:995f80348e02 | 86 | * @param format following parameters are compatible to stdout's printf |
okano | 0:995f80348e02 | 87 | */ |
okano | 0:995f80348e02 | 88 | void printf( char line, char *format, ... ); |
okano | 0:995f80348e02 | 89 | |
MACRUM | 2:baf578069dfc | 90 | /** Printf |
MACRUM | 2:baf578069dfc | 91 | * |
MACRUM | 2:baf578069dfc | 92 | * printf function with X and Y character position on the LCD. |
MACRUM | 2:baf578069dfc | 93 | * it can be used like |
MACRUM | 2:baf578069dfc | 94 | * |
MACRUM | 2:baf578069dfc | 95 | * lcd.printf( 0, 0, "Hello world!" ); |
MACRUM | 2:baf578069dfc | 96 | * lcd.printf( 4, 1, "pi = %.6f", 3.14159265 ); |
MACRUM | 2:baf578069dfc | 97 | * |
MACRUM | 2:baf578069dfc | 98 | * @param x X horizontal character position on the LCD |
MACRUM | 2:baf578069dfc | 99 | * @param y Y vertical character position on the LCD |
MACRUM | 2:baf578069dfc | 100 | * @param format following parameters are compatible to stdout's printf |
MACRUM | 2:baf578069dfc | 101 | */ |
MACRUM | 2:baf578069dfc | 102 | void printf( char x, char y, char *format, ... ); |
MACRUM | 2:baf578069dfc | 103 | |
okano | 0:995f80348e02 | 104 | /** Put character : "putc()" |
okano | 0:995f80348e02 | 105 | * |
okano | 0:995f80348e02 | 106 | * @param line line# (0 for upper, 1 for lower) |
okano | 0:995f80348e02 | 107 | * @param c character code |
okano | 0:995f80348e02 | 108 | */ |
okano | 0:995f80348e02 | 109 | void putc( char line, char c ); |
okano | 0:995f80348e02 | 110 | |
okano | 0:995f80348e02 | 111 | /** Put string : "puts()" |
okano | 0:995f80348e02 | 112 | * |
okano | 0:995f80348e02 | 113 | * @param line line# (0 for upper, 1 for lower) |
okano | 0:995f80348e02 | 114 | * @param s pointer to a string data |
okano | 0:995f80348e02 | 115 | */ |
okano | 0:995f80348e02 | 116 | void puts( char line, char *s ); |
okano | 0:995f80348e02 | 117 | |
okano | 0:995f80348e02 | 118 | /** Put character into specified screen position |
okano | 0:995f80348e02 | 119 | * |
okano | 0:995f80348e02 | 120 | * @param c character code |
okano | 0:995f80348e02 | 121 | * @param x horizontal character position on the LCD |
okano | 0:995f80348e02 | 122 | * @param y vertical character position on the LCD |
okano | 0:995f80348e02 | 123 | */ |
okano | 0:995f80348e02 | 124 | void putcxy( char c, char x, char y ); |
okano | 0:995f80348e02 | 125 | |
okano | 0:995f80348e02 | 126 | /** Clear the LCD |
okano | 0:995f80348e02 | 127 | */ |
okano | 0:995f80348e02 | 128 | void clear( void ); |
okano | 0:995f80348e02 | 129 | |
okano | 0:995f80348e02 | 130 | /** Contrast adjustment |
okano | 0:995f80348e02 | 131 | * |
okano | 0:995f80348e02 | 132 | * @param contrast value (from 0x00 to 0x3E) |
okano | 0:995f80348e02 | 133 | */ |
okano | 0:995f80348e02 | 134 | void contrast( char contrast ); |
okano | 0:995f80348e02 | 135 | |
okano | 0:995f80348e02 | 136 | /** Put a custom character given as bitmap data |
okano | 0:995f80348e02 | 137 | * |
okano | 0:995f80348e02 | 138 | * @param c_code character code |
okano | 0:995f80348e02 | 139 | * @param cg pointer to bitmap data (array of 8 bytes) |
okano | 0:995f80348e02 | 140 | * @param x horizontal character position on the LCD |
okano | 0:995f80348e02 | 141 | * @param y vertical character position on the LCD |
okano | 0:995f80348e02 | 142 | */ |
okano | 0:995f80348e02 | 143 | void put_custom_char( char c_code, const char *cg, char x, char y ); |
okano | 0:995f80348e02 | 144 | |
okano | 0:995f80348e02 | 145 | /** Set CGRAM (set custom bitmap as a character) |
okano | 0:995f80348e02 | 146 | * |
okano | 0:995f80348e02 | 147 | * @param c_code character code |
okano | 0:995f80348e02 | 148 | * @param cg pointer to bitmap data (array of 8 bytes) |
okano | 0:995f80348e02 | 149 | */ |
okano | 0:995f80348e02 | 150 | void set_CGRAM( char char_code, const char* cg ); |
okano | 0:995f80348e02 | 151 | |
okano | 0:995f80348e02 | 152 | /** Set CGRAM (set custom bitmap as a character) |
okano | 0:995f80348e02 | 153 | * |
okano | 0:995f80348e02 | 154 | * @param c_code character code |
okano | 0:995f80348e02 | 155 | * @param v bitmap data (5 bit pattern in this variable are copied to all row of a character bitmap) |
okano | 0:995f80348e02 | 156 | */ |
okano | 0:995f80348e02 | 157 | void set_CGRAM( char char_code, char v ); |
okano | 0:995f80348e02 | 158 | |
okano | 0:995f80348e02 | 159 | /** Icon operation (for SB1602B) |
okano | 0:995f80348e02 | 160 | * |
okano | 0:995f80348e02 | 161 | * @param flg bitpattern to choose ICON |
okano | 0:995f80348e02 | 162 | */ |
okano | 0:995f80348e02 | 163 | void puticon( unsigned short flg ); |
okano | 0:995f80348e02 | 164 | |
MACRUM | 2:baf578069dfc | 165 | /** Set number of charactors in a line |
MACRUM | 2:baf578069dfc | 166 | * |
MACRUM | 2:baf578069dfc | 167 | * @param ch number of charactors in a line |
MACRUM | 2:baf578069dfc | 168 | */ |
MACRUM | 2:baf578069dfc | 169 | void setCharsInLine( char ch ) { charsInLine = ch; }; |
MACRUM | 2:baf578069dfc | 170 | |
okano | 0:995f80348e02 | 171 | private: |
okano | 0:995f80348e02 | 172 | char curs[2]; |
okano | 0:995f80348e02 | 173 | void init( char *init_massage ); |
okano | 0:995f80348e02 | 174 | void clear_lest_of_line( char line ); |
okano | 0:995f80348e02 | 175 | int lcd_write( char first, char second ); |
okano | 0:995f80348e02 | 176 | int lcd_command( char command ); |
okano | 0:995f80348e02 | 177 | int lcd_data( char data ); |
okano | 0:995f80348e02 | 178 | I2C *i2c_p; |
okano | 0:995f80348e02 | 179 | I2C &i2c; |
MACRUM | 4:f2fb19e5486f | 180 | DigitalOut *rst_p; |
MACRUM | 4:f2fb19e5486f | 181 | DigitalOut &rst; |
okano | 0:995f80348e02 | 182 | char i2c_addr; |
MACRUM | 2:baf578069dfc | 183 | char charsInLine; |
okano | 0:995f80348e02 | 184 | |
okano | 0:995f80348e02 | 185 | private: |
okano | 0:995f80348e02 | 186 | typedef enum { |
okano | 0:995f80348e02 | 187 | #ifdef INIT_VALUE_DATASHEET_ORIGINAL |
okano | 0:995f80348e02 | 188 | Comm_FunctionSet_Normal = 0x38, |
okano | 0:995f80348e02 | 189 | Comm_FunctionSet_Extended = 0x39, |
okano | 0:995f80348e02 | 190 | Comm_InternalOscFrequency = 0x14, |
okano | 0:995f80348e02 | 191 | Comm_ContrastSet = 0x78, |
okano | 0:995f80348e02 | 192 | Comm_PwrIconContrast = 0x5E, |
okano | 0:995f80348e02 | 193 | Comm_FollowerCtrl = 0x6A, |
okano | 0:995f80348e02 | 194 | Comm_DisplayOnOff = 0x0C, |
okano | 0:995f80348e02 | 195 | Comm_ClearDisplay = 0x01, |
okano | 0:995f80348e02 | 196 | Comm_EntryModeSet = 0x06, |
okano | 0:995f80348e02 | 197 | #else |
okano | 0:995f80348e02 | 198 | Comm_FunctionSet_Normal = 0x38, |
okano | 0:995f80348e02 | 199 | Comm_FunctionSet_Extended = 0x39, |
okano | 0:995f80348e02 | 200 | Comm_InternalOscFrequency = 0x14, |
okano | 0:995f80348e02 | 201 | Comm_ContrastSet = 0x70, |
okano | 0:995f80348e02 | 202 | Comm_PwrIconContrast = 0x5C, |
okano | 0:995f80348e02 | 203 | Comm_FollowerCtrl = 0x60, |
okano | 0:995f80348e02 | 204 | Comm_DisplayOnOff = 0x0C, |
okano | 0:995f80348e02 | 205 | Comm_ClearDisplay = 0x01, |
okano | 0:995f80348e02 | 206 | Comm_EntryModeSet = 0x04, |
okano | 0:995f80348e02 | 207 | Comm_ReturnHome = 0x02, |
okano | 0:995f80348e02 | 208 | #endif |
okano | 0:995f80348e02 | 209 | Comm_SetCGRAM = 0x40 |
okano | 0:995f80348e02 | 210 | } _commands; |
okano | 0:995f80348e02 | 211 | |
okano | 0:995f80348e02 | 212 | typedef enum { |
okano | 0:995f80348e02 | 213 | MaxCharsInALine = 0x10, // buffer depth for one line (no scroll function used) |
okano | 0:995f80348e02 | 214 | COMMAND = 0x00, |
okano | 0:995f80348e02 | 215 | DATA = 0x40 |
okano | 0:995f80348e02 | 216 | } _constants; |
okano | 0:995f80348e02 | 217 | } |
okano | 0:995f80348e02 | 218 | ; |
okano | 0:995f80348e02 | 219 | |
okano | 0:995f80348e02 | 220 | #endif |
okano | 0:995f80348e02 | 221 | |
okano | 0:995f80348e02 | 222 | |
okano | 0:995f80348e02 | 223 | |
okano | 0:995f80348e02 | 224 | |
okano | 0:995f80348e02 | 225 | |
okano | 0:995f80348e02 | 226 | |
okano | 0:995f80348e02 | 227 | |
okano | 0:995f80348e02 | 228 |