You can output chars to AQM1602 with printf(). ex. lcd.printf("iter: %5.5d.\r\n", iter);

Dependents:   aqm1602 FCAS-M101V1

Revision:
1:ac441b938a80
Parent:
0:4d904885c9b8
Child:
2:9233e977ee6e
--- a/AQM1602.cpp	Fri Oct 02 06:13:12 2015 +0000
+++ b/AQM1602.cpp	Mon Oct 19 02:40:02 2015 +0000
@@ -1,12 +1,12 @@
 #include "AQM1602.h"
 
-AQM1602::AQM1602(PinName sda, PinName scl, char address)
-    : i2c(sda, scl), addr(address)
+AQM1602::AQM1602(PinName sda, PinName scl, bool pw3v3, char address)
+    : i2c(sda, scl), addr(address), vdd3v3(pw3v3)
 {
     init();
 }
-AQM1602::AQM1602(I2C &_i2c, char address)
-    : i2c(_i2c), addr(address)
+AQM1602::AQM1602(I2C &_i2c, bool pw3v3, char address)
+    : i2c(_i2c), addr(address), vdd3v3(pw3v3)
 {
     init();
 }
@@ -28,18 +28,18 @@
 int AQM1602::_putc(int val)     // for printf()
 {
     if (val == '\n') {
-        _column = 0;
-        _row = (_row + 1) % 2;
+        col = 0;
+        row = (row + 1) % 2;
     } else {
-        locate(_column, _row);
+        locate(col, row);
         buf[0]= 0x40;
         buf[1]= val;
         i2c.write(addr, buf, 2);
 
-        _column++;
-        if (_column >= 16) {
-            _column = 0;
-            _row = (_row + 1) % 2;
+        col++;
+        if (col >= 16) {
+            col = 0;
+            row = (row + 1) % 2;
         }
     }
     wait_ms(1);
@@ -52,27 +52,29 @@
     return -1;
 }
 
-void AQM1602::locate(int col, int row)
+void AQM1602::locate(int _col, int _row)
 {
+    col= _col;
+    row= _row;
     cmd(0x80 + row * 0x40 + col);
     return;
 }
 
 void AQM1602::init()
 {
-    _column= _row= 0;
+    col= row= 0;
     buf[0]= 0x00;
     buf[1]= 0x00;
     buf[2]= 0x00;
     wait4cmd= 3;
-    valContrast= 0x23;
+//    valContrast= 0x23;
 
     wait_ms(wait4cmd);
     // Function set = 0x38; 0b0011 1000
     // Function set = 0x39; 0b0011 1001
     this->clearIS();
     this->setIS();
-    
+
     // ** must be IS=1. **
     // Internal OSC frequency = 0x14; 0b0001 0100
     this->cmd(0x14);
@@ -80,7 +82,7 @@
 
     // Power/ICON/Contrast control = 0x56; 0b0101 0110
     // Contrast set = 0x70; 0b0111 0011
-    this->setContrast(valContrast, false);
+    this->setContrast(0x23, false);
 
     // Follower control = 0x6C; 0b0110 1100
     this->cmd(0x6C);
@@ -89,11 +91,11 @@
     this->clearIS();
     this->setDispFlag(true, true, true);
     this->clear();
-    
+
     // Function set = 0x38; 0b0011 1000
     // Display ON/OFF control = 0x0C; 0b 0000 1DCB
     // Clear Display = 0x01; 0b 0000 0001
-    
+
     return;
 }
 
@@ -102,26 +104,42 @@
 // C5,C4,C3,C2,C1,C0 can only be set when internal follower is used (OPF1=0,OPF2=0).
 // They can more precisely adjust the input reference voltage of V0 generator.
 // The details please refer to the supply voltage for LCD driver.
-    
-    if(val > 0x3f)
+
+    if(val > 0x3f)// || val < 0x00)
         return;
-        
-    valContrast= val;
+
+    contrast= val;
+    setPwContrast(ctrlIS);
+
+    return;
+}
+
+void AQM1602::setPwContrast(bool ctrlIS)
+{
+// C5,C4,C3,C2,C1,C0 can only be set when internal follower is used (OPF1=0,OPF2=0).
+// They can more precisely adjust the input reference voltage of V0 generator.
+// The details please refer to the supply voltage for LCD driver.
+
     // Cmd of Contrast-setting must be setted IS.
     if(ctrlIS)
         this->setIS();
-    
-    // 0b 0101 01++
-    this->cmd(0x54+ (val>>4));
+
+    // 0b 0101 0*++     // PW, C5, C4
+    char val= 0x50;
+    if(vdd3v3)      // set Booster circuit.
+        val += 0x04;
+    val += (contrast>>4);
+    this->cmd(val);
+//    this->cmd(0x54+ (contrast>>4));
     wait_ms(wait4cmd);
-    
-    // 0b 0111 ++++
-    this->cmd(0x70+ (val&0x0f));
+
+    // 0b 0111 ++++     // C3, C2, C1, C0
+    this->cmd(0x70+ (contrast&0x0f));
     wait_ms(wait4cmd);
-    
+
     if(ctrlIS)
         this->clearIS();
-    
+
     wait_ms(wait4cmd);
     return;
 }