character LCD module to I2C adapter Reference http://mbed.org/users/okini3939/notebook/i2c-lcd-library/

Dependents:   JRO_CR2 frdm_test JRO_DDSv2 JRO_DDSv2_rev2019

Fork of I2CLCD by Suga koubou

Files at this revision

API Documentation at this revision

Comitter:
miguelcordero191
Date:
Mon Feb 23 20:37:14 2015 +0000
Parent:
2:bc4583ce560e
Commit message:
Some comments were added

Changed in this revision

I2CLCD.cpp Show annotated file Show diff for this revision Revisions of this file
I2CLCD.h Show annotated file Show diff for this revision Revisions of this file
diff -r bc4583ce560e -r 0c291dbc7acc I2CLCD.cpp
--- a/I2CLCD.cpp	Sun Feb 27 14:28:40 2011 +0000
+++ b/I2CLCD.cpp	Mon Feb 23 20:37:14 2015 +0000
@@ -20,6 +20,32 @@
  * @param value ASCII character code
  * @retval value
  */
+ 
+void I2CLCD::printf(const char *text, int x, int y)
+{
+    int n, len;
+
+    len = strlen(text);
+    
+    i2c.start();
+    i2c.write(i2caddr);
+    i2c.write(0x00);        //Comsend
+    i2c.write(address(x,y));
+    i2c.stop();
+  
+    wait_us(200);
+    
+    i2c.start();
+    i2c.write(i2caddr);
+    i2c.write(0x40);        //Datasend
+    for(n=0; n<len; n++){
+           i2c.write(*text);
+           ++text;
+    }
+    i2c.stop();
+    wait_us(200);  
+} 
+
 int I2CLCD::_putc (int value) {
 
     if (value == '\n') {
@@ -80,21 +106,58 @@
 
     i2caddr = p_i2caddr;
     type = p_type;
-
-    lcd_cfg(p_config);
-
+    /*
+#ifndef LCD_NHD_C022BiZ
+    //lcd_cfg(p_config);
+#endif
     wait_ms(500);
     lcd_out(0x30, 0);
-    wait_ms(5);
-    lcd_out(0x30, 0);
-    wait_ms(2);
+    wait_us(50);
     lcd_out(0x30, 0);
-
-    lcd_out(0x38, 0); // func 
-    lcd_out(0x10, 0); // shift
-    lcd_out(0x0c, 0); // display
-    lcd_out(0x06, 0); // entry mode
+    wait_us(50);
+    lcd_out(0x39, 0);
+    wait_us(50);
+    lcd_out(0x14, 0);       //Bias set
+    wait_us(50);
+    lcd_out(0x78, 0);       //Constrast set
+    wait_us(50); 
+    lcd_out(0x5E, 0);       //Power/ Icon/ Constrast control
+    wait_us(50);
+    lcd_out(0x6A, 0);       //Follower control
+    wait_ms(300); 
+    
+    lcd_out(INST_FUNC, 0); // func 
+    wait_us(50);
+    lcd_out(INST_SHIFT, 0); // shift
+    wait_us(50);
+    lcd_out(INST_DISPLAY, 0); // display
+    wait_us(50);
+    lcd_out(INST_CLEAR, 0); // clear
+    wait_ms(5);
+    lcd_out(INST_ENTRY_MODE, 0); // entry mode
+    wait_us(50);
     cls();
+    wait_us(50);
+    */
+    
+    i2c.frequency(100000);
+    wait_ms(100);
+    i2c.start();
+    i2c.write(i2caddr);
+    i2c.write(0x00);        //Comsend
+    i2c.write(0x38);
+    wait_ms(10);
+    i2c.write(0x39);
+    wait_ms(10);
+    i2c.write(0x14);
+    i2c.write(0x78);
+    i2c.write(0x5E);
+    i2c.write(0x6D);
+    i2c.write(0x0C);
+    i2c.write(0x01);
+    i2c.write(0x06);
+    wait_ms(10);
+    i2c.stop();
 }
 
 void I2CLCD::cls() {
@@ -176,21 +239,21 @@
     i2c.stop();
 }
 
-void I2CLCD::lcd_out (char dat, char rs) {
+void I2CLCD::lcd_out (char dat, char is_value) {
+    
     i2c.start();
     i2c.write(i2caddr);
-    i2c.write(rs ? 0x40 : 0);
+    i2c.write(is_value ? 0x40 : 0x00);
     i2c.write(dat);
     i2c.stop();
 }
 
-char I2CLCD::lcd_in (char rs) {
+char I2CLCD::lcd_in (char is_value) {
     char i;
 
     i2c.start();
     i2c.write(i2caddr);
-    i2c.write(rs ? 0x40 : 0);
-
+    i2c.write(is_value ? 0x40 : 0x00);
     i2c.start();
     i2c.write(i2caddr | 0x01);
     i = i2c.read(0);
diff -r bc4583ce560e -r 0c291dbc7acc I2CLCD.h
--- a/I2CLCD.h	Sun Feb 27 14:28:40 2011 +0000
+++ b/I2CLCD.h	Mon Feb 23 20:37:14 2015 +0000
@@ -17,10 +17,31 @@
 
 #include "mbed.h"
 
+#define LCD_NHD_C022BiZ
 /**
  * @brief default I2C address
  */
-#define I2CLCD_ADDR 0x7c
+
+#ifdef LCD_NHD_C022BiZ
+
+#define I2CLCD_ADDR         0x7c
+#define INST_FUNC           0x38
+#define INST_SHIFT          0x10
+#define INST_DISPLAY        0x0f
+#define INST_CLEAR          0x01
+#define INST_ENTRY_MODE     0x06
+
+#else
+
+#define I2CLCD_ADDR         0x7c
+#define INST_FUNC           0x38
+#define INST_SHIFT          0x10
+#define INST_DISPLAY        0x0c
+#define INST_CLEAR          0x01
+#define INST_ENTRY_MODE     0x06
+
+#endif
+
 
 /**
  * @brief LCD type
@@ -58,16 +79,17 @@
     void locate (int, int);
     void cls ();
     void lcd_cfg (I2CLCDConfig);
-
+    void printf ( const char* text, int x=0, int y=0);
+    
 protected:
     virtual int _putc (int);
     virtual int _getc ();
-
+    
     int address (int, int);
     int rows ();
     int cols ();
     void init (int, I2CLCDType, I2CLCDConfig);
-    void lcd_out (char, char);
+    void lcd_out (char, char = 0);
     char lcd_in (char);
 
     I2C i2c;