Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SB1602E_Hello BME280_LCD PreHeater PreHeater ... more
Revision 2:baf578069dfc, committed 2015-04-07
- Comitter:
- MACRUM
- Date:
- Tue Apr 07 05:03:44 2015 +0000
- Parent:
- 1:fce3e353410c
- Commit message:
- Add printf with X-Y parameters and setter of number of chars in a line
Changed in this revision
| SB1602E.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SB1602E.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SB1602E.cpp Mon Jan 05 05:19:43 2015 +0000
+++ b/SB1602E.cpp Tue Apr 07 05:03:44 2015 +0000
@@ -1,8 +1,8 @@
/** Text LCD module "SB1602E" class library
*
- * @author Tedd OKANO & Masato YAMANISHI
- * @version 2.01
- * @date 05-Jan-2015
+ * @author Tedd OKANO, Masato YAMANISHI & Toyomasa Watarai
+ * @version 2.1
+ * @date 07-April-2015
*
* SB1602E is an I2C based low voltage text LCD panel (based Sitronix ST7032 chip)
* The module by StrawberryLinux
@@ -21,6 +21,8 @@
* revision 1.3 02-May-2014 a. puticon() added (for SB1602B) by Masato YAMANISHI san
* revision 2.0 20-Oct-2014 a. class name is changed and published as "SB1602E"
* b. re-written for better usability
+ * revision 2.1 07-Apl-2015 a. add printf() with X and Y position
+ * b. add setter for number of chars in a line (e.g. 8x2 LCD support)
*/
#include <stdarg.h>
@@ -28,12 +30,12 @@
#include "SB1602E.h"
-SB1602E::SB1602E( PinName I2C_sda, PinName I2C_scl, char *init_massage ) : i2c_p( new I2C( I2C_sda, I2C_scl ) ), i2c( *i2c_p )
+SB1602E::SB1602E( PinName I2C_sda, PinName I2C_scl, char *init_massage ) : i2c_p( new I2C( I2C_sda, I2C_scl ) ), i2c( *i2c_p ), charsInLine( MaxCharsInALine )
{
init( init_massage );
}
-SB1602E::SB1602E( I2C &i2c_, char *init_massage ) : i2c_p( NULL ), i2c( i2c_ )
+SB1602E::SB1602E( I2C &i2c_, char *init_massage ) : i2c_p( NULL ), i2c( i2c_ ), charsInLine( MaxCharsInALine )
{
init( init_massage );
}
@@ -103,6 +105,19 @@
puts( line, s );
}
+void SB1602E::printf( char x, char y, char *format, ... )
+{
+ char s[ 32 ];
+ va_list args;
+
+ va_start( args, format );
+ vsnprintf( s, 32, format, args );
+ va_end( args );
+
+ curs[ y ] = x;
+ puts( y, s );
+}
+
void SB1602E::putc( char line, char c )
{
if ( (c == '\n') || (c == '\r') ) {
@@ -125,7 +140,7 @@
const char Comm_SetDDRAMAddress = 0x80;
const char DDRAMAddress_Ofst[] = { 0x00, 0x40 };
- if ( (x >= MaxCharsInALine) || (y >= 2) )
+ if ( (x >= charsInLine) || (y >= 2) )
return;
lcd_command( (Comm_SetDDRAMAddress | DDRAMAddress_Ofst[ y ]) + x );
@@ -176,7 +191,7 @@
void SB1602E::clear_lest_of_line( char line )
{
- for ( int i = curs[ line ]; i < MaxCharsInALine; i++ )
+ for ( int i = curs[ line ]; i < charsInLine; i++ )
putcxy( ' ', i, line );
}
--- a/SB1602E.h Mon Jan 05 05:19:43 2015 +0000
+++ b/SB1602E.h Tue Apr 07 05:03:44 2015 +0000
@@ -1,8 +1,8 @@
/** Text LCD module "SB1602E" class library
*
- * @author Tedd OKANO & Masato YAMANISHI
- * @version 2.01
- * @date 05-Jan-2015
+ * @author Tedd OKANO, Masato YAMANISHI & Toyomasa Watarai
+ * @version 2.1
+ * @date 07-April-2015
*
* SB1602E is an I2C based low voltage text LCD panel (based Sitronix ST7032 chip)
* The module by StrawberryLinux
@@ -21,6 +21,8 @@
* revision 1.3 02-May-2014 a. puticon() added (for SB1602B) by Masato YAMANISHI san
* revision 2.0 20-Oct-2014 a. class name is changed and published as "SB1602E"
* b. re-written for better usability
+ * revision 2.1 07-Apl-2015 a. add printf() with X and Y position
+ * b. add setter for number of chars in a line (e.g. 8x2 LCD support)
*/
#ifndef MBED_SB1602E
@@ -31,12 +33,10 @@
#include "SB1602E.h"
-/** PCA9629A class
+/** SB1602E class
*
- * This is a driver code for the PCA9629A stepper motor controller.
- * This class provides interface for PCA9629A operation and accessing its registers.
- * Detail information is available on next URL.
- * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_bus_controller_and_bridge_ics/PCA9629APW.html
+ * This is a driver code for the SB1602E LCD module.
+ * This class provides interface for ST7032 operation and accessing its registers.
*
* Example:
* @code
@@ -76,7 +76,7 @@
/** Printf
*
- * pirntf function with line number.
+ * printf function with line number.
* it can be used like
*
* lcd.printf( 0, "Hello world!" );
@@ -87,6 +87,20 @@
*/
void printf( char line, char *format, ... );
+ /** Printf
+ *
+ * printf function with X and Y character position on the LCD.
+ * it can be used like
+ *
+ * lcd.printf( 0, 0, "Hello world!" );
+ * lcd.printf( 4, 1, "pi = %.6f", 3.14159265 );
+ *
+ * @param x X horizontal character position on the LCD
+ * @param y Y vertical character position on the LCD
+ * @param format following parameters are compatible to stdout's printf
+ */
+ void printf( char x, char y, char *format, ... );
+
/** Put character : "putc()"
*
* @param line line# (0 for upper, 1 for lower)
@@ -148,6 +162,12 @@
*/
void puticon( unsigned short flg );
+ /** Set number of charactors in a line
+ *
+ * @param ch number of charactors in a line
+ */
+ void setCharsInLine( char ch ) { charsInLine = ch; };
+
private:
char curs[2];
void init( char *init_massage );
@@ -158,6 +178,7 @@
I2C *i2c_p;
I2C &i2c;
char i2c_addr;
+ char charsInLine;
private:
typedef enum {
SB1602E (ST7032)